summaryrefslogtreecommitdiffstats
path: root/server/src/api/community.rs
diff options
context:
space:
mode:
authorDessalines <tyhou13@gmx.com>2019-08-29 15:18:50 -0700
committerDessalines <tyhou13@gmx.com>2019-08-29 15:18:50 -0700
commit8d1db3c39542e6c76a82f9d6119e89fdcfd6e845 (patch)
tree9fc65c20d37105889185e5c35fa234e0fa836ebc /server/src/api/community.rs
parentde6ddeeca44e6f6be516f0c48f4bae503b7bdc85 (diff)
Allow admins to add mods and transfer communities
- Fixes #238
Diffstat (limited to 'server/src/api/community.rs')
-rw-r--r--server/src/api/community.rs16
1 files changed, 9 insertions, 7 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<GetCommunityResponse> for Oper<TransferCommunity> {
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::<Vec<i32>>().contains(&user_id) {
return Err(APIError::err(&self.op, "not_an_admin"))?
}
@@ -675,11 +682,6 @@ impl Perform<GetCommunityResponse> for Oper<TransferCommunity> {
}
};
- 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(