]> Untitled Git - lemmy.git/blob - crates/api/src/local_user/list_banned.rs
Add cargo feature for building lemmy_api_common with mininum deps (#2243)
[lemmy.git] / crates / api / src / local_user / list_banned.rs
1 use crate::Perform;
2 use actix_web::web::Data;
3 use lemmy_api_common::{
4   person::{BannedPersonsResponse, GetBannedPersons},
5   utils::{blocking, get_local_user_view_from_jwt, is_admin},
6 };
7 use lemmy_db_views_actor::structs::PersonViewSafe;
8 use lemmy_utils::{ConnectionId, LemmyError};
9 use lemmy_websocket::LemmyContext;
10
11 #[async_trait::async_trait(?Send)]
12 impl Perform for GetBannedPersons {
13   type Response = BannedPersonsResponse;
14
15   async fn perform(
16     &self,
17     context: &Data<LemmyContext>,
18     _websocket_id: Option<ConnectionId>,
19   ) -> Result<Self::Response, LemmyError> {
20     let data: &GetBannedPersons = self;
21     let local_user_view =
22       get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
23
24     // Make sure user is an admin
25     is_admin(&local_user_view)?;
26
27     let banned = blocking(context.pool(), PersonViewSafe::banned).await??;
28
29     let res = Self::Response { banned };
30
31     Ok(res)
32   }
33 }