From 03f0616a7c2b00ac0e47247795308c0a35a12e88 Mon Sep 17 00:00:00 2001 From: Colin Reeder Date: Thu, 17 Sep 2020 22:04:57 -0600 Subject: Add UI for removing community moderators --- res/lang/en.ftl | 1 + src/routes/communities.rs | 67 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/res/lang/en.ftl b/res/lang/en.ftl index da13d7f..49218f8 100644 --- a/res/lang/en.ftl +++ b/res/lang/en.ftl @@ -59,6 +59,7 @@ post_not_approved = This post has not been approved by the community. preview = Preview register = Register remote = Remote +remove = remove reply = reply reply_submit = Reply reply_to = Reply to diff --git a/src/routes/communities.rs b/src/routes/communities.rs index fc2bb8d..526c89b 100644 --- a/src/routes/communities.rs +++ b/src/routes/communities.rs @@ -478,7 +478,24 @@ async fn page_community_moderators( { api_res.iter().map(|user| { render::rsx! { -
  • {user.username.as_ref()}
  • +
  • + {user.username.as_ref()} + { + if community_info.you_are_moderator == Some(true) { + Some(render::rsx! { + <> + {" "} +
    + + +
    + + }) + } else { + None + } + } +
  • } }) .collect::>() @@ -550,6 +567,49 @@ async fn handler_community_moderators_add( .body("Successfully added.".into())?) } +async fn handler_community_moderators_remove( + params: (i64,), + ctx: Arc, + req: hyper::Request, +) -> Result, crate::Error> { + let (community_id,) = params; + + let (req_parts, body) = req.into_parts(); + + let cookies = get_cookie_map_for_headers(&req_parts.headers)?; + + #[derive(Deserialize)] + struct ModeratorsRemoveParams { + user: i64, + } + + let body = hyper::body::to_bytes(body).await?; + let body: ModeratorsRemoveParams = serde_urlencoded::from_bytes(&body)?; + + res_to_error( + ctx.http_client + .request(for_client( + hyper::Request::delete(format!( + "{}/api/unstable/communities/{}/moderators/{}", + ctx.backend_host, community_id, body.user, + )) + .body(Default::default())?, + &req_parts.headers, + &cookies, + )?) + .await?, + ) + .await?; + + Ok(hyper::Response::builder() + .status(hyper::StatusCode::SEE_OTHER) + .header( + hyper::header::LOCATION, + format!("/communities/{}/moderators", community_id), + ) + .body("Successfully removed.".into())?) +} + async fn handler_community_post_approve( params: (i64, i64), ctx: Arc, @@ -868,6 +928,11 @@ pub fn route_communities() -> crate::RouteNode<()> { "add", crate::RouteNode::new() .with_handler_async("POST", handler_community_moderators_add), + ) + .with_child( + "remove", + crate::RouteNode::new() + .with_handler_async("POST", handler_community_moderators_remove), ), ) .with_child( -- cgit v1.2.3