lemmy/crates/api/src/local_user/list_banned.rs

27 lines
781 B
Rust
Raw Normal View History

2022-04-13 18:12:25 +00:00
use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
context::LemmyContext,
2022-04-13 18:12:25 +00:00
person::{BannedPersonsResponse, GetBannedPersons},
utils::{is_admin, local_user_view_from_jwt},
2022-04-13 18:12:25 +00:00
};
use lemmy_db_views_actor::structs::PersonView;
use lemmy_utils::error::LemmyError;
2022-04-13 18:12:25 +00:00
#[async_trait::async_trait(?Send)]
impl Perform for GetBannedPersons {
type Response = BannedPersonsResponse;
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
2022-04-13 18:12:25 +00:00
let data: &GetBannedPersons = self;
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
2022-04-13 18:12:25 +00:00
// Make sure user is an admin
is_admin(&local_user_view)?;
let banned = PersonView::banned(context.pool()).await?;
2022-04-13 18:12:25 +00:00
Ok(Self::Response { banned })
2022-04-13 18:12:25 +00:00
}
}