]> Untitled Git - lemmy.git/blobdiff - crates/api/src/community.rs
Removing the site creator, adding leave_admin. Fixes #1808 (#2052)
[lemmy.git] / crates / api / src / community.rs
index c0aea60224dd61f15e79e38edc639ce4e783688b..a1a44f0941462ee9256de042494db40d1b943023 100644 (file)
@@ -44,7 +44,6 @@ use lemmy_db_schema::{
     },
     person::Person,
     post::Post,
-    site::Site,
   },
   traits::{Bannable, Blockable, Crud, Followable, Joinable},
 };
@@ -214,6 +213,7 @@ impl Perform for BanFromCommunity {
 
     let community_id = data.community_id;
     let banned_person_id = data.person_id;
+    let expires = data.expires.map(naive_from_unix);
 
     // Verify that only mods or admins can ban
     is_mod_or_admin(context.pool(), local_user_view.person.id, community_id).await?;
@@ -221,6 +221,7 @@ impl Perform for BanFromCommunity {
     let community_user_ban_form = CommunityPersonBanForm {
       community_id: data.community_id,
       person_id: data.person_id,
+      expires: Some(expires),
     };
 
     let community: ApubCommunity = blocking(context.pool(), move |conn: &'_ _| {
@@ -257,6 +258,7 @@ impl Perform for BanFromCommunity {
         &community,
         &banned_person,
         &local_user_view.person.clone().into(),
+        expires,
         context,
       )
       .await?;
@@ -304,9 +306,6 @@ impl Perform for BanFromCommunity {
     }
 
     // Mod tables
-    // TODO eventually do correct expires
-    let expires = data.expires.map(naive_from_unix);
-
     let form = ModBanFromCommunityForm {
       mod_person_id: local_user_view.person.id,
       other_person_id: data.person_id,
@@ -457,20 +456,7 @@ impl Perform for TransferCommunity {
     let local_user_view =
       get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
 
-    let site_creator_id = blocking(context.pool(), move |conn| {
-      Site::read(conn, 1).map(|s| s.creator_id)
-    })
-    .await??;
-
-    let mut admins = blocking(context.pool(), PersonViewSafe::admins).await??;
-
-    // Making sure the site creator, if an admin, is at the top
-    let creator_index = admins
-      .iter()
-      .position(|r| r.person.id == site_creator_id)
-      .context(location_info!())?;
-    let creator_person = admins.remove(creator_index);
-    admins.insert(0, creator_person);
+    let admins = blocking(context.pool(), PersonViewSafe::admins).await??;
 
     // Fetch the community mods
     let community_id = data.community_id;