mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-10 02:05:10 +00:00
feat: allow all admins to purge content (#3271)
This commit is contained in:
parent
203e35899e
commit
21d5349785
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
site::{PurgeComment, PurgeItemResponse},
|
site::{PurgeComment, PurgeItemResponse},
|
||||||
utils::{is_top_admin, local_user_view_from_jwt},
|
utils::{is_admin, local_user_view_from_jwt},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -23,8 +23,8 @@ impl Perform for PurgeComment {
|
||||||
let data: &Self = self;
|
let data: &Self = self;
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
|
|
||||||
// Only let the top admin purge an item
|
// Only let admin purge an item
|
||||||
is_top_admin(context.pool(), local_user_view.person.id).await?;
|
is_admin(&local_user_view)?;
|
||||||
|
|
||||||
let comment_id = data.comment_id;
|
let comment_id = data.comment_id;
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
request::purge_image_from_pictrs,
|
request::purge_image_from_pictrs,
|
||||||
site::{PurgeCommunity, PurgeItemResponse},
|
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::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -24,8 +24,8 @@ impl Perform for PurgeCommunity {
|
||||||
let data: &Self = self;
|
let data: &Self = self;
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
|
|
||||||
// Only let the top admin purge an item
|
// Only let admin purge an item
|
||||||
is_top_admin(context.pool(), local_user_view.person.id).await?;
|
is_admin(&local_user_view)?;
|
||||||
|
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
request::purge_image_from_pictrs,
|
request::purge_image_from_pictrs,
|
||||||
site::{PurgeItemResponse, PurgePerson},
|
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::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -24,8 +24,8 @@ impl Perform for PurgePerson {
|
||||||
let data: &Self = self;
|
let data: &Self = self;
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
|
|
||||||
// Only let the top admin purge an item
|
// Only let admin purge an item
|
||||||
is_top_admin(context.pool(), local_user_view.person.id).await?;
|
is_admin(&local_user_view)?;
|
||||||
|
|
||||||
// Read the person to get their images
|
// Read the person to get their images
|
||||||
let person_id = data.person_id;
|
let person_id = data.person_id;
|
||||||
|
|
|
@ -4,7 +4,7 @@ use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
request::purge_image_from_pictrs,
|
request::purge_image_from_pictrs,
|
||||||
site::{PurgeItemResponse, PurgePost},
|
site::{PurgeItemResponse, PurgePost},
|
||||||
utils::{is_top_admin, local_user_view_from_jwt},
|
utils::{is_admin, local_user_view_from_jwt},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -24,8 +24,8 @@ impl Perform for PurgePost {
|
||||||
let data: &Self = self;
|
let data: &Self = self;
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
|
|
||||||
// Only let the top admin purge an item
|
// Only let admin purge an item
|
||||||
is_top_admin(context.pool(), local_user_view.person.id).await?;
|
is_admin(&local_user_view)?;
|
||||||
|
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,6 @@ use lemmy_db_views_actor::structs::{
|
||||||
CommunityModeratorView,
|
CommunityModeratorView,
|
||||||
CommunityPersonBanView,
|
CommunityPersonBanView,
|
||||||
CommunityView,
|
CommunityView,
|
||||||
PersonView,
|
|
||||||
};
|
};
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
claims::Claims,
|
claims::Claims,
|
||||||
|
@ -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> {
|
pub fn is_admin(local_user_view: &LocalUserView) -> Result<(), LemmyError> {
|
||||||
if !local_user_view.person.admin {
|
if !local_user_view.person.admin {
|
||||||
return Err(LemmyError::from_message("not_an_admin"));
|
return Err(LemmyError::from_message("not_an_admin"));
|
||||||
|
|
Loading…
Reference in a new issue