Compare commits

...

2 Commits

Author SHA1 Message Date
Nutomic cf426493e1
Fix community add mod check (fixes #4624) (#4667) 1 month ago
Dessalines 8e3ff0408e
Fixing extra modlog entries when post_id or comment_id is given. (#4664)
- Previously when given a post_id, it didn't filter out any other
  modlog entries, such as community removals. This fixes that problem.
- Context: https://github.com/LemmyNet/lemmy-ui/pull/2437

Co-authored-by: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com>
1 month ago

2
Cargo.lock generated

@ -2588,7 +2588,7 @@ dependencies = [
"actix-web", "actix-web",
"actix-web-httpauth", "actix-web-httpauth",
"anyhow", "anyhow",
"base64 0.21.7", "base64 0.22.0",
"bcrypt", "bcrypt",
"captcha", "captcha",
"chrono", "chrono",

@ -36,9 +36,21 @@ pub async fn add_mod_to_community(
let community = Community::read(&mut context.pool(), community_id) let community = Community::read(&mut context.pool(), community_id)
.await? .await?
.ok_or(LemmyErrorType::CouldntFindCommunity)?; .ok_or(LemmyErrorType::CouldntFindCommunity)?;
// If user is admin and community is remote, explicitly check that he is a
// moderator. This is necessary because otherwise the action would be rejected
// by the community's home instance.
if local_user_view.local_user.admin && !community.local { if local_user_view.local_user.admin && !community.local {
let is_mod = CommunityModeratorView::is_community_moderator(
&mut context.pool(),
community.id,
local_user_view.person.id,
)
.await?;
if !is_mod {
Err(LemmyErrorType::NotAModerator)? Err(LemmyErrorType::NotAModerator)?
} }
}
// Update in local database // Update in local database
let community_moderator_form = CommunityModeratorForm { let community_moderator_form = CommunityModeratorForm {

@ -40,6 +40,11 @@ impl AdminPurgeCommentView {
query = query.filter(admin_purge_comment::admin_person_id.eq(admin_person_id)); query = query.filter(admin_purge_comment::admin_person_id.eq(admin_person_id));
}; };
// If a post or comment ID is given, then don't find any results
if params.post_id.is_some() || params.comment_id.is_some() {
return Ok(vec![]);
}
let (limit, offset) = limit_and_offset(params.page, params.limit)?; let (limit, offset) = limit_and_offset(params.page, params.limit)?;
query query

@ -38,6 +38,11 @@ impl AdminPurgeCommunityView {
query = query.filter(admin_purge_community::admin_person_id.eq(admin_person_id)); query = query.filter(admin_purge_community::admin_person_id.eq(admin_person_id));
}; };
// If a post or comment ID is given, then don't find any results
if params.post_id.is_some() || params.comment_id.is_some() {
return Ok(vec![]);
}
let (limit, offset) = limit_and_offset(params.page, params.limit)?; let (limit, offset) = limit_and_offset(params.page, params.limit)?;
query query

@ -38,6 +38,11 @@ impl AdminPurgePersonView {
query = query.filter(admin_purge_person::admin_person_id.eq(admin_person_id)); query = query.filter(admin_purge_person::admin_person_id.eq(admin_person_id));
}; };
// If a post or comment ID is given, then don't find any results
if params.post_id.is_some() || params.comment_id.is_some() {
return Ok(vec![]);
}
let (limit, offset) = limit_and_offset(params.page, params.limit)?; let (limit, offset) = limit_and_offset(params.page, params.limit)?;
query query

@ -40,6 +40,11 @@ impl AdminPurgePostView {
query = query.filter(admin_purge_post::admin_person_id.eq(admin_person_id)); query = query.filter(admin_purge_post::admin_person_id.eq(admin_person_id));
}; };
// If a post or comment ID is given, then don't find any results
if params.post_id.is_some() || params.comment_id.is_some() {
return Ok(vec![]);
}
let (limit, offset) = limit_and_offset(params.page, params.limit)?; let (limit, offset) = limit_and_offset(params.page, params.limit)?;
query query

@ -52,6 +52,11 @@ impl ModAddCommunityView {
query = query.filter(person_alias_1.field(person::id).eq(other_person_id)); query = query.filter(person_alias_1.field(person::id).eq(other_person_id));
}; };
// If a post or comment ID is given, then don't find any results
if params.post_id.is_some() || params.comment_id.is_some() {
return Ok(vec![]);
}
let (limit, offset) = limit_and_offset(params.page, params.limit)?; let (limit, offset) = limit_and_offset(params.page, params.limit)?;
query query

@ -44,6 +44,11 @@ impl ModAddView {
query = query.filter(person_alias_1.field(person::id).eq(other_person_id)); query = query.filter(person_alias_1.field(person::id).eq(other_person_id));
}; };
// If a post or comment ID is given, then don't find any results
if params.post_id.is_some() || params.comment_id.is_some() {
return Ok(vec![]);
}
let (limit, offset) = limit_and_offset(params.page, params.limit)?; let (limit, offset) = limit_and_offset(params.page, params.limit)?;
query query

@ -54,6 +54,11 @@ impl ModBanFromCommunityView {
query = query.filter(mod_ban_from_community::other_person_id.eq(other_person_id)); query = query.filter(mod_ban_from_community::other_person_id.eq(other_person_id));
}; };
// If a post or comment ID is given, then don't find any results
if params.post_id.is_some() || params.comment_id.is_some() {
return Ok(vec![]);
}
let (limit, offset) = limit_and_offset(params.page, params.limit)?; let (limit, offset) = limit_and_offset(params.page, params.limit)?;
query query

@ -44,6 +44,11 @@ impl ModBanView {
query = query.filter(person_alias_1.field(person::id).eq(other_person_id)); query = query.filter(person_alias_1.field(person::id).eq(other_person_id));
}; };
// If a post or comment ID is given, then don't find any results
if params.post_id.is_some() || params.comment_id.is_some() {
return Ok(vec![]);
}
let (limit, offset) = limit_and_offset(params.page, params.limit)?; let (limit, offset) = limit_and_offset(params.page, params.limit)?;
query query

@ -55,6 +55,11 @@ impl ModFeaturePostView {
query = query.filter(post::id.eq(post_id)); query = query.filter(post::id.eq(post_id));
} }
// If a comment ID is given, then don't find any results
if params.comment_id.is_some() {
return Ok(vec![]);
}
let (limit, offset) = limit_and_offset(params.page, params.limit)?; let (limit, offset) = limit_and_offset(params.page, params.limit)?;
query query

@ -45,6 +45,11 @@ impl ModHideCommunityView {
query = query.filter(mod_hide_community::mod_person_id.eq(admin_id)); query = query.filter(mod_hide_community::mod_person_id.eq(admin_id));
}; };
// If a post or comment ID is given, then don't find any results
if params.post_id.is_some() || params.comment_id.is_some() {
return Ok(vec![]);
}
let (limit, offset) = limit_and_offset(params.page, params.limit)?; let (limit, offset) = limit_and_offset(params.page, params.limit)?;
query query

@ -56,6 +56,11 @@ impl ModLockPostView {
query = query.filter(post::id.eq(post_id)); query = query.filter(post::id.eq(post_id));
} }
// If a comment ID is given, then don't find any results
if params.comment_id.is_some() {
return Ok(vec![]);
}
let (limit, offset) = limit_and_offset(params.page, params.limit)?; let (limit, offset) = limit_and_offset(params.page, params.limit)?;
query query

@ -58,6 +58,11 @@ impl ModRemoveCommentView {
query = query.filter(comment::id.eq(comment_id)); query = query.filter(comment::id.eq(comment_id));
} }
// If a post ID is given, then don't find any results
if params.post_id.is_some() {
return Ok(vec![]);
}
let (limit, offset) = limit_and_offset(params.page, params.limit)?; let (limit, offset) = limit_and_offset(params.page, params.limit)?;
query query

@ -39,6 +39,11 @@ impl ModRemoveCommunityView {
query = query.filter(mod_remove_community::mod_person_id.eq(mod_person_id)); query = query.filter(mod_remove_community::mod_person_id.eq(mod_person_id));
}; };
// If a post or comment ID is given, then don't find any results
if params.post_id.is_some() || params.comment_id.is_some() {
return Ok(vec![]);
}
let (limit, offset) = limit_and_offset(params.page, params.limit)?; let (limit, offset) = limit_and_offset(params.page, params.limit)?;
query query

@ -56,6 +56,11 @@ impl ModRemovePostView {
query = query.filter(post::id.eq(post_id)); query = query.filter(post::id.eq(post_id));
} }
// If a comment ID is given, then don't find any results
if params.comment_id.is_some() {
return Ok(vec![]);
}
let (limit, offset) = limit_and_offset(params.page, params.limit)?; let (limit, offset) = limit_and_offset(params.page, params.limit)?;
query query

@ -54,6 +54,11 @@ impl ModTransferCommunityView {
query = query.filter(person_alias_1.field(person::id).eq(other_person_id)); query = query.filter(person_alias_1.field(person::id).eq(other_person_id));
}; };
// If a post or comment ID is given, then don't find any results
if params.post_id.is_some() || params.comment_id.is_some() {
return Ok(vec![]);
}
let (limit, offset) = limit_and_offset(params.page, params.limit)?; let (limit, offset) = limit_and_offset(params.page, params.limit)?;
query query

Loading…
Cancel
Save