Browse Source

Merge branch 'rework/react-v2' of gitlab.com:chapo-sandbox/lemmy into rework/react-v2

pull/269/head
GreatBearShark 1 year ago
parent
commit
d5c77ff6a0
  1. 19
      server/src/api/community.rs
  2. 3
      server/src/api/user.rs

19
server/src/api/community.rs

@ -295,8 +295,15 @@ impl Perform for Oper<CreateCommunity> {
.await??,
);
// ...but let admins create them anyway
if !admins.contains(&user_id) {
let mut sitemods: Vec<i32> = vec![];
sitemods.append(
&mut blocking(pool, move |conn| {
UserView::sitemods(conn).map(|v| v.into_iter().map(|s| s.id).collect())
})
.await??,
);
// ...but let admins/sitemods create them anyway
if !(admins.contains(&user_id) || sitemods.contains(&user_id)) {
return Err(APIError::err("create_community_disabled").into());
}
}
@ -918,9 +925,11 @@ impl Perform for Oper<TransferCommunity> {
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).any(|x| x == user_id) {
return Err(APIError::err("not_an_admin").into());
// Make sure user is the creator, or an admin, or sitemod
if user_id != read_community.creator_id
&& !(admins.iter().map(|a| a.id).any(|x| x == user_id)
|| sitemods.iter().map(|a| a.id).any(|x| x == user_id)) {
return Err(APIError::err("not_an_admin_or_sitemod").into());
}
let community_form = CommunityForm {

3
server/src/api/user.rs

@ -1017,9 +1017,6 @@ impl Perform for Oper<AddSitemod> {
blocking(pool, move |conn| ModAdd::create(conn, &form)).await??;
let site_creator_id =
blocking(pool, move |conn| Site::read(conn, 1).map(|s| s.creator_id)).await??;
let sitemods = blocking(pool, move |conn| UserView::sitemods(conn)).await??;
let res = AddSitemodResponse { sitemods };

Loading…
Cancel
Save