From: Dessalines Date: Fri, 19 Nov 2021 20:56:41 +0000 (-0500) Subject: Adding a banned endpoint for admins. Removing it from GetSite. Fixes #1806 X-Git-Url: http://these/git/%22https:/nerdica.net/photo/contact/80/README.md?a=commitdiff_plain;h=bd31475dba8f7f32d35a124c01dee5126d913933;p=lemmy.git Adding a banned endpoint for admins. Removing it from GetSite. Fixes #1806 --- diff --git a/crates/api/src/lib.rs b/crates/api/src/lib.rs index 26a41d3d..3cffe016 100644 --- a/crates/api/src/lib.rs +++ b/crates/api/src/lib.rs @@ -48,6 +48,9 @@ pub async fn match_websocket_operation( do_websocket_operation::(context, id, op, data).await } UserOperation::BanPerson => do_websocket_operation::(context, id, op, data).await, + UserOperation::GetBannedPersons => { + do_websocket_operation::(context, id, op, data).await + } UserOperation::BlockPerson => { do_websocket_operation::(context, id, op, data).await } diff --git a/crates/api/src/local_user.rs b/crates/api/src/local_user.rs index 781a581a..8a2d2a92 100644 --- a/crates/api/src/local_user.rs +++ b/crates/api/src/local_user.rs @@ -528,6 +528,30 @@ impl Perform for BanPerson { } } +#[async_trait::async_trait(?Send)] +impl Perform for GetBannedPersons { + type Response = BannedPersonsResponse; + + async fn perform( + &self, + context: &Data, + _websocket_id: Option, + ) -> Result { + let data: &GetBannedPersons = self; + let local_user_view = + get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + + // Make sure user is an admin + is_admin(&local_user_view)?; + + let banned = blocking(context.pool(), PersonViewSafe::banned).await??; + + let res = Self::Response { banned }; + + Ok(res) + } +} + #[async_trait::async_trait(?Send)] impl Perform for BlockPerson { type Response = BlockPersonResponse; diff --git a/crates/api/src/site.rs b/crates/api/src/site.rs index fdcd91cf..04cd099e 100644 --- a/crates/api/src/site.rs +++ b/crates/api/src/site.rs @@ -510,7 +510,6 @@ impl Perform for TransferSite { let creator_person = admins.remove(creator_index); admins.insert(0, creator_person); - let banned = blocking(context.pool(), PersonViewSafe::banned).await??; let federated_instances = build_federated_instances( context.pool(), &context.settings().federation, @@ -521,7 +520,6 @@ impl Perform for TransferSite { Ok(GetSiteResponse { site_view: Some(site_view), admins, - banned, online: 0, version: version::VERSION.to_string(), my_user: None, diff --git a/crates/api_common/src/person.rs b/crates/api_common/src/person.rs index 47c26591..0b5da49f 100644 --- a/crates/api_common/src/person.rs +++ b/crates/api_common/src/person.rs @@ -145,6 +145,16 @@ pub struct BanPerson { pub auth: Sensitive, } +#[derive(Debug, Serialize, Deserialize)] +pub struct GetBannedPersons { + pub auth: String, +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct BannedPersonsResponse { + pub banned: Vec, +} + #[derive(Debug, Serialize, Deserialize, Clone)] pub struct BanPersonResponse { pub person_view: PersonViewSafe, diff --git a/crates/api_common/src/site.rs b/crates/api_common/src/site.rs index b53b99d4..07f7e853 100644 --- a/crates/api_common/src/site.rs +++ b/crates/api_common/src/site.rs @@ -139,7 +139,6 @@ pub struct SiteResponse { pub struct GetSiteResponse { pub site_view: Option, // Because the site might not be set up yet pub admins: Vec, - pub banned: Vec, pub online: usize, pub version: String, pub my_user: Option, diff --git a/crates/api_crud/src/site/read.rs b/crates/api_crud/src/site/read.rs index 06146b96..229d5939 100644 --- a/crates/api_crud/src/site/read.rs +++ b/crates/api_crud/src/site/read.rs @@ -92,8 +92,6 @@ impl PerformCrud for GetSite { } } - let banned = blocking(context.pool(), PersonViewSafe::banned).await??; - let online = context .chat_server() .send(GetUsersOnline) @@ -160,7 +158,6 @@ impl PerformCrud for GetSite { Ok(GetSiteResponse { site_view, admins, - banned, online, version: version::VERSION.to_string(), my_user, diff --git a/crates/websocket/src/lib.rs b/crates/websocket/src/lib.rs index 5a132a18..e5c2730f 100644 --- a/crates/websocket/src/lib.rs +++ b/crates/websocket/src/lib.rs @@ -130,6 +130,7 @@ pub enum UserOperation { ListRegistrationApplications, ApproveRegistrationApplication, BanPerson, + GetBannedPersons, Search, ResolveObject, MarkAllAsRead, diff --git a/src/api_routes.rs b/src/api_routes.rs index 88466485..5d5fe876 100644 --- a/src/api_routes.rs +++ b/src/api_routes.rs @@ -181,6 +181,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) { .route("/join", web::post().to(route_post::)) // Admin action. I don't like that it's in /user .route("/ban", web::post().to(route_post::)) + .route("/banned", web::get().to(route_get::)) .route("/block", web::post().to(route_post::)) // Account actions. I don't like that they're in /user maybe /accounts .route("/login", web::post().to(route_post::))