summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Reeder <colin@vpzom.click>2020-09-17 22:04:57 -0600
committerColin Reeder <colin@vpzom.click>2020-09-17 22:04:57 -0600
commit03f0616a7c2b00ac0e47247795308c0a35a12e88 (patch)
tree883586445642766fb6515a5dbfa923b3f576d92a
parent5a0cd2b9310417536603ad8f051d9fa8b3e65e69 (diff)
Add UI for removing community moderators
-rw-r--r--res/lang/en.ftl1
-rw-r--r--src/routes/communities.rs67
2 files changed, 67 insertions, 1 deletions
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! {
- <li><a href={format!("/users/{}", user.id)}>{user.username.as_ref()}</a></li>
+ <li>
+ <a href={format!("/users/{}", user.id)}>{user.username.as_ref()}</a>
+ {
+ if community_info.you_are_moderator == Some(true) {
+ Some(render::rsx! {
+ <>
+ {" "}
+ <form class={"inline"} method={"POST"} action={format!("/communities/{}/moderators/remove", community_id)}>
+ <input type={"hidden"} name={"user"} value={user.id.to_string()} />
+ <button type={"submit"}>{lang.tr("remove", None)}</button>
+ </form>
+ </>
+ })
+ } else {
+ None
+ }
+ }
+ </li>
}
})
.collect::<Vec<_>>()
@@ -550,6 +567,49 @@ async fn handler_community_moderators_add(
.body("Successfully added.".into())?)
}
+async fn handler_community_moderators_remove(
+ params: (i64,),
+ ctx: Arc<crate::RouteContext>,
+ req: hyper::Request<hyper::Body>,
+) -> Result<hyper::Response<hyper::Body>, 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<crate::RouteContext>,
@@ -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(