mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-22 20:31:19 +00:00
* Cleanup checks for community actions (fixes #2858, fixes #2868) * allow restoring deleted community * review changes * remove unneeded sql * remove joins * change mod log check
This commit is contained in:
parent
608bb6b1b4
commit
9e099726e6
38 changed files with 273 additions and 231 deletions
|
@ -2,7 +2,7 @@ use actix_web::web::{Data, Json};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{CommentResponse, DistinguishComment},
|
comment::{CommentResponse, DistinguishComment},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
utils::{check_community_ban, is_mod_or_admin},
|
utils::{check_community_mod_action, check_community_user_action},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::comment::{Comment, CommentUpdateForm},
|
source::comment::{Comment, CommentUpdateForm},
|
||||||
|
@ -19,18 +19,19 @@ pub async fn distinguish_comment(
|
||||||
) -> Result<Json<CommentResponse>, LemmyError> {
|
) -> Result<Json<CommentResponse>, LemmyError> {
|
||||||
let orig_comment = CommentView::read(&mut context.pool(), data.comment_id, None).await?;
|
let orig_comment = CommentView::read(&mut context.pool(), data.comment_id, None).await?;
|
||||||
|
|
||||||
check_community_ban(
|
check_community_user_action(
|
||||||
local_user_view.person.id,
|
&local_user_view.person,
|
||||||
orig_comment.community.id,
|
orig_comment.community.id,
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// Verify that only a mod or admin can distinguish a comment
|
// Verify that only a mod or admin can distinguish a comment
|
||||||
is_mod_or_admin(
|
check_community_mod_action(
|
||||||
&mut context.pool(),
|
&local_user_view.person,
|
||||||
local_user_view.person.id,
|
|
||||||
orig_comment.community.id,
|
orig_comment.community.id,
|
||||||
|
false,
|
||||||
|
&mut context.pool(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ use lemmy_api_common::{
|
||||||
comment::{CommentResponse, CreateCommentLike},
|
comment::{CommentResponse, CreateCommentLike},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
send_activity::{ActivityChannel, SendActivityData},
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{check_community_ban, check_downvotes_enabled},
|
utils::{check_community_user_action, check_downvotes_enabled},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::LocalUserId,
|
newtypes::LocalUserId,
|
||||||
|
@ -36,8 +36,8 @@ pub async fn like_comment(
|
||||||
let comment_id = data.comment_id;
|
let comment_id = data.comment_id;
|
||||||
let orig_comment = CommentView::read(&mut context.pool(), comment_id, None).await?;
|
let orig_comment = CommentView::read(&mut context.pool(), comment_id, None).await?;
|
||||||
|
|
||||||
check_community_ban(
|
check_community_user_action(
|
||||||
local_user_view.person.id,
|
&local_user_view.person,
|
||||||
orig_comment.community.id,
|
orig_comment.community.id,
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,7 +5,7 @@ use lemmy_api_common::{
|
||||||
comment::{CommentReportResponse, CreateCommentReport},
|
comment::{CommentReportResponse, CreateCommentReport},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
send_activity::{ActivityChannel, SendActivityData},
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{check_community_ban, send_new_report_email_to_admins},
|
utils::{check_community_user_action, send_new_report_email_to_admins},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -33,7 +33,12 @@ pub async fn create_comment_report(
|
||||||
let comment_id = data.comment_id;
|
let comment_id = data.comment_id;
|
||||||
let comment_view = CommentView::read(&mut context.pool(), comment_id, None).await?;
|
let comment_view = CommentView::read(&mut context.pool(), comment_id, None).await?;
|
||||||
|
|
||||||
check_community_ban(person_id, comment_view.community.id, &mut context.pool()).await?;
|
check_community_user_action(
|
||||||
|
&local_user_view.person,
|
||||||
|
comment_view.community.id,
|
||||||
|
&mut context.pool(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
let report_form = CommentReportForm {
|
let report_form = CommentReportForm {
|
||||||
creator_id: person_id,
|
creator_id: person_id,
|
||||||
|
|
|
@ -2,6 +2,7 @@ use actix_web::web::{Data, Json, Query};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{ListCommentReports, ListCommentReportsResponse},
|
comment::{ListCommentReports, ListCommentReportsResponse},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
|
utils::check_community_mod_action_opt,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::{comment_report_view::CommentReportQuery, structs::LocalUserView};
|
use lemmy_db_views::{comment_report_view::CommentReportQuery, structs::LocalUserView};
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
|
@ -17,6 +18,8 @@ pub async fn list_comment_reports(
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
let unresolved_only = data.unresolved_only.unwrap_or_default();
|
let unresolved_only = data.unresolved_only.unwrap_or_default();
|
||||||
|
|
||||||
|
check_community_mod_action_opt(&local_user_view, community_id, &mut context.pool()).await?;
|
||||||
|
|
||||||
let page = data.page;
|
let page = data.page;
|
||||||
let limit = data.limit;
|
let limit = data.limit;
|
||||||
let comment_reports = CommentReportQuery {
|
let comment_reports = CommentReportQuery {
|
||||||
|
|
|
@ -2,7 +2,7 @@ use actix_web::web::{Data, Json};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{CommentReportResponse, ResolveCommentReport},
|
comment::{CommentReportResponse, ResolveCommentReport},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
utils::is_mod_or_admin,
|
utils::check_community_mod_action,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{source::comment_report::CommentReport, traits::Reportable};
|
use lemmy_db_schema::{source::comment_report::CommentReport, traits::Reportable};
|
||||||
use lemmy_db_views::structs::{CommentReportView, LocalUserView};
|
use lemmy_db_views::structs::{CommentReportView, LocalUserView};
|
||||||
|
@ -20,7 +20,13 @@ pub async fn resolve_comment_report(
|
||||||
let report = CommentReportView::read(&mut context.pool(), report_id, person_id).await?;
|
let report = CommentReportView::read(&mut context.pool(), report_id, person_id).await?;
|
||||||
|
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
is_mod_or_admin(&mut context.pool(), person_id, report.community.id).await?;
|
check_community_mod_action(
|
||||||
|
&local_user_view.person,
|
||||||
|
report.community.id,
|
||||||
|
false,
|
||||||
|
&mut context.pool(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
if data.resolved {
|
if data.resolved {
|
||||||
CommentReport::resolve(&mut context.pool(), report_id, person_id)
|
CommentReport::resolve(&mut context.pool(), report_id, person_id)
|
||||||
|
|
|
@ -4,7 +4,7 @@ use lemmy_api_common::{
|
||||||
community::{AddModToCommunity, AddModToCommunityResponse},
|
community::{AddModToCommunity, AddModToCommunityResponse},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
send_activity::{ActivityChannel, SendActivityData},
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::is_mod_or_admin,
|
utils::check_community_mod_action,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -26,7 +26,13 @@ pub async fn add_mod_to_community(
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
|
|
||||||
// Verify that only mods or admins can add mod
|
// Verify that only mods or admins can add mod
|
||||||
is_mod_or_admin(&mut context.pool(), local_user_view.person.id, community_id).await?;
|
check_community_mod_action(
|
||||||
|
&local_user_view.person,
|
||||||
|
community_id,
|
||||||
|
false,
|
||||||
|
&mut context.pool(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
let community = Community::read(&mut context.pool(), community_id).await?;
|
let community = Community::read(&mut context.pool(), community_id).await?;
|
||||||
if local_user_view.local_user.admin && !community.local {
|
if local_user_view.local_user.admin && !community.local {
|
||||||
Err(LemmyErrorType::NotAModerator)?
|
Err(LemmyErrorType::NotAModerator)?
|
||||||
|
|
|
@ -4,7 +4,7 @@ use lemmy_api_common::{
|
||||||
community::{BanFromCommunity, BanFromCommunityResponse},
|
community::{BanFromCommunity, BanFromCommunityResponse},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
send_activity::{ActivityChannel, SendActivityData},
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{is_mod_or_admin, remove_user_data_in_community},
|
utils::{check_community_mod_action, remove_user_data_in_community},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -36,10 +36,11 @@ pub async fn ban_from_community(
|
||||||
let expires = data.expires.map(naive_from_unix);
|
let expires = data.expires.map(naive_from_unix);
|
||||||
|
|
||||||
// Verify that only mods or admins can ban
|
// Verify that only mods or admins can ban
|
||||||
is_mod_or_admin(
|
check_community_mod_action(
|
||||||
&mut context.pool(),
|
&local_user_view.person,
|
||||||
local_user_view.person.id,
|
|
||||||
data.community_id,
|
data.community_id,
|
||||||
|
false,
|
||||||
|
&mut context.pool(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
is_valid_body_field(&data.reason, false)?;
|
is_valid_body_field(&data.reason, false)?;
|
||||||
|
|
|
@ -4,7 +4,7 @@ use lemmy_api_common::{
|
||||||
community::{CommunityResponse, FollowCommunity},
|
community::{CommunityResponse, FollowCommunity},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
send_activity::{ActivityChannel, SendActivityData},
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{check_community_ban, check_community_deleted_or_removed},
|
utils::check_community_user_action,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -32,8 +32,8 @@ pub async fn follow_community(
|
||||||
|
|
||||||
if data.follow {
|
if data.follow {
|
||||||
if community.local {
|
if community.local {
|
||||||
check_community_ban(local_user_view.person.id, community.id, &mut context.pool()).await?;
|
check_community_user_action(&local_user_view.person, community.id, &mut context.pool())
|
||||||
check_community_deleted_or_removed(community.id, &mut context.pool()).await?;
|
.await?;
|
||||||
|
|
||||||
CommunityFollower::follow(&mut context.pool(), &community_follower_form)
|
CommunityFollower::follow(&mut context.pool(), &community_follower_form)
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -3,7 +3,7 @@ use anyhow::Context;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{GetCommunityResponse, TransferCommunity},
|
community::{GetCommunityResponse, TransferCommunity},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
utils::{is_admin, is_top_mod},
|
utils::{check_community_user_action, is_admin, is_top_mod},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -27,11 +27,12 @@ pub async fn transfer_community(
|
||||||
context: Data<LemmyContext>,
|
context: Data<LemmyContext>,
|
||||||
local_user_view: LocalUserView,
|
local_user_view: LocalUserView,
|
||||||
) -> Result<Json<GetCommunityResponse>, LemmyError> {
|
) -> Result<Json<GetCommunityResponse>, LemmyError> {
|
||||||
// Fetch the community mods
|
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
let mut community_mods =
|
let mut community_mods =
|
||||||
CommunityModeratorView::for_community(&mut context.pool(), community_id).await?;
|
CommunityModeratorView::for_community(&mut context.pool(), community_id).await?;
|
||||||
|
|
||||||
|
check_community_user_action(&local_user_view.person, community_id, &mut context.pool()).await?;
|
||||||
|
|
||||||
// Make sure transferrer is either the top community mod, or an admin
|
// Make sure transferrer is either the top community mod, or an admin
|
||||||
if !(is_top_mod(&local_user_view, &community_mods).is_ok() || is_admin(&local_user_view).is_ok())
|
if !(is_top_mod(&local_user_view, &community_mods).is_ok() || is_admin(&local_user_view).is_ok())
|
||||||
{
|
{
|
||||||
|
|
|
@ -44,11 +44,7 @@ pub async fn login(
|
||||||
if !valid {
|
if !valid {
|
||||||
Err(LemmyErrorType::IncorrectLogin)?
|
Err(LemmyErrorType::IncorrectLogin)?
|
||||||
}
|
}
|
||||||
check_user_valid(
|
check_user_valid(&local_user_view.person)?;
|
||||||
local_user_view.person.banned,
|
|
||||||
local_user_view.person.ban_expires,
|
|
||||||
local_user_view.person.deleted,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
// Check if the user's email is verified if email verification is turned on
|
// Check if the user's email is verified if email verification is turned on
|
||||||
// However, skip checking verification if the user is an admin
|
// However, skip checking verification if the user is an admin
|
||||||
|
|
|
@ -2,6 +2,7 @@ use actix_web::web::{Data, Json};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
person::{GetReportCount, GetReportCountResponse},
|
person::{GetReportCount, GetReportCountResponse},
|
||||||
|
utils::check_community_mod_action_opt,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::{
|
use lemmy_db_views::structs::{
|
||||||
CommentReportView,
|
CommentReportView,
|
||||||
|
@ -21,6 +22,8 @@ pub async fn report_count(
|
||||||
let admin = local_user_view.local_user.admin;
|
let admin = local_user_view.local_user.admin;
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
|
|
||||||
|
check_community_mod_action_opt(&local_user_view, community_id, &mut context.pool()).await?;
|
||||||
|
|
||||||
let comment_reports =
|
let comment_reports =
|
||||||
CommentReportView::get_report_count(&mut context.pool(), person_id, admin, community_id)
|
CommentReportView::get_report_count(&mut context.pool(), person_id, admin, community_id)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
|
@ -5,7 +5,7 @@ use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{FeaturePost, PostResponse},
|
post::{FeaturePost, PostResponse},
|
||||||
send_activity::{ActivityChannel, SendActivityData},
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{check_community_ban, check_community_deleted_or_removed, is_admin, is_mod_or_admin},
|
utils::{check_community_mod_action, is_admin},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -27,23 +27,15 @@ pub async fn feature_post(
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let orig_post = Post::read(&mut context.pool(), post_id).await?;
|
let orig_post = Post::read(&mut context.pool(), post_id).await?;
|
||||||
|
|
||||||
check_community_ban(
|
check_community_mod_action(
|
||||||
local_user_view.person.id,
|
&local_user_view.person,
|
||||||
orig_post.community_id,
|
orig_post.community_id,
|
||||||
|
false,
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
check_community_deleted_or_removed(orig_post.community_id, &mut context.pool()).await?;
|
|
||||||
|
|
||||||
if data.feature_type == PostFeatureType::Community {
|
if data.feature_type == PostFeatureType::Local {
|
||||||
// Verify that only the mods can feature in community
|
|
||||||
is_mod_or_admin(
|
|
||||||
&mut context.pool(),
|
|
||||||
local_user_view.person.id,
|
|
||||||
orig_post.community_id,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
} else {
|
|
||||||
is_admin(&local_user_view)?;
|
is_admin(&local_user_view)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,12 +64,17 @@ pub async fn feature_post(
|
||||||
|
|
||||||
ModFeaturePost::create(&mut context.pool(), &form).await?;
|
ModFeaturePost::create(&mut context.pool(), &form).await?;
|
||||||
|
|
||||||
let person_id = local_user_view.person.id;
|
|
||||||
ActivityChannel::submit_activity(
|
ActivityChannel::submit_activity(
|
||||||
SendActivityData::FeaturePost(post, local_user_view.person, data.featured),
|
SendActivityData::FeaturePost(post, local_user_view.person.clone(), data.featured),
|
||||||
&context,
|
&context,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
build_post_response(&context, orig_post.community_id, person_id, post_id).await
|
build_post_response(
|
||||||
|
&context,
|
||||||
|
orig_post.community_id,
|
||||||
|
&local_user_view.person,
|
||||||
|
post_id,
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,7 @@ use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{CreatePostLike, PostResponse},
|
post::{CreatePostLike, PostResponse},
|
||||||
send_activity::{ActivityChannel, SendActivityData},
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{
|
utils::{check_community_user_action, check_downvotes_enabled, mark_post_as_read},
|
||||||
check_community_ban,
|
|
||||||
check_community_deleted_or_removed,
|
|
||||||
check_downvotes_enabled,
|
|
||||||
mark_post_as_read,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -39,13 +34,12 @@ pub async fn like_post(
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let post = Post::read(&mut context.pool(), post_id).await?;
|
let post = Post::read(&mut context.pool(), post_id).await?;
|
||||||
|
|
||||||
check_community_ban(
|
check_community_user_action(
|
||||||
local_user_view.person.id,
|
&local_user_view.person,
|
||||||
post.community_id,
|
post.community_id,
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
check_community_deleted_or_removed(post.community_id, &mut context.pool()).await?;
|
|
||||||
|
|
||||||
let like_form = PostLikeForm {
|
let like_form = PostLikeForm {
|
||||||
post_id: data.post_id,
|
post_id: data.post_id,
|
||||||
|
@ -83,7 +77,7 @@ pub async fn like_post(
|
||||||
build_post_response(
|
build_post_response(
|
||||||
context.deref(),
|
context.deref(),
|
||||||
post.community_id,
|
post.community_id,
|
||||||
local_user_view.person.id,
|
&local_user_view.person,
|
||||||
post_id,
|
post_id,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -5,7 +5,7 @@ use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{LockPost, PostResponse},
|
post::{LockPost, PostResponse},
|
||||||
send_activity::{ActivityChannel, SendActivityData},
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{check_community_ban, check_community_deleted_or_removed, is_mod_or_admin},
|
utils::check_community_mod_action,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -26,21 +26,13 @@ pub async fn lock_post(
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let orig_post = Post::read(&mut context.pool(), post_id).await?;
|
let orig_post = Post::read(&mut context.pool(), post_id).await?;
|
||||||
|
|
||||||
check_community_ban(
|
check_community_mod_action(
|
||||||
local_user_view.person.id,
|
&local_user_view.person,
|
||||||
orig_post.community_id,
|
orig_post.community_id,
|
||||||
|
false,
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
check_community_deleted_or_removed(orig_post.community_id, &mut context.pool()).await?;
|
|
||||||
|
|
||||||
// Verify that only the mods can lock
|
|
||||||
is_mod_or_admin(
|
|
||||||
&mut context.pool(),
|
|
||||||
local_user_view.person.id,
|
|
||||||
orig_post.community_id,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
// Update the post
|
// Update the post
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
|
@ -63,12 +55,17 @@ pub async fn lock_post(
|
||||||
};
|
};
|
||||||
ModLockPost::create(&mut context.pool(), &form).await?;
|
ModLockPost::create(&mut context.pool(), &form).await?;
|
||||||
|
|
||||||
let person_id = local_user_view.person.id;
|
|
||||||
ActivityChannel::submit_activity(
|
ActivityChannel::submit_activity(
|
||||||
SendActivityData::LockPost(post, local_user_view.person, data.locked),
|
SendActivityData::LockPost(post, local_user_view.person.clone(), data.locked),
|
||||||
&context,
|
&context,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
build_post_response(&context, orig_post.community_id, person_id, post_id).await
|
build_post_response(
|
||||||
|
&context,
|
||||||
|
orig_post.community_id,
|
||||||
|
&local_user_view.person,
|
||||||
|
post_id,
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{CreatePostReport, PostReportResponse},
|
post::{CreatePostReport, PostReportResponse},
|
||||||
send_activity::{ActivityChannel, SendActivityData},
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{check_community_ban, send_new_report_email_to_admins},
|
utils::{check_community_user_action, send_new_report_email_to_admins},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -33,7 +33,12 @@ pub async fn create_post_report(
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let post_view = PostView::read(&mut context.pool(), post_id, None, false).await?;
|
let post_view = PostView::read(&mut context.pool(), post_id, None, false).await?;
|
||||||
|
|
||||||
check_community_ban(person_id, post_view.community.id, &mut context.pool()).await?;
|
check_community_user_action(
|
||||||
|
&local_user_view.person,
|
||||||
|
post_view.community.id,
|
||||||
|
&mut context.pool(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
let report_form = PostReportForm {
|
let report_form = PostReportForm {
|
||||||
creator_id: person_id,
|
creator_id: person_id,
|
||||||
|
|
|
@ -2,6 +2,7 @@ use actix_web::web::{Data, Json, Query};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{ListPostReports, ListPostReportsResponse},
|
post::{ListPostReports, ListPostReportsResponse},
|
||||||
|
utils::check_community_mod_action_opt,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::{post_report_view::PostReportQuery, structs::LocalUserView};
|
use lemmy_db_views::{post_report_view::PostReportQuery, structs::LocalUserView};
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
|
@ -17,6 +18,8 @@ pub async fn list_post_reports(
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
let unresolved_only = data.unresolved_only.unwrap_or_default();
|
let unresolved_only = data.unresolved_only.unwrap_or_default();
|
||||||
|
|
||||||
|
check_community_mod_action_opt(&local_user_view, community_id, &mut context.pool()).await?;
|
||||||
|
|
||||||
let page = data.page;
|
let page = data.page;
|
||||||
let limit = data.limit;
|
let limit = data.limit;
|
||||||
let post_reports = PostReportQuery {
|
let post_reports = PostReportQuery {
|
||||||
|
|
|
@ -2,7 +2,7 @@ use actix_web::web::{Data, Json};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{PostReportResponse, ResolvePostReport},
|
post::{PostReportResponse, ResolvePostReport},
|
||||||
utils::is_mod_or_admin,
|
utils::check_community_mod_action,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{source::post_report::PostReport, traits::Reportable};
|
use lemmy_db_schema::{source::post_report::PostReport, traits::Reportable};
|
||||||
use lemmy_db_views::structs::{LocalUserView, PostReportView};
|
use lemmy_db_views::structs::{LocalUserView, PostReportView};
|
||||||
|
@ -20,7 +20,13 @@ pub async fn resolve_post_report(
|
||||||
let report = PostReportView::read(&mut context.pool(), report_id, person_id).await?;
|
let report = PostReportView::read(&mut context.pool(), report_id, person_id).await?;
|
||||||
|
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
is_mod_or_admin(&mut context.pool(), person_id, report.community.id).await?;
|
check_community_mod_action(
|
||||||
|
&local_user_view.person,
|
||||||
|
report.community.id,
|
||||||
|
false,
|
||||||
|
&mut context.pool(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
if data.resolved {
|
if data.resolved {
|
||||||
PostReport::resolve(&mut context.pool(), report_id, person_id)
|
PostReport::resolve(&mut context.pool(), report_id, person_id)
|
||||||
|
|
|
@ -2,13 +2,9 @@ use actix_web::web::{Data, Json, Query};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
site::{GetModlog, GetModlogResponse},
|
site::{GetModlog, GetModlogResponse},
|
||||||
utils::{check_private_instance, is_admin, is_mod_or_admin},
|
utils::{check_community_mod_action_opt, check_private_instance, is_admin},
|
||||||
};
|
|
||||||
use lemmy_db_schema::{
|
|
||||||
newtypes::{CommunityId, PersonId},
|
|
||||||
source::local_site::LocalSite,
|
|
||||||
ModlogActionType,
|
|
||||||
};
|
};
|
||||||
|
use lemmy_db_schema::{source::local_site::LocalSite, ModlogActionType};
|
||||||
use lemmy_db_views::structs::LocalUserView;
|
use lemmy_db_views::structs::LocalUserView;
|
||||||
use lemmy_db_views_moderator::structs::{
|
use lemmy_db_views_moderator::structs::{
|
||||||
AdminPurgeCommentView,
|
AdminPurgeCommentView,
|
||||||
|
@ -44,19 +40,16 @@ pub async fn get_mod_log(
|
||||||
let type_ = data.type_.unwrap_or(All);
|
let type_ = data.type_.unwrap_or(All);
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
|
|
||||||
let (local_person_id, is_admin) = match local_user_view {
|
let is_mod_or_admin = if let Some(local_user_view) = local_user_view {
|
||||||
Some(s) => (s.person.id, is_admin(&s).is_ok()),
|
let is_mod = community_id.is_some()
|
||||||
None => (PersonId(-1), false),
|
&& check_community_mod_action_opt(&local_user_view, community_id, &mut context.pool())
|
||||||
};
|
|
||||||
let community_id_value = match community_id {
|
|
||||||
Some(s) => s,
|
|
||||||
None => CommunityId(-1),
|
|
||||||
};
|
|
||||||
let is_mod_of_community = data.community_id.is_some()
|
|
||||||
&& is_mod_or_admin(&mut context.pool(), local_person_id, community_id_value)
|
|
||||||
.await
|
.await
|
||||||
.is_ok();
|
.is_ok();
|
||||||
let hide_modlog_names = local_site.hide_modlog_mod_names && !is_mod_of_community && !is_admin;
|
is_mod || is_admin(&local_user_view).is_ok()
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
};
|
||||||
|
let hide_modlog_names = local_site.hide_modlog_mod_names && !is_mod_or_admin;
|
||||||
|
|
||||||
let mod_person_id = if hide_modlog_names {
|
let mod_person_id = if hide_modlog_names {
|
||||||
None
|
None
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
use actix_web::web::Json;
|
use actix_web::web::Json;
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::{CommentId, CommunityId, LocalUserId, PersonId, PostId},
|
newtypes::{CommentId, CommunityId, LocalUserId, PostId},
|
||||||
source::{
|
source::{
|
||||||
actor_language::CommunityLanguage,
|
actor_language::CommunityLanguage,
|
||||||
comment::Comment,
|
comment::Comment,
|
||||||
|
@ -44,8 +44,7 @@ pub async fn build_community_response(
|
||||||
local_user_view: LocalUserView,
|
local_user_view: LocalUserView,
|
||||||
community_id: CommunityId,
|
community_id: CommunityId,
|
||||||
) -> Result<Json<CommunityResponse>, LemmyError> {
|
) -> Result<Json<CommunityResponse>, LemmyError> {
|
||||||
let is_mod_or_admin =
|
let is_mod_or_admin = is_mod_or_admin(&mut context.pool(), &local_user_view.person, community_id)
|
||||||
is_mod_or_admin(&mut context.pool(), local_user_view.person.id, community_id)
|
|
||||||
.await
|
.await
|
||||||
.is_ok();
|
.is_ok();
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
|
@ -67,16 +66,16 @@ pub async fn build_community_response(
|
||||||
pub async fn build_post_response(
|
pub async fn build_post_response(
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
community_id: CommunityId,
|
community_id: CommunityId,
|
||||||
person_id: PersonId,
|
person: &Person,
|
||||||
post_id: PostId,
|
post_id: PostId,
|
||||||
) -> Result<Json<PostResponse>, LemmyError> {
|
) -> Result<Json<PostResponse>, LemmyError> {
|
||||||
let is_mod_or_admin = is_mod_or_admin(&mut context.pool(), person_id, community_id)
|
let is_mod_or_admin = is_mod_or_admin(&mut context.pool(), person, community_id)
|
||||||
.await
|
.await
|
||||||
.is_ok();
|
.is_ok();
|
||||||
let post_view = PostView::read(
|
let post_view = PostView::read(
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
post_id,
|
post_id,
|
||||||
Some(person_id),
|
Some(person.id),
|
||||||
is_mod_or_admin,
|
is_mod_or_admin,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
|
@ -6,9 +6,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
use actix_web::cookie::{Cookie, SameSite};
|
use actix_web::cookie::{Cookie, SameSite};
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use chrono::{DateTime, Utc};
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
impls::person::is_banned,
|
|
||||||
newtypes::{CommunityId, DbUrl, PersonId, PostId},
|
newtypes::{CommunityId, DbUrl, PersonId, PostId},
|
||||||
source::{
|
source::{
|
||||||
comment::{Comment, CommentUpdateForm},
|
comment::{Comment, CommentUpdateForm},
|
||||||
|
@ -33,7 +31,7 @@ use lemmy_db_views_actor::structs::{
|
||||||
};
|
};
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
email::{send_email, translations::Lang},
|
email::{send_email, translations::Lang},
|
||||||
error::{LemmyError, LemmyErrorExt, LemmyErrorType},
|
error::{LemmyError, LemmyErrorExt, LemmyErrorType, LemmyResult},
|
||||||
location_info,
|
location_info,
|
||||||
rate_limit::RateLimitConfig,
|
rate_limit::RateLimitConfig,
|
||||||
settings::structs::Settings,
|
settings::structs::Settings,
|
||||||
|
@ -49,10 +47,12 @@ pub static AUTH_COOKIE_NAME: &str = "auth";
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
pub async fn is_mod_or_admin(
|
pub async fn is_mod_or_admin(
|
||||||
pool: &mut DbPool<'_>,
|
pool: &mut DbPool<'_>,
|
||||||
person_id: PersonId,
|
person: &Person,
|
||||||
community_id: CommunityId,
|
community_id: CommunityId,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let is_mod_or_admin = CommunityView::is_mod_or_admin(pool, person_id, community_id).await?;
|
check_user_valid(person)?;
|
||||||
|
|
||||||
|
let is_mod_or_admin = CommunityView::is_mod_or_admin(pool, person.id, community_id).await?;
|
||||||
if !is_mod_or_admin {
|
if !is_mod_or_admin {
|
||||||
Err(LemmyErrorType::NotAModOrAdmin)?
|
Err(LemmyErrorType::NotAModOrAdmin)?
|
||||||
} else {
|
} else {
|
||||||
|
@ -68,7 +68,7 @@ pub async fn is_mod_or_admin_opt(
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
if let Some(local_user_view) = local_user_view {
|
if let Some(local_user_view) = local_user_view {
|
||||||
if let Some(community_id) = community_id {
|
if let Some(community_id) = community_id {
|
||||||
is_mod_or_admin(pool, local_user_view.person.id, community_id).await
|
is_mod_or_admin(pool, &local_user_view.person, community_id).await
|
||||||
} else {
|
} else {
|
||||||
is_admin(local_user_view)
|
is_admin(local_user_view)
|
||||||
}
|
}
|
||||||
|
@ -78,8 +78,11 @@ pub async fn is_mod_or_admin_opt(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_admin(local_user_view: &LocalUserView) -> Result<(), LemmyError> {
|
pub fn is_admin(local_user_view: &LocalUserView) -> Result<(), LemmyError> {
|
||||||
|
check_user_valid(&local_user_view.person)?;
|
||||||
if !local_user_view.local_user.admin {
|
if !local_user_view.local_user.admin {
|
||||||
Err(LemmyErrorType::NotAnAdmin)?
|
Err(LemmyErrorType::NotAnAdmin)?
|
||||||
|
} else if local_user_view.person.banned {
|
||||||
|
Err(LemmyErrorType::Banned)?
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -89,6 +92,7 @@ pub fn is_top_mod(
|
||||||
local_user_view: &LocalUserView,
|
local_user_view: &LocalUserView,
|
||||||
community_mods: &[CommunityModeratorView],
|
community_mods: &[CommunityModeratorView],
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
|
check_user_valid(&local_user_view.person)?;
|
||||||
if local_user_view.person.id
|
if local_user_view.person.id
|
||||||
!= community_mods
|
!= community_mods
|
||||||
.first()
|
.first()
|
||||||
|
@ -134,52 +138,91 @@ pub async fn mark_post_as_unread(
|
||||||
.with_lemmy_type(LemmyErrorType::CouldntMarkPostAsRead)
|
.with_lemmy_type(LemmyErrorType::CouldntMarkPostAsRead)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_user_valid(
|
pub fn check_user_valid(person: &Person) -> Result<(), LemmyError> {
|
||||||
banned: bool,
|
|
||||||
ban_expires: Option<DateTime<Utc>>,
|
|
||||||
deleted: bool,
|
|
||||||
) -> Result<(), LemmyError> {
|
|
||||||
// Check for a site ban
|
// Check for a site ban
|
||||||
if is_banned(banned, ban_expires) {
|
if person.banned {
|
||||||
Err(LemmyErrorType::SiteBan)?
|
Err(LemmyErrorType::SiteBan)?
|
||||||
}
|
}
|
||||||
// check for account deletion
|
// check for account deletion
|
||||||
else if deleted {
|
else if person.deleted {
|
||||||
Err(LemmyErrorType::Deleted)?
|
Err(LemmyErrorType::Deleted)?
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
/// Checks that a normal user action (eg posting or voting) is allowed in a given community.
|
||||||
pub async fn check_community_ban(
|
///
|
||||||
person_id: PersonId,
|
/// In particular it checks that neither the user nor community are banned or deleted, and that
|
||||||
|
/// the user isn't banned.
|
||||||
|
pub async fn check_community_user_action(
|
||||||
|
person: &Person,
|
||||||
community_id: CommunityId,
|
community_id: CommunityId,
|
||||||
pool: &mut DbPool<'_>,
|
pool: &mut DbPool<'_>,
|
||||||
) -> Result<(), LemmyError> {
|
) -> LemmyResult<()> {
|
||||||
let is_banned = CommunityPersonBanView::get(pool, person_id, community_id)
|
check_user_valid(person)?;
|
||||||
.await
|
check_community_deleted_removed(community_id, pool).await?;
|
||||||
.is_ok();
|
check_community_ban(person, community_id, pool).await?;
|
||||||
if is_banned {
|
|
||||||
Err(LemmyErrorType::BannedFromCommunity)?
|
|
||||||
} else {
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
async fn check_community_deleted_removed(
|
||||||
pub async fn check_community_deleted_or_removed(
|
|
||||||
community_id: CommunityId,
|
community_id: CommunityId,
|
||||||
pool: &mut DbPool<'_>,
|
pool: &mut DbPool<'_>,
|
||||||
) -> Result<(), LemmyError> {
|
) -> LemmyResult<()> {
|
||||||
let community = Community::read(pool, community_id)
|
let community = Community::read(pool, community_id)
|
||||||
.await
|
.await
|
||||||
.with_lemmy_type(LemmyErrorType::CouldntFindCommunity)?;
|
.with_lemmy_type(LemmyErrorType::CouldntFindCommunity)?;
|
||||||
if community.deleted || community.removed {
|
if community.deleted || community.removed {
|
||||||
Err(LemmyErrorType::Deleted)?
|
Err(LemmyErrorType::Deleted)?
|
||||||
} else {
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn check_community_ban(
|
||||||
|
person: &Person,
|
||||||
|
community_id: CommunityId,
|
||||||
|
pool: &mut DbPool<'_>,
|
||||||
|
) -> LemmyResult<()> {
|
||||||
|
// check if user was banned from site or community
|
||||||
|
let is_banned = CommunityPersonBanView::get(pool, person.id, community_id).await?;
|
||||||
|
if is_banned {
|
||||||
|
Err(LemmyErrorType::BannedFromCommunity)?
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check that the given user can perform a mod action in the community.
|
||||||
|
///
|
||||||
|
/// In particular it checks that he is an admin or mod, wasn't banned and the community isn't
|
||||||
|
/// removed/deleted.
|
||||||
|
pub async fn check_community_mod_action(
|
||||||
|
person: &Person,
|
||||||
|
community_id: CommunityId,
|
||||||
|
allow_deleted: bool,
|
||||||
|
pool: &mut DbPool<'_>,
|
||||||
|
) -> LemmyResult<()> {
|
||||||
|
is_mod_or_admin(pool, person, community_id).await?;
|
||||||
|
check_community_ban(person, community_id, pool).await?;
|
||||||
|
|
||||||
|
// it must be possible to restore deleted community
|
||||||
|
if !allow_deleted {
|
||||||
|
check_community_deleted_removed(community_id, pool).await?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn check_community_mod_action_opt(
|
||||||
|
local_user_view: &LocalUserView,
|
||||||
|
community_id: Option<CommunityId>,
|
||||||
|
pool: &mut DbPool<'_>,
|
||||||
|
) -> LemmyResult<()> {
|
||||||
|
if let Some(community_id) = community_id {
|
||||||
|
check_community_mod_action(&local_user_view.person, community_id, false, pool).await?;
|
||||||
|
} else {
|
||||||
|
is_admin(local_user_view)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_post_deleted_or_removed(post: &Post) -> Result<(), LemmyError> {
|
pub fn check_post_deleted_or_removed(post: &Post) -> Result<(), LemmyError> {
|
||||||
|
|
|
@ -6,8 +6,7 @@ use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
send_activity::{ActivityChannel, SendActivityData},
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{
|
utils::{
|
||||||
check_community_ban,
|
check_community_user_action,
|
||||||
check_community_deleted_or_removed,
|
|
||||||
check_post_deleted_or_removed,
|
check_post_deleted_or_removed,
|
||||||
generate_local_apub_endpoint,
|
generate_local_apub_endpoint,
|
||||||
get_post,
|
get_post,
|
||||||
|
@ -57,8 +56,7 @@ pub async fn create_comment(
|
||||||
let post = get_post(post_id, &mut context.pool()).await?;
|
let post = get_post(post_id, &mut context.pool()).await?;
|
||||||
let community_id = post.community_id;
|
let community_id = post.community_id;
|
||||||
|
|
||||||
check_community_ban(local_user_view.person.id, community_id, &mut context.pool()).await?;
|
check_community_user_action(&local_user_view.person, community_id, &mut context.pool()).await?;
|
||||||
check_community_deleted_or_removed(community_id, &mut context.pool()).await?;
|
|
||||||
check_post_deleted_or_removed(&post)?;
|
check_post_deleted_or_removed(&post)?;
|
||||||
|
|
||||||
// Check if post is locked, no new comments
|
// Check if post is locked, no new comments
|
||||||
|
|
|
@ -5,7 +5,7 @@ use lemmy_api_common::{
|
||||||
comment::{CommentResponse, DeleteComment},
|
comment::{CommentResponse, DeleteComment},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
send_activity::{ActivityChannel, SendActivityData},
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::check_community_ban,
|
utils::check_community_user_action,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -31,8 +31,8 @@ pub async fn delete_comment(
|
||||||
Err(LemmyErrorType::CouldntUpdateComment)?
|
Err(LemmyErrorType::CouldntUpdateComment)?
|
||||||
}
|
}
|
||||||
|
|
||||||
check_community_ban(
|
check_community_user_action(
|
||||||
local_user_view.person.id,
|
&local_user_view.person,
|
||||||
orig_comment.community.id,
|
orig_comment.community.id,
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,7 +5,7 @@ use lemmy_api_common::{
|
||||||
comment::{CommentResponse, RemoveComment},
|
comment::{CommentResponse, RemoveComment},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
send_activity::{ActivityChannel, SendActivityData},
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{check_community_ban, is_mod_or_admin},
|
utils::check_community_mod_action,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -27,21 +27,14 @@ pub async fn remove_comment(
|
||||||
let comment_id = data.comment_id;
|
let comment_id = data.comment_id;
|
||||||
let orig_comment = CommentView::read(&mut context.pool(), comment_id, None).await?;
|
let orig_comment = CommentView::read(&mut context.pool(), comment_id, None).await?;
|
||||||
|
|
||||||
check_community_ban(
|
check_community_mod_action(
|
||||||
local_user_view.person.id,
|
&local_user_view.person,
|
||||||
orig_comment.community.id,
|
orig_comment.community.id,
|
||||||
|
false,
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// Verify that only a mod or admin can remove
|
|
||||||
is_mod_or_admin(
|
|
||||||
&mut context.pool(),
|
|
||||||
local_user_view.person.id,
|
|
||||||
orig_comment.community.id,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
// Do the remove
|
// Do the remove
|
||||||
let removed = data.removed;
|
let removed = data.removed;
|
||||||
let updated_comment = Comment::update(
|
let updated_comment = Comment::update(
|
||||||
|
|
|
@ -5,7 +5,7 @@ use lemmy_api_common::{
|
||||||
comment::{CommentResponse, EditComment},
|
comment::{CommentResponse, EditComment},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
send_activity::{ActivityChannel, SendActivityData},
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{check_community_ban, local_site_to_slur_regex},
|
utils::{check_community_user_action, local_site_to_slur_regex},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -37,8 +37,8 @@ pub async fn update_comment(
|
||||||
let comment_id = data.comment_id;
|
let comment_id = data.comment_id;
|
||||||
let orig_comment = CommentView::read(&mut context.pool(), comment_id, None).await?;
|
let orig_comment = CommentView::read(&mut context.pool(), comment_id, None).await?;
|
||||||
|
|
||||||
check_community_ban(
|
check_community_user_action(
|
||||||
local_user_view.person.id,
|
&local_user_view.person,
|
||||||
orig_comment.community.id,
|
orig_comment.community.id,
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,7 +5,7 @@ use lemmy_api_common::{
|
||||||
community::{CommunityResponse, DeleteCommunity},
|
community::{CommunityResponse, DeleteCommunity},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
send_activity::{ActivityChannel, SendActivityData},
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::is_top_mod,
|
utils::{check_community_mod_action, is_top_mod},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::community::{Community, CommunityUpdateForm},
|
source::community::{Community, CommunityUpdateForm},
|
||||||
|
@ -26,6 +26,14 @@ pub async fn delete_community(
|
||||||
let community_mods =
|
let community_mods =
|
||||||
CommunityModeratorView::for_community(&mut context.pool(), community_id).await?;
|
CommunityModeratorView::for_community(&mut context.pool(), community_id).await?;
|
||||||
|
|
||||||
|
check_community_mod_action(
|
||||||
|
&local_user_view.person,
|
||||||
|
community_id,
|
||||||
|
true,
|
||||||
|
&mut context.pool(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
// Make sure deleter is the top mod
|
// Make sure deleter is the top mod
|
||||||
is_top_mod(&local_user_view, &community_mods)?;
|
is_top_mod(&local_user_view, &community_mods)?;
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ use lemmy_api_common::{
|
||||||
community::{CommunityResponse, RemoveCommunity},
|
community::{CommunityResponse, RemoveCommunity},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
send_activity::{ActivityChannel, SendActivityData},
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::is_admin,
|
utils::{check_community_mod_action, is_admin},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -26,6 +26,14 @@ pub async fn remove_community(
|
||||||
context: Data<LemmyContext>,
|
context: Data<LemmyContext>,
|
||||||
local_user_view: LocalUserView,
|
local_user_view: LocalUserView,
|
||||||
) -> Result<Json<CommunityResponse>, LemmyError> {
|
) -> Result<Json<CommunityResponse>, LemmyError> {
|
||||||
|
check_community_mod_action(
|
||||||
|
&local_user_view.person,
|
||||||
|
data.community_id,
|
||||||
|
true,
|
||||||
|
&mut context.pool(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
// Verify its an admin (only an admin can remove a community)
|
// Verify its an admin (only an admin can remove a community)
|
||||||
is_admin(&local_user_view)?;
|
is_admin(&local_user_view)?;
|
||||||
|
|
||||||
|
|
|
@ -5,10 +5,9 @@ use lemmy_api_common::{
|
||||||
community::{CommunityResponse, EditCommunity},
|
community::{CommunityResponse, EditCommunity},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
send_activity::{ActivityChannel, SendActivityData},
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::local_site_to_slur_regex,
|
utils::{check_community_mod_action, local_site_to_slur_regex},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::PersonId,
|
|
||||||
source::{
|
source::{
|
||||||
actor_language::{CommunityLanguage, SiteLanguage},
|
actor_language::{CommunityLanguage, SiteLanguage},
|
||||||
community::{Community, CommunityUpdateForm},
|
community::{Community, CommunityUpdateForm},
|
||||||
|
@ -18,7 +17,6 @@ use lemmy_db_schema::{
|
||||||
utils::{diesel_option_overwrite, diesel_option_overwrite_to_url, naive_now},
|
utils::{diesel_option_overwrite, diesel_option_overwrite_to_url, naive_now},
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::LocalUserView;
|
use lemmy_db_views::structs::LocalUserView;
|
||||||
use lemmy_db_views_actor::structs::CommunityModeratorView;
|
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
error::{LemmyError, LemmyErrorExt, LemmyErrorType},
|
error::{LemmyError, LemmyErrorExt, LemmyErrorType},
|
||||||
utils::{slurs::check_slurs_opt, validation::is_valid_body_field},
|
utils::{slurs::check_slurs_opt, validation::is_valid_body_field},
|
||||||
|
@ -42,14 +40,13 @@ pub async fn update_community(
|
||||||
let description = diesel_option_overwrite(data.description.clone());
|
let description = diesel_option_overwrite(data.description.clone());
|
||||||
|
|
||||||
// Verify its a mod (only mods can edit it)
|
// Verify its a mod (only mods can edit it)
|
||||||
let community_id = data.community_id;
|
check_community_mod_action(
|
||||||
let mods: Vec<PersonId> =
|
&local_user_view.person,
|
||||||
CommunityModeratorView::for_community(&mut context.pool(), community_id)
|
data.community_id,
|
||||||
.await
|
false,
|
||||||
.map(|v| v.into_iter().map(|m| m.moderator.id).collect())?;
|
&mut context.pool(),
|
||||||
if !mods.contains(&local_user_view.person.id) {
|
)
|
||||||
Err(LemmyErrorType::NotAModerator)?
|
.await?;
|
||||||
}
|
|
||||||
|
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
if let Some(languages) = data.discussion_languages.clone() {
|
if let Some(languages) = data.discussion_languages.clone() {
|
||||||
|
|
|
@ -7,8 +7,7 @@ use lemmy_api_common::{
|
||||||
request::fetch_site_data,
|
request::fetch_site_data,
|
||||||
send_activity::{ActivityChannel, SendActivityData},
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{
|
utils::{
|
||||||
check_community_ban,
|
check_community_user_action,
|
||||||
check_community_deleted_or_removed,
|
|
||||||
generate_local_apub_endpoint,
|
generate_local_apub_endpoint,
|
||||||
honeypot_check,
|
honeypot_check,
|
||||||
local_site_to_slur_regex,
|
local_site_to_slur_regex,
|
||||||
|
@ -60,13 +59,12 @@ pub async fn create_post(
|
||||||
is_valid_body_field(&data.body, true)?;
|
is_valid_body_field(&data.body, true)?;
|
||||||
check_url_scheme(&data.url)?;
|
check_url_scheme(&data.url)?;
|
||||||
|
|
||||||
check_community_ban(
|
check_community_user_action(
|
||||||
local_user_view.person.id,
|
&local_user_view.person,
|
||||||
data.community_id,
|
data.community_id,
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
check_community_deleted_or_removed(data.community_id, &mut context.pool()).await?;
|
|
||||||
|
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
let community = Community::read(&mut context.pool(), community_id).await?;
|
let community = Community::read(&mut context.pool(), community_id).await?;
|
||||||
|
@ -184,5 +182,5 @@ pub async fn create_post(
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
build_post_response(&context, community_id, person_id, post_id).await
|
build_post_response(&context, community_id, &local_user_view.person, post_id).await
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{DeletePost, PostResponse},
|
post::{DeletePost, PostResponse},
|
||||||
send_activity::{ActivityChannel, SendActivityData},
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{check_community_ban, check_community_deleted_or_removed},
|
utils::check_community_user_action,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::post::{Post, PostUpdateForm},
|
source::post::{Post, PostUpdateForm},
|
||||||
|
@ -28,13 +28,12 @@ pub async fn delete_post(
|
||||||
Err(LemmyErrorType::CouldntUpdatePost)?
|
Err(LemmyErrorType::CouldntUpdatePost)?
|
||||||
}
|
}
|
||||||
|
|
||||||
check_community_ban(
|
check_community_user_action(
|
||||||
local_user_view.person.id,
|
&local_user_view.person,
|
||||||
orig_post.community_id,
|
orig_post.community_id,
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
check_community_deleted_or_removed(orig_post.community_id, &mut context.pool()).await?;
|
|
||||||
|
|
||||||
// Verify that only the creator can delete
|
// Verify that only the creator can delete
|
||||||
if !Post::is_post_creator(local_user_view.person.id, orig_post.creator_id) {
|
if !Post::is_post_creator(local_user_view.person.id, orig_post.creator_id) {
|
||||||
|
@ -52,12 +51,17 @@ pub async fn delete_post(
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let person_id = local_user_view.person.id;
|
|
||||||
ActivityChannel::submit_activity(
|
ActivityChannel::submit_activity(
|
||||||
SendActivityData::DeletePost(post, local_user_view.person, data.0.clone()),
|
SendActivityData::DeletePost(post, local_user_view.person.clone(), data.0.clone()),
|
||||||
&context,
|
&context,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
build_post_response(&context, orig_post.community_id, person_id, data.post_id).await
|
build_post_response(
|
||||||
|
&context,
|
||||||
|
orig_post.community_id,
|
||||||
|
&local_user_view.person,
|
||||||
|
data.post_id,
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{PostResponse, RemovePost},
|
post::{PostResponse, RemovePost},
|
||||||
send_activity::{ActivityChannel, SendActivityData},
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{check_community_ban, is_mod_or_admin},
|
utils::check_community_mod_action,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -26,21 +26,14 @@ pub async fn remove_post(
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let orig_post = Post::read(&mut context.pool(), post_id).await?;
|
let orig_post = Post::read(&mut context.pool(), post_id).await?;
|
||||||
|
|
||||||
check_community_ban(
|
check_community_mod_action(
|
||||||
local_user_view.person.id,
|
&local_user_view.person,
|
||||||
orig_post.community_id,
|
orig_post.community_id,
|
||||||
|
false,
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// Verify that only the mods can remove
|
|
||||||
is_mod_or_admin(
|
|
||||||
&mut context.pool(),
|
|
||||||
local_user_view.person.id,
|
|
||||||
orig_post.community_id,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
// Update the post
|
// Update the post
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let removed = data.removed;
|
let removed = data.removed;
|
||||||
|
@ -63,12 +56,17 @@ pub async fn remove_post(
|
||||||
};
|
};
|
||||||
ModRemovePost::create(&mut context.pool(), &form).await?;
|
ModRemovePost::create(&mut context.pool(), &form).await?;
|
||||||
|
|
||||||
let person_id = local_user_view.person.id;
|
|
||||||
ActivityChannel::submit_activity(
|
ActivityChannel::submit_activity(
|
||||||
SendActivityData::RemovePost(post, local_user_view.person, data.0),
|
SendActivityData::RemovePost(post, local_user_view.person.clone(), data.0),
|
||||||
&context,
|
&context,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
build_post_response(&context, orig_post.community_id, person_id, post_id).await
|
build_post_response(
|
||||||
|
&context,
|
||||||
|
orig_post.community_id,
|
||||||
|
&local_user_view.person,
|
||||||
|
post_id,
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ use lemmy_api_common::{
|
||||||
post::{EditPost, PostResponse},
|
post::{EditPost, PostResponse},
|
||||||
request::fetch_site_data,
|
request::fetch_site_data,
|
||||||
send_activity::{ActivityChannel, SendActivityData},
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{check_community_ban, local_site_to_slur_regex},
|
utils::{check_community_user_action, local_site_to_slur_regex},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -55,8 +55,8 @@ pub async fn update_post(
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let orig_post = Post::read(&mut context.pool(), post_id).await?;
|
let orig_post = Post::read(&mut context.pool(), post_id).await?;
|
||||||
|
|
||||||
check_community_ban(
|
check_community_user_action(
|
||||||
local_user_view.person.id,
|
&local_user_view.person,
|
||||||
orig_post.community_id,
|
orig_post.community_id,
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
)
|
)
|
||||||
|
@ -107,7 +107,7 @@ pub async fn update_post(
|
||||||
build_post_response(
|
build_post_response(
|
||||||
context.deref(),
|
context.deref(),
|
||||||
orig_post.community_id,
|
orig_post.community_id,
|
||||||
local_user_view.person.id,
|
&local_user_view.person,
|
||||||
post_id,
|
post_id,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -140,7 +140,7 @@ impl ActivityHandler for CreateOrUpdateNote {
|
||||||
if distinguished != existing_comment.distinguished {
|
if distinguished != existing_comment.distinguished {
|
||||||
let creator = self.actor.dereference(context).await?;
|
let creator = self.actor.dereference(context).await?;
|
||||||
let (post, _) = self.object.get_parents(context).await?;
|
let (post, _) = self.object.get_parents(context).await?;
|
||||||
is_mod_or_admin(&mut context.pool(), creator.id, post.community_id).await?;
|
is_mod_or_admin(&mut context.pool(), &creator, post.community_id).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,9 +92,7 @@ pub(crate) async fn verify_person_in_community(
|
||||||
}
|
}
|
||||||
let person_id = person.id;
|
let person_id = person.id;
|
||||||
let community_id = community.id;
|
let community_id = community.id;
|
||||||
let is_banned = CommunityPersonBanView::get(&mut context.pool(), person_id, community_id)
|
let is_banned = CommunityPersonBanView::get(&mut context.pool(), person_id, community_id).await?;
|
||||||
.await
|
|
||||||
.is_ok();
|
|
||||||
if is_banned {
|
if is_banned {
|
||||||
Err(LemmyErrorType::PersonIsBannedFromCommunity)?
|
Err(LemmyErrorType::PersonIsBannedFromCommunity)?
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -166,7 +166,7 @@ impl Object for ApubPost {
|
||||||
let creator = page.creator()?.dereference(context).await?;
|
let creator = page.creator()?.dereference(context).await?;
|
||||||
let community = page.community(context).await?;
|
let community = page.community(context).await?;
|
||||||
if community.posting_restricted_to_mods {
|
if community.posting_restricted_to_mods {
|
||||||
is_mod_or_admin(&mut context.pool(), creator.id, community.id).await?;
|
is_mod_or_admin(&mut context.pool(), &creator, community.id).await?;
|
||||||
}
|
}
|
||||||
let mut name = page
|
let mut name = page
|
||||||
.name
|
.name
|
||||||
|
|
|
@ -11,7 +11,6 @@ use crate::{
|
||||||
traits::{ApubActor, Crud, Followable},
|
traits::{ApubActor, Crud, Followable},
|
||||||
utils::{functions::lower, get_conn, naive_now, DbPool},
|
utils::{functions::lower, get_conn, naive_now, DbPool},
|
||||||
};
|
};
|
||||||
use chrono::{DateTime, Utc};
|
|
||||||
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, JoinOnDsl, QueryDsl};
|
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, JoinOnDsl, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
|
|
||||||
|
@ -87,14 +86,6 @@ impl Person {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_banned(banned_: bool, expires: Option<DateTime<Utc>>) -> bool {
|
|
||||||
if let Some(expires) = expires {
|
|
||||||
banned_ && expires.gt(&naive_now())
|
|
||||||
} else {
|
|
||||||
banned_
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ApubActor for Person {
|
impl ApubActor for Person {
|
||||||
async fn read_from_apub_id(
|
async fn read_from_apub_id(
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
use crate::structs::CommunityPersonBanView;
|
use crate::structs::CommunityPersonBanView;
|
||||||
use diesel::{result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{dsl::exists, result::Error, select, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::{CommunityId, PersonId},
|
newtypes::{CommunityId, PersonId},
|
||||||
schema::{community, community_person_ban, person},
|
schema::community_person_ban,
|
||||||
utils::{get_conn, DbPool},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -12,16 +12,14 @@ impl CommunityPersonBanView {
|
||||||
pool: &mut DbPool<'_>,
|
pool: &mut DbPool<'_>,
|
||||||
from_person_id: PersonId,
|
from_person_id: PersonId,
|
||||||
from_community_id: CommunityId,
|
from_community_id: CommunityId,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<bool, Error> {
|
||||||
let conn = &mut get_conn(pool).await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
select(exists(
|
||||||
community_person_ban::table
|
community_person_ban::table
|
||||||
.inner_join(community::table)
|
|
||||||
.inner_join(person::table)
|
|
||||||
.select((community::all_columns, person::all_columns))
|
|
||||||
.filter(community_person_ban::community_id.eq(from_community_id))
|
.filter(community_person_ban::community_id.eq(from_community_id))
|
||||||
.filter(community_person_ban::person_id.eq(from_person_id))
|
.filter(community_person_ban::person_id.eq(from_person_id)),
|
||||||
.order_by(community_person_ban::published)
|
))
|
||||||
.first::<CommunityPersonBanView>(conn)
|
.get_result::<bool>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,11 +14,7 @@ async fn local_user_view_from_jwt(
|
||||||
) -> Result<LocalUserView, LemmyError> {
|
) -> Result<LocalUserView, LemmyError> {
|
||||||
let local_user_id = Claims::validate(jwt, context).await?;
|
let local_user_id = Claims::validate(jwt, context).await?;
|
||||||
let local_user_view = LocalUserView::read(&mut context.pool(), local_user_id).await?;
|
let local_user_view = LocalUserView::read(&mut context.pool(), local_user_id).await?;
|
||||||
check_user_valid(
|
check_user_valid(&local_user_view.person)?;
|
||||||
local_user_view.person.banned,
|
|
||||||
local_user_view.person.ban_expires,
|
|
||||||
local_user_view.person.deleted,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
Ok(local_user_view)
|
Ok(local_user_view)
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,11 +109,7 @@ async fn local_user_view_from_jwt(
|
||||||
.await
|
.await
|
||||||
.with_lemmy_type(LemmyErrorType::NotLoggedIn)?;
|
.with_lemmy_type(LemmyErrorType::NotLoggedIn)?;
|
||||||
let local_user_view = LocalUserView::read(&mut context.pool(), local_user_id).await?;
|
let local_user_view = LocalUserView::read(&mut context.pool(), local_user_id).await?;
|
||||||
check_user_valid(
|
check_user_valid(&local_user_view.person)?;
|
||||||
local_user_view.person.banned,
|
|
||||||
local_user_view.person.ban_expires,
|
|
||||||
local_user_view.person.deleted,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
Ok(local_user_view)
|
Ok(local_user_view)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue