Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow all admins to purge content #3271

Merged
merged 1 commit into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/api/src/site/purge/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use actix_web::web::Data;
use lemmy_api_common::{
context::LemmyContext,
site::{PurgeComment, PurgeItemResponse},
utils::{is_top_admin, local_user_view_from_jwt},
utils::{is_admin, local_user_view_from_jwt},
};
use lemmy_db_schema::{
source::{
Expand All @@ -23,8 +23,8 @@ impl Perform for PurgeComment {
let data: &Self = self;
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;

// Only let the top admin purge an item
is_top_admin(context.pool(), local_user_view.person.id).await?;
// Only let admin purge an item
is_admin(&local_user_view)?;

let comment_id = data.comment_id;

Expand Down
6 changes: 3 additions & 3 deletions crates/api/src/site/purge/community.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use lemmy_api_common::{
context::LemmyContext,
request::purge_image_from_pictrs,
site::{PurgeCommunity, PurgeItemResponse},
utils::{is_top_admin, local_user_view_from_jwt, purge_image_posts_for_community},
utils::{is_admin, local_user_view_from_jwt, purge_image_posts_for_community},
};
use lemmy_db_schema::{
source::{
Expand All @@ -24,8 +24,8 @@ impl Perform for PurgeCommunity {
let data: &Self = self;
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;

// Only let the top admin purge an item
is_top_admin(context.pool(), local_user_view.person.id).await?;
// Only let admin purge an item
is_admin(&local_user_view)?;

let community_id = data.community_id;

Expand Down
6 changes: 3 additions & 3 deletions crates/api/src/site/purge/person.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use lemmy_api_common::{
context::LemmyContext,
request::purge_image_from_pictrs,
site::{PurgeItemResponse, PurgePerson},
utils::{is_top_admin, local_user_view_from_jwt, purge_image_posts_for_person},
utils::{is_admin, local_user_view_from_jwt, purge_image_posts_for_person},
};
use lemmy_db_schema::{
source::{
Expand All @@ -24,8 +24,8 @@ impl Perform for PurgePerson {
let data: &Self = self;
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;

// Only let the top admin purge an item
is_top_admin(context.pool(), local_user_view.person.id).await?;
// Only let admin purge an item
is_admin(&local_user_view)?;

// Read the person to get their images
let person_id = data.person_id;
Expand Down
6 changes: 3 additions & 3 deletions crates/api/src/site/purge/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use lemmy_api_common::{
context::LemmyContext,
request::purge_image_from_pictrs,
site::{PurgeItemResponse, PurgePost},
utils::{is_top_admin, local_user_view_from_jwt},
utils::{is_admin, local_user_view_from_jwt},
};
use lemmy_db_schema::{
source::{
Expand All @@ -24,8 +24,8 @@ impl Perform for PurgePost {
let data: &Self = self;
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;

// Only let the top admin purge an item
is_top_admin(context.pool(), local_user_view.person.id).await?;
// Only let admin purge an item
is_admin(&local_user_view)?;

let post_id = data.post_id;

Expand Down
13 changes: 0 additions & 13 deletions crates/api_common/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ use lemmy_db_views_actor::structs::{
CommunityModeratorView,
CommunityPersonBanView,
CommunityView,
PersonView,
};
use lemmy_utils::{
claims::Claims,
Expand Down Expand Up @@ -79,18 +78,6 @@ pub async fn is_mod_or_admin_opt(
}
}

pub async fn is_top_admin(pool: &DbPool, person_id: PersonId) -> Result<(), LemmyError> {
let admins = PersonView::admins(pool).await?;
let top_admin = admins
.first()
.ok_or_else(|| LemmyError::from_message("no admins"))?;

if top_admin.person.id != person_id {
return Err(LemmyError::from_message("not_top_admin"));
}
Ok(())
}

pub fn is_admin(local_user_view: &LocalUserView) -> Result<(), LemmyError> {
if !local_user_view.person.admin {
return Err(LemmyError::from_message("not_an_admin"));
Expand Down