From 8d1db3c39542e6c76a82f9d6119e89fdcfd6e845 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Thu, 29 Aug 2019 15:18:50 -0700 Subject: [PATCH] Allow admins to add mods and transfer communities - Fixes #238 --- server/src/api/community.rs | 16 +++++++++------- ui/src/components/comment-node.tsx | 6 ++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/server/src/api/community.rs b/server/src/api/community.rs index 37bc20db..a278aa14 100644 --- a/server/src/api/community.rs +++ b/server/src/api/community.rs @@ -605,8 +605,15 @@ impl Perform for Oper { let read_community = Community::read(&conn, data.community_id)?; - // Make sure user is the creator - if read_community.creator_id != user_id { + let site_creator_id = Site::read(&conn, 1)?.creator_id; + let mut admins = UserView::admins(&conn)?; + let creator_index = admins.iter().position(|r| r.id == site_creator_id).unwrap(); + let creator_user = admins.remove(creator_index); + admins.insert(0, creator_user); + + + // Make sure user is the creator, or an admin + if user_id != read_community.creator_id && !admins.iter().map(|a| a.id).collect::>().contains(&user_id) { return Err(APIError::err(&self.op, "not_an_admin"))? } @@ -675,11 +682,6 @@ impl Perform for Oper { } }; - let site_creator_id = Site::read(&conn, 1)?.creator_id; - let mut admins = UserView::admins(&conn)?; - let creator_index = admins.iter().position(|r| r.id == site_creator_id).unwrap(); - let creator_user = admins.remove(creator_index); - admins.insert(0, creator_user); // Return the jwt Ok( diff --git a/ui/src/components/comment-node.tsx b/ui/src/components/comment-node.tsx index f26275c8..8779f1f9 100644 --- a/ui/src/components/comment-node.tsx +++ b/ui/src/components/comment-node.tsx @@ -152,8 +152,8 @@ export class CommentNode extends Component { } } - {/* Community creators can transfer community to another mod */} - {this.amCommunityCreator && this.isMod && + {/* Community creators and admins can transfer community to another mod */} + {(this.amCommunityCreator || this.canAdmin) && this.isMod &&
  • {!this.state.showConfirmTransferCommunity ? # @@ -491,6 +491,7 @@ export class CommentNode extends Component { user_id: i.props.node.comment.creator_id, }; WebSocketService.Instance.transferCommunity(form); + i.state.showConfirmTransferCommunity = false; i.setState(i.state); } @@ -509,6 +510,7 @@ export class CommentNode extends Component { user_id: i.props.node.comment.creator_id, }; WebSocketService.Instance.transferSite(form); + i.state.showConfirmTransferSite = false; i.setState(i.state); } -- 2.44.1