Adding a banned endpoint for admins. Removing it from GetSite. Fixes #1806

add_banned_persons_endpoint
Dessalines 2021-11-19 15:56:41 -05:00
parent b733df2903
commit bd31475dba
8 changed files with 39 additions and 6 deletions

View File

@ -48,6 +48,9 @@ pub async fn match_websocket_operation(
do_websocket_operation::<ApproveRegistrationApplication>(context, id, op, data).await do_websocket_operation::<ApproveRegistrationApplication>(context, id, op, data).await
} }
UserOperation::BanPerson => do_websocket_operation::<BanPerson>(context, id, op, data).await, UserOperation::BanPerson => do_websocket_operation::<BanPerson>(context, id, op, data).await,
UserOperation::GetBannedPersons => {
do_websocket_operation::<GetBannedPersons>(context, id, op, data).await
}
UserOperation::BlockPerson => { UserOperation::BlockPerson => {
do_websocket_operation::<BlockPerson>(context, id, op, data).await do_websocket_operation::<BlockPerson>(context, id, op, data).await
} }

View File

@ -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<LemmyContext>,
_websocket_id: Option<ConnectionId>,
) -> Result<Self::Response, LemmyError> {
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)] #[async_trait::async_trait(?Send)]
impl Perform for BlockPerson { impl Perform for BlockPerson {
type Response = BlockPersonResponse; type Response = BlockPersonResponse;

View File

@ -510,7 +510,6 @@ impl Perform for TransferSite {
let creator_person = admins.remove(creator_index); let creator_person = admins.remove(creator_index);
admins.insert(0, creator_person); admins.insert(0, creator_person);
let banned = blocking(context.pool(), PersonViewSafe::banned).await??;
let federated_instances = build_federated_instances( let federated_instances = build_federated_instances(
context.pool(), context.pool(),
&context.settings().federation, &context.settings().federation,
@ -521,7 +520,6 @@ impl Perform for TransferSite {
Ok(GetSiteResponse { Ok(GetSiteResponse {
site_view: Some(site_view), site_view: Some(site_view),
admins, admins,
banned,
online: 0, online: 0,
version: version::VERSION.to_string(), version: version::VERSION.to_string(),
my_user: None, my_user: None,

View File

@ -145,6 +145,16 @@ pub struct BanPerson {
pub auth: Sensitive<String>, pub auth: Sensitive<String>,
} }
#[derive(Debug, Serialize, Deserialize)]
pub struct GetBannedPersons {
pub auth: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct BannedPersonsResponse {
pub banned: Vec<PersonViewSafe>,
}
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
pub struct BanPersonResponse { pub struct BanPersonResponse {
pub person_view: PersonViewSafe, pub person_view: PersonViewSafe,

View File

@ -139,7 +139,6 @@ pub struct SiteResponse {
pub struct GetSiteResponse { pub struct GetSiteResponse {
pub site_view: Option<SiteView>, // Because the site might not be set up yet pub site_view: Option<SiteView>, // Because the site might not be set up yet
pub admins: Vec<PersonViewSafe>, pub admins: Vec<PersonViewSafe>,
pub banned: Vec<PersonViewSafe>,
pub online: usize, pub online: usize,
pub version: String, pub version: String,
pub my_user: Option<MyUserInfo>, pub my_user: Option<MyUserInfo>,

View File

@ -92,8 +92,6 @@ impl PerformCrud for GetSite {
} }
} }
let banned = blocking(context.pool(), PersonViewSafe::banned).await??;
let online = context let online = context
.chat_server() .chat_server()
.send(GetUsersOnline) .send(GetUsersOnline)
@ -160,7 +158,6 @@ impl PerformCrud for GetSite {
Ok(GetSiteResponse { Ok(GetSiteResponse {
site_view, site_view,
admins, admins,
banned,
online, online,
version: version::VERSION.to_string(), version: version::VERSION.to_string(),
my_user, my_user,

View File

@ -130,6 +130,7 @@ pub enum UserOperation {
ListRegistrationApplications, ListRegistrationApplications,
ApproveRegistrationApplication, ApproveRegistrationApplication,
BanPerson, BanPerson,
GetBannedPersons,
Search, Search,
ResolveObject, ResolveObject,
MarkAllAsRead, MarkAllAsRead,

View File

@ -181,6 +181,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) {
.route("/join", web::post().to(route_post::<UserJoin>)) .route("/join", web::post().to(route_post::<UserJoin>))
// Admin action. I don't like that it's in /user // Admin action. I don't like that it's in /user
.route("/ban", web::post().to(route_post::<BanPerson>)) .route("/ban", web::post().to(route_post::<BanPerson>))
.route("/banned", web::get().to(route_get::<GetBannedPersons>))
.route("/block", web::post().to(route_post::<BlockPerson>)) .route("/block", web::post().to(route_post::<BlockPerson>))
// Account actions. I don't like that they're in /user maybe /accounts // Account actions. I don't like that they're in /user maybe /accounts
.route("/login", web::post().to(route_post::<Login>)) .route("/login", web::post().to(route_post::<Login>))