]> Untitled Git - lemmy.git/commitdiff
Add Modlog Filters (#2313)
authorAnon <makotech222@users.noreply.github.com>
Tue, 16 Aug 2022 11:52:04 +0000 (06:52 -0500)
committerGitHub <noreply@github.com>
Tue, 16 Aug 2022 11:52:04 +0000 (11:52 +0000)
* Fix crash running locally on windows.

* Add support for filtering mod logs

* Refactor cleanup

* Clippy fix

* Condense match statements

* Clippy fix 2

26 files changed:
crates/api/src/site/mod_log.rs
crates/api_common/src/site.rs
crates/api_crud/src/site/create.rs
crates/api_crud/src/site/update.rs
crates/db_schema/src/lib.rs
crates/db_schema/src/schema.rs
crates/db_schema/src/source/site.rs
crates/db_views_moderator/src/admin_purge_comment_view.rs
crates/db_views_moderator/src/admin_purge_community_view.rs
crates/db_views_moderator/src/admin_purge_person_view.rs
crates/db_views_moderator/src/admin_purge_post_view.rs
crates/db_views_moderator/src/mod_add_community_view.rs
crates/db_views_moderator/src/mod_add_view.rs
crates/db_views_moderator/src/mod_ban_from_community_view.rs
crates/db_views_moderator/src/mod_ban_view.rs
crates/db_views_moderator/src/mod_hide_community_view.rs
crates/db_views_moderator/src/mod_lock_post_view.rs
crates/db_views_moderator/src/mod_remove_comment_view.rs
crates/db_views_moderator/src/mod_remove_community_view.rs
crates/db_views_moderator/src/mod_remove_post_view.rs
crates/db_views_moderator/src/mod_sticky_post_view.rs
crates/db_views_moderator/src/mod_transfer_community_view.rs
crates/db_views_moderator/src/structs.rs
migrations/2022-06-12-012121_add_site_hide_modlog_names/down.sql [new file with mode: 0644]
migrations/2022-06-12-012121_add_site_hide_modlog_names/up.sql [new file with mode: 0644]
src/main.rs

index a96595da9c38a23c1def8dcb699c4f3483be321f..a3ac67b9afbd5b79303e7399458962daa0ef59bf 100644 (file)
@@ -2,7 +2,18 @@ use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
   site::{GetModlog, GetModlogResponse},
-  utils::{blocking, check_private_instance, get_local_user_view_from_jwt_opt},
+  utils::{
+    blocking,
+    check_private_instance,
+    get_local_user_view_from_jwt_opt,
+    is_admin,
+    is_mod_or_admin,
+  },
+};
+use lemmy_db_schema::{
+  newtypes::{CommunityId, PersonId},
+  source::site::Site,
+  ModlogActionType,
 };
 use lemmy_db_views_moderator::structs::{
   AdminPurgeCommentView,
@@ -20,9 +31,11 @@ use lemmy_db_views_moderator::structs::{
   ModRemovePostView,
   ModStickyPostView,
   ModTransferCommunityView,
+  ModlogListParams,
 };
 use lemmy_utils::{error::LemmyError, ConnectionId};
 use lemmy_websocket::LemmyContext;
+use ModlogActionType::*;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for GetModlog {
@@ -42,55 +55,123 @@ impl Perform for GetModlog {
 
     check_private_instance(&local_user_view, context.pool()).await?;
 
+    let type_ = data.type_.unwrap_or(All);
     let community_id = data.community_id;
-    let mod_person_id = data.mod_person_id;
-    let page = data.page;
-    let limit = data.limit;
-    let removed_posts = blocking(context.pool(), move |conn| {
-      ModRemovePostView::list(conn, community_id, mod_person_id, page, limit)
-    })
-    .await??;
 
-    let locked_posts = blocking(context.pool(), move |conn| {
-      ModLockPostView::list(conn, community_id, mod_person_id, page, limit)
-    })
-    .await??;
+    let site = blocking(context.pool(), Site::read_local_site).await??;
+    let (local_person_id, is_admin) = match local_user_view {
+      Some(s) => (s.person.id, is_admin(&s).is_ok()),
+      None => (PersonId(-1), false),
+    };
+    let community_id_value = match community_id {
+      Some(s) => s,
+      None => CommunityId(-1),
+    };
+    let is_mod_of_community = data.community_id.is_some()
+      && is_mod_or_admin(context.pool(), local_person_id, community_id_value)
+        .await
+        .is_ok();
+    let hide_modlog_names = site.hide_modlog_mod_names && !is_mod_of_community && !is_admin;
 
-    let stickied_posts = blocking(context.pool(), move |conn| {
-      ModStickyPostView::list(conn, community_id, mod_person_id, page, limit)
-    })
-    .await??;
+    let mod_person_id = if hide_modlog_names {
+      None
+    } else {
+      data.mod_person_id
+    };
+    let other_person_id = data.other_person_id;
+    let params = ModlogListParams {
+      community_id,
+      mod_person_id,
+      other_person_id,
+      page: data.page,
+      limit: data.limit,
+      hide_modlog_names,
+    };
+    let removed_posts = match type_ {
+      All | ModRemovePost => {
+        blocking(context.pool(), move |conn| {
+          ModRemovePostView::list(conn, params)
+        })
+        .await??
+      }
+      _ => Default::default(),
+    };
 
-    let removed_comments = blocking(context.pool(), move |conn| {
-      ModRemoveCommentView::list(conn, community_id, mod_person_id, page, limit)
-    })
-    .await??;
+    let locked_posts = match type_ {
+      All | ModLockPost => {
+        blocking(context.pool(), move |conn| {
+          ModLockPostView::list(conn, params)
+        })
+        .await??
+      }
+      _ => Default::default(),
+    };
 
-    let banned_from_community = blocking(context.pool(), move |conn| {
-      ModBanFromCommunityView::list(conn, community_id, mod_person_id, page, limit)
-    })
-    .await??;
+    let stickied_posts = match type_ {
+      All | ModStickyPost => {
+        blocking(context.pool(), move |conn| {
+          ModStickyPostView::list(conn, params)
+        })
+        .await??
+      }
+      _ => Default::default(),
+    };
 
-    let added_to_community = blocking(context.pool(), move |conn| {
-      ModAddCommunityView::list(conn, community_id, mod_person_id, page, limit)
-    })
-    .await??;
+    let removed_comments = match type_ {
+      All | ModRemoveComment => {
+        blocking(context.pool(), move |conn| {
+          ModRemoveCommentView::list(conn, params)
+        })
+        .await??
+      }
+      _ => Default::default(),
+    };
 
-    let transferred_to_community = blocking(context.pool(), move |conn| {
-      ModTransferCommunityView::list(conn, community_id, mod_person_id, page, limit)
-    })
-    .await??;
+    let banned_from_community = match type_ {
+      All | ModBanFromCommunity => {
+        blocking(context.pool(), move |conn| {
+          ModBanFromCommunityView::list(conn, params)
+        })
+        .await??
+      }
+      _ => Default::default(),
+    };
 
-    let hidden_communities = blocking(context.pool(), move |conn| {
-      ModHideCommunityView::list(conn, community_id, mod_person_id, page, limit)
-    })
-    .await??;
+    let added_to_community = match type_ {
+      All | ModAddCommunity => {
+        blocking(context.pool(), move |conn| {
+          ModAddCommunityView::list(conn, params)
+        })
+        .await??
+      }
+      _ => Default::default(),
+    };
+
+    let transferred_to_community = match type_ {
+      All | ModTransferCommunity => {
+        blocking(context.pool(), move |conn| {
+          ModTransferCommunityView::list(conn, params)
+        })
+        .await??
+      }
+      _ => Default::default(),
+    };
+
+    let hidden_communities = match type_ {
+      All | ModHideCommunity if other_person_id.is_none() => {
+        blocking(context.pool(), move |conn| {
+          ModHideCommunityView::list(conn, params)
+        })
+        .await??
+      }
+      _ => Default::default(),
+    };
 
     // These arrays are only for the full modlog, when a community isn't given
     let (
-      removed_communities,
       banned,
       added,
+      removed_communities,
       admin_purged_persons,
       admin_purged_communities,
       admin_purged_posts,
@@ -98,13 +179,44 @@ impl Perform for GetModlog {
     ) = if data.community_id.is_none() {
       blocking(context.pool(), move |conn| {
         Ok((
-          ModRemoveCommunityView::list(conn, mod_person_id, page, limit)?,
-          ModBanView::list(conn, mod_person_id, page, limit)?,
-          ModAddView::list(conn, mod_person_id, page, limit)?,
-          AdminPurgePersonView::list(conn, mod_person_id, page, limit)?,
-          AdminPurgeCommunityView::list(conn, mod_person_id, page, limit)?,
-          AdminPurgePostView::list(conn, mod_person_id, page, limit)?,
-          AdminPurgeCommentView::list(conn, mod_person_id, page, limit)?,
+          match type_ {
+            All | ModBan => ModBanView::list(conn, params)?,
+            _ => Default::default(),
+          },
+          match type_ {
+            All | ModAdd => ModAddView::list(conn, params)?,
+            _ => Default::default(),
+          },
+          match type_ {
+            All | ModRemoveCommunity if other_person_id.is_none() => {
+              ModRemoveCommunityView::list(conn, params)?
+            }
+            _ => Default::default(),
+          },
+          match type_ {
+            All | AdminPurgePerson if other_person_id.is_none() => {
+              AdminPurgePersonView::list(conn, params)?
+            }
+            _ => Default::default(),
+          },
+          match type_ {
+            All | AdminPurgeCommunity if other_person_id.is_none() => {
+              AdminPurgeCommunityView::list(conn, params)?
+            }
+            _ => Default::default(),
+          },
+          match type_ {
+            All | AdminPurgePost if other_person_id.is_none() => {
+              AdminPurgePostView::list(conn, params)?
+            }
+            _ => Default::default(),
+          },
+          match type_ {
+            All | AdminPurgeComment if other_person_id.is_none() => {
+              AdminPurgeCommentView::list(conn, params)?
+            }
+            _ => Default::default(),
+          },
         )) as Result<_, LemmyError>
       })
       .await??
index 8a0e16a941a9e184c4b9e89174e70889c6868496..f5098a5eec35b6e1c01a0c7de8359c9ed81ecf42 100644 (file)
@@ -2,6 +2,7 @@ use crate::sensitive::Sensitive;
 use lemmy_db_schema::{
   newtypes::{CommentId, CommunityId, PersonId, PostId},
   ListingType,
+  ModlogActionType,
   SearchType,
   SortType,
 };
@@ -83,6 +84,8 @@ pub struct GetModlog {
   pub page: Option<i64>,
   pub limit: Option<i64>,
   pub auth: Option<Sensitive<String>>,
+  pub type_: Option<ModlogActionType>,
+  pub other_person_id: Option<PersonId>,
 }
 
 #[derive(Debug, Serialize, Deserialize, Clone)]
@@ -122,6 +125,7 @@ pub struct CreateSite {
   pub default_theme: Option<String>,
   pub default_post_listing_type: Option<String>,
   pub auth: Sensitive<String>,
+  pub hide_modlog_mod_names: Option<bool>,
 }
 
 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
@@ -143,6 +147,7 @@ pub struct EditSite {
   pub default_post_listing_type: Option<String>,
   pub legal_information: Option<String>,
   pub auth: Sensitive<String>,
+  pub hide_modlog_mod_names: Option<bool>,
 }
 
 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
index 05a8c202e75b1aff480d93e0fcc61c1663c6bd41..c61e3feae2873cf7ee18d5b0156415ad7f7662b0 100644 (file)
@@ -76,6 +76,7 @@ impl PerformCrud for CreateSite {
       public_key: Some(keypair.public_key),
       default_theme: data.default_theme.clone(),
       default_post_listing_type: data.default_post_listing_type.clone(),
+      hide_modlog_mod_names: data.hide_modlog_mod_names,
       ..SiteForm::default()
     };
 
index dabd118c5777cea5ef38eb6eaeede73b979cd976..e5a56468ba3fc3aa75484df4134de15c3c9f1d3d 100644 (file)
@@ -86,6 +86,7 @@ impl PerformCrud for EditSite {
       default_theme: data.default_theme.clone(),
       default_post_listing_type: data.default_post_listing_type.clone(),
       legal_information,
+      hide_modlog_mod_names: data.hide_modlog_mod_names,
       ..SiteForm::default()
     };
 
index a89d1c987313342b13da68136941d55922b0ad8c..901ff287aa4c3ed01630d55617f6123243586a5f 100644 (file)
@@ -71,3 +71,23 @@ pub enum SubscribedType {
   NotSubscribed,
   Pending,
 }
+
+#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
+pub enum ModlogActionType {
+  All,
+  ModRemovePost,
+  ModLockPost,
+  ModStickyPost,
+  ModRemoveComment,
+  ModRemoveCommunity,
+  ModBanFromCommunity,
+  ModAddCommunity,
+  ModTransferCommunity,
+  ModAdd,
+  ModBan,
+  ModHideCommunity,
+  AdminPurgePerson,
+  AdminPurgeCommunity,
+  AdminPurgePost,
+  AdminPurgeComment,
+}
index 9416bc4377c785a2f1f7aea82e8d1ec808c7b22a..44e8e0bbc0b79920c034ff22cffee2226dd6dad0 100644 (file)
@@ -477,6 +477,7 @@ table! {
         default_theme -> Text,
         default_post_listing_type -> Text,
         legal_information -> Nullable<Text>,
+        hide_modlog_mod_names -> Bool,
     }
 }
 
index cc5b75054729f16d7699f736c0ed284c15986324..7975071c7b3d8fffb0a4280120b6e13c06173d72 100644 (file)
@@ -32,6 +32,7 @@ pub struct Site {
   pub default_theme: String,
   pub default_post_listing_type: String,
   pub legal_information: Option<String>,
+  pub hide_modlog_mod_names: bool,
 }
 
 #[derive(Default)]
@@ -61,4 +62,5 @@ pub struct SiteForm {
   pub default_theme: Option<String>,
   pub default_post_listing_type: Option<String>,
   pub legal_information: Option<Option<String>>,
+  pub hide_modlog_mod_names: Option<bool>,
 }
index 033991a8f7adc3dad60168f6ca78ece0660321bb..cd94a08548095aa40d2ade8544543ff66f8f7a18 100644 (file)
@@ -1,4 +1,4 @@
-use crate::structs::AdminPurgeCommentView;
+use crate::structs::{AdminPurgeCommentView, ModlogListParams};
 use diesel::{result::Error, *};
 use lemmy_db_schema::{
   newtypes::PersonId,
@@ -12,30 +12,33 @@ use lemmy_db_schema::{
   utils::limit_and_offset,
 };
 
-type AdminPurgeCommentViewTuple = (AdminPurgeComment, PersonSafe, Post);
+type AdminPurgeCommentViewTuple = (AdminPurgeComment, Option<PersonSafe>, Post);
 
 impl AdminPurgeCommentView {
-  pub fn list(
-    conn: &PgConnection,
-    admin_person_id: Option<PersonId>,
-    page: Option<i64>,
-    limit: Option<i64>,
-  ) -> Result<Vec<Self>, Error> {
+  pub fn list(conn: &PgConnection, params: ModlogListParams) -> Result<Vec<Self>, Error> {
+    let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
+    let show_mod_names = !params.hide_modlog_names;
+    let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
+
+    let admin_names_join = admin_purge_comment::admin_person_id
+      .eq(person::id)
+      .and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
+
     let mut query = admin_purge_comment::table
-      .inner_join(person::table.on(admin_purge_comment::admin_person_id.eq(person::id)))
+      .left_join(person::table.on(admin_names_join))
       .inner_join(post::table)
       .select((
         admin_purge_comment::all_columns,
-        Person::safe_columns_tuple(),
+        Person::safe_columns_tuple().nullable(),
         post::all_columns,
       ))
       .into_boxed();
 
-    if let Some(admin_person_id) = admin_person_id {
+    if let Some(admin_person_id) = params.mod_person_id {
       query = query.filter(admin_purge_comment::admin_person_id.eq(admin_person_id));
     };
 
-    let (limit, offset) = limit_and_offset(page, limit)?;
+    let (limit, offset) = limit_and_offset(params.page, params.limit)?;
 
     let res = query
       .limit(limit)
@@ -43,7 +46,8 @@ impl AdminPurgeCommentView {
       .order_by(admin_purge_comment::when_.desc())
       .load::<AdminPurgeCommentViewTuple>(conn)?;
 
-    Ok(Self::from_tuple_to_vec(res))
+    let results = Self::from_tuple_to_vec(res);
+    Ok(results)
   }
 }
 
index 7510779ff9db976e732c425916c9509ebc1fd2e0..80528d00b6b4139a923777b4a68f74f7061277bb 100644 (file)
@@ -1,4 +1,4 @@
-use crate::structs::AdminPurgeCommunityView;
+use crate::structs::{AdminPurgeCommunityView, ModlogListParams};
 use diesel::{result::Error, *};
 use lemmy_db_schema::{
   newtypes::PersonId,
@@ -11,28 +11,31 @@ use lemmy_db_schema::{
   utils::limit_and_offset,
 };
 
-type AdminPurgeCommunityViewTuple = (AdminPurgeCommunity, PersonSafe);
+type AdminPurgeCommunityViewTuple = (AdminPurgeCommunity, Option<PersonSafe>);
 
 impl AdminPurgeCommunityView {
-  pub fn list(
-    conn: &PgConnection,
-    admin_person_id: Option<PersonId>,
-    page: Option<i64>,
-    limit: Option<i64>,
-  ) -> Result<Vec<Self>, Error> {
+  pub fn list(conn: &PgConnection, params: ModlogListParams) -> Result<Vec<Self>, Error> {
+    let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
+    let show_mod_names = !params.hide_modlog_names;
+    let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
+
+    let admin_names_join = admin_purge_community::admin_person_id
+      .eq(person::id)
+      .and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
+
     let mut query = admin_purge_community::table
-      .inner_join(person::table.on(admin_purge_community::admin_person_id.eq(person::id)))
+      .left_join(person::table.on(admin_names_join))
       .select((
         admin_purge_community::all_columns,
-        Person::safe_columns_tuple(),
+        Person::safe_columns_tuple().nullable(),
       ))
       .into_boxed();
 
-    if let Some(admin_person_id) = admin_person_id {
+    if let Some(admin_person_id) = params.mod_person_id {
       query = query.filter(admin_purge_community::admin_person_id.eq(admin_person_id));
     };
 
-    let (limit, offset) = limit_and_offset(page, limit)?;
+    let (limit, offset) = limit_and_offset(params.page, params.limit)?;
 
     let res = query
       .limit(limit)
@@ -40,7 +43,8 @@ impl AdminPurgeCommunityView {
       .order_by(admin_purge_community::when_.desc())
       .load::<AdminPurgeCommunityViewTuple>(conn)?;
 
-    Ok(Self::from_tuple_to_vec(res))
+    let results = Self::from_tuple_to_vec(res);
+    Ok(results)
   }
 }
 
index eb0b714ab623fb91e7c8b89369ba5f7ada0f9bf0..84a33a53f84fa96cf397e02a2a67dd3de3854a90 100644 (file)
@@ -1,4 +1,4 @@
-use crate::structs::AdminPurgePersonView;
+use crate::structs::{AdminPurgePersonView, ModlogListParams};
 use diesel::{result::Error, *};
 use lemmy_db_schema::{
   newtypes::PersonId,
@@ -11,28 +11,30 @@ use lemmy_db_schema::{
   utils::limit_and_offset,
 };
 
-type AdminPurgePersonViewTuple = (AdminPurgePerson, PersonSafe);
+type AdminPurgePersonViewTuple = (AdminPurgePerson, Option<PersonSafe>);
 
 impl AdminPurgePersonView {
-  pub fn list(
-    conn: &PgConnection,
-    admin_person_id: Option<PersonId>,
-    page: Option<i64>,
-    limit: Option<i64>,
-  ) -> Result<Vec<Self>, Error> {
+  pub fn list(conn: &PgConnection, params: ModlogListParams) -> Result<Vec<Self>, Error> {
+    let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
+    let show_mod_names = !params.hide_modlog_names;
+    let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
+
+    let admin_names_join = admin_purge_person::admin_person_id
+      .eq(person::id)
+      .and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
     let mut query = admin_purge_person::table
-      .inner_join(person::table.on(admin_purge_person::admin_person_id.eq(person::id)))
+      .left_join(person::table.on(admin_names_join))
       .select((
         admin_purge_person::all_columns,
-        Person::safe_columns_tuple(),
+        Person::safe_columns_tuple().nullable(),
       ))
       .into_boxed();
 
-    if let Some(admin_person_id) = admin_person_id {
+    if let Some(admin_person_id) = params.mod_person_id {
       query = query.filter(admin_purge_person::admin_person_id.eq(admin_person_id));
     };
 
-    let (limit, offset) = limit_and_offset(page, limit)?;
+    let (limit, offset) = limit_and_offset(params.page, params.limit)?;
 
     let res = query
       .limit(limit)
@@ -40,7 +42,8 @@ impl AdminPurgePersonView {
       .order_by(admin_purge_person::when_.desc())
       .load::<AdminPurgePersonViewTuple>(conn)?;
 
-    Ok(Self::from_tuple_to_vec(res))
+    let results = Self::from_tuple_to_vec(res);
+    Ok(results)
   }
 }
 
index 368b7c53f23d7e65a92154eb5f75857b461a94c5..9a7f73997b6bdca4f67b408168513d13919a7591 100644 (file)
@@ -1,4 +1,4 @@
-use crate::structs::AdminPurgePostView;
+use crate::structs::{AdminPurgePostView, ModlogListParams};
 use diesel::{result::Error, *};
 use lemmy_db_schema::{
   newtypes::PersonId,
@@ -12,30 +12,32 @@ use lemmy_db_schema::{
   utils::limit_and_offset,
 };
 
-type AdminPurgePostViewTuple = (AdminPurgePost, PersonSafe, CommunitySafe);
+type AdminPurgePostViewTuple = (AdminPurgePost, Option<PersonSafe>, CommunitySafe);
 
 impl AdminPurgePostView {
-  pub fn list(
-    conn: &PgConnection,
-    admin_person_id: Option<PersonId>,
-    page: Option<i64>,
-    limit: Option<i64>,
-  ) -> Result<Vec<Self>, Error> {
+  pub fn list(conn: &PgConnection, params: ModlogListParams) -> Result<Vec<Self>, Error> {
+    let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
+    let show_mod_names = !params.hide_modlog_names;
+    let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
+
+    let admin_names_join = admin_purge_post::admin_person_id
+      .eq(person::id)
+      .and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
     let mut query = admin_purge_post::table
-      .inner_join(person::table.on(admin_purge_post::admin_person_id.eq(person::id)))
+      .left_join(person::table.on(admin_names_join))
       .inner_join(community::table)
       .select((
         admin_purge_post::all_columns,
-        Person::safe_columns_tuple(),
+        Person::safe_columns_tuple().nullable(),
         Community::safe_columns_tuple(),
       ))
       .into_boxed();
 
-    if let Some(admin_person_id) = admin_person_id {
+    if let Some(admin_person_id) = params.mod_person_id {
       query = query.filter(admin_purge_post::admin_person_id.eq(admin_person_id));
     };
 
-    let (limit, offset) = limit_and_offset(page, limit)?;
+    let (limit, offset) = limit_and_offset(params.page, params.limit)?;
 
     let res = query
       .limit(limit)
@@ -43,7 +45,8 @@ impl AdminPurgePostView {
       .order_by(admin_purge_post::when_.desc())
       .load::<AdminPurgePostViewTuple>(conn)?;
 
-    Ok(Self::from_tuple_to_vec(res))
+    let results = Self::from_tuple_to_vec(res);
+    Ok(results)
   }
 }
 
index 0182b809ea30551a9371a07eccc6b0088c80685c..4c4d8f8788e9035b15518de6fd748591871e2bdd 100644 (file)
@@ -1,7 +1,7 @@
-use crate::structs::ModAddCommunityView;
+use crate::structs::{ModAddCommunityView, ModlogListParams};
 use diesel::{result::Error, *};
 use lemmy_db_schema::{
-  newtypes::{CommunityId, PersonId},
+  newtypes::PersonId,
   schema::{community, mod_add_community, person, person_alias_1},
   source::{
     community::{Community, CommunitySafe},
@@ -12,39 +12,49 @@ use lemmy_db_schema::{
   utils::limit_and_offset,
 };
 
-type ModAddCommunityViewTuple = (ModAddCommunity, PersonSafe, CommunitySafe, PersonSafeAlias1);
+type ModAddCommunityViewTuple = (
+  ModAddCommunity,
+  Option<PersonSafe>,
+  CommunitySafe,
+  PersonSafeAlias1,
+);
 
 impl ModAddCommunityView {
-  pub fn list(
-    conn: &PgConnection,
-    community_id: Option<CommunityId>,
-    mod_person_id: Option<PersonId>,
-    page: Option<i64>,
-    limit: Option<i64>,
-  ) -> Result<Vec<Self>, Error> {
+  pub fn list(conn: &PgConnection, params: ModlogListParams) -> Result<Vec<Self>, Error> {
+    let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
+    let show_mod_names = !params.hide_modlog_names;
+    let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
+
+    let admin_names_join = mod_add_community::mod_person_id
+      .eq(person::id)
+      .and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
     let mut query = mod_add_community::table
-      .inner_join(person::table.on(mod_add_community::mod_person_id.eq(person::id)))
+      .left_join(person::table.on(admin_names_join))
       .inner_join(community::table)
       .inner_join(
         person_alias_1::table.on(mod_add_community::other_person_id.eq(person_alias_1::id)),
       )
       .select((
         mod_add_community::all_columns,
-        Person::safe_columns_tuple(),
+        Person::safe_columns_tuple().nullable(),
         Community::safe_columns_tuple(),
         PersonAlias1::safe_columns_tuple(),
       ))
       .into_boxed();
 
-    if let Some(mod_person_id) = mod_person_id {
+    if let Some(mod_person_id) = params.mod_person_id {
       query = query.filter(mod_add_community::mod_person_id.eq(mod_person_id));
     };
 
-    if let Some(community_id) = community_id {
+    if let Some(community_id) = params.community_id {
       query = query.filter(mod_add_community::community_id.eq(community_id));
     };
 
-    let (limit, offset) = limit_and_offset(page, limit)?;
+    if let Some(other_person_id) = params.other_person_id {
+      query = query.filter(person_alias_1::id.eq(other_person_id));
+    };
+
+    let (limit, offset) = limit_and_offset(params.page, params.limit)?;
 
     let res = query
       .limit(limit)
@@ -52,7 +62,8 @@ impl ModAddCommunityView {
       .order_by(mod_add_community::when_.desc())
       .load::<ModAddCommunityViewTuple>(conn)?;
 
-    Ok(Self::from_tuple_to_vec(res))
+    let results = Self::from_tuple_to_vec(res);
+    Ok(results)
   }
 }
 
index 86c7ef19765f90f577ed8f41eb2f16a655215158..fe9afea5ee4b051928ffd0ae04250ccf3587e121 100644 (file)
@@ -1,4 +1,4 @@
-use crate::structs::ModAddView;
+use crate::structs::{ModAddView, ModlogListParams};
 use diesel::{result::Error, *};
 use lemmy_db_schema::{
   newtypes::PersonId,
@@ -11,30 +11,36 @@ use lemmy_db_schema::{
   utils::limit_and_offset,
 };
 
-type ModAddViewTuple = (ModAdd, PersonSafe, PersonSafeAlias1);
+type ModAddViewTuple = (ModAdd, Option<PersonSafe>, PersonSafeAlias1);
 
 impl ModAddView {
-  pub fn list(
-    conn: &PgConnection,
-    mod_person_id: Option<PersonId>,
-    page: Option<i64>,
-    limit: Option<i64>,
-  ) -> Result<Vec<Self>, Error> {
+  pub fn list(conn: &PgConnection, params: ModlogListParams) -> Result<Vec<Self>, Error> {
+    let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
+    let show_mod_names = !params.hide_modlog_names;
+    let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
+
+    let admin_names_join = mod_add::mod_person_id
+      .eq(person::id)
+      .and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
     let mut query = mod_add::table
-      .inner_join(person::table.on(mod_add::mod_person_id.eq(person::id)))
+      .left_join(person::table.on(admin_names_join))
       .inner_join(person_alias_1::table.on(mod_add::other_person_id.eq(person_alias_1::id)))
       .select((
         mod_add::all_columns,
-        Person::safe_columns_tuple(),
+        Person::safe_columns_tuple().nullable(),
         PersonAlias1::safe_columns_tuple(),
       ))
       .into_boxed();
 
-    if let Some(mod_person_id) = mod_person_id {
+    if let Some(mod_person_id) = params.mod_person_id {
       query = query.filter(mod_add::mod_person_id.eq(mod_person_id));
     };
 
-    let (limit, offset) = limit_and_offset(page, limit)?;
+    if let Some(other_person_id) = params.other_person_id {
+      query = query.filter(person_alias_1::id.eq(other_person_id));
+    };
+
+    let (limit, offset) = limit_and_offset(params.page, params.limit)?;
 
     let res = query
       .limit(limit)
@@ -42,7 +48,8 @@ impl ModAddView {
       .order_by(mod_add::when_.desc())
       .load::<ModAddViewTuple>(conn)?;
 
-    Ok(Self::from_tuple_to_vec(res))
+    let results = Self::from_tuple_to_vec(res);
+    Ok(results)
   }
 }
 
index 70696aace233982ec3048e6bcce157ca49ca3850..9c5cc7f7734e64ef706b73c4d3c8e3f1270f4eca 100644 (file)
@@ -1,7 +1,7 @@
-use crate::structs::ModBanFromCommunityView;
+use crate::structs::{ModBanFromCommunityView, ModlogListParams};
 use diesel::{result::Error, *};
 use lemmy_db_schema::{
-  newtypes::{CommunityId, PersonId},
+  newtypes::PersonId,
   schema::{community, mod_ban_from_community, person, person_alias_1},
   source::{
     community::{Community, CommunitySafe},
@@ -14,42 +14,47 @@ use lemmy_db_schema::{
 
 type ModBanFromCommunityViewTuple = (
   ModBanFromCommunity,
-  PersonSafe,
+  Option<PersonSafe>,
   CommunitySafe,
   PersonSafeAlias1,
 );
 
 impl ModBanFromCommunityView {
-  pub fn list(
-    conn: &PgConnection,
-    community_id: Option<CommunityId>,
-    mod_person_id: Option<PersonId>,
-    page: Option<i64>,
-    limit: Option<i64>,
-  ) -> Result<Vec<Self>, Error> {
+  pub fn list(conn: &PgConnection, params: ModlogListParams) -> Result<Vec<Self>, Error> {
+    let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
+    let show_mod_names = !params.hide_modlog_names;
+    let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
+
+    let admin_names_join = mod_ban_from_community::mod_person_id
+      .eq(person::id)
+      .and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
     let mut query = mod_ban_from_community::table
-      .inner_join(person::table.on(mod_ban_from_community::mod_person_id.eq(person::id)))
+      .left_join(person::table.on(admin_names_join))
       .inner_join(community::table)
       .inner_join(
         person_alias_1::table.on(mod_ban_from_community::other_person_id.eq(person_alias_1::id)),
       )
       .select((
         mod_ban_from_community::all_columns,
-        Person::safe_columns_tuple(),
+        Person::safe_columns_tuple().nullable(),
         Community::safe_columns_tuple(),
         PersonAlias1::safe_columns_tuple(),
       ))
       .into_boxed();
 
-    if let Some(mod_person_id) = mod_person_id {
+    if let Some(mod_person_id) = params.mod_person_id {
       query = query.filter(mod_ban_from_community::mod_person_id.eq(mod_person_id));
     };
 
-    if let Some(community_id) = community_id {
+    if let Some(community_id) = params.community_id {
       query = query.filter(mod_ban_from_community::community_id.eq(community_id));
     };
 
-    let (limit, offset) = limit_and_offset(page, limit)?;
+    if let Some(other_person_id) = params.other_person_id {
+      query = query.filter(mod_ban_from_community::other_person_id.eq(other_person_id));
+    };
+
+    let (limit, offset) = limit_and_offset(params.page, params.limit)?;
 
     let res = query
       .limit(limit)
@@ -57,7 +62,8 @@ impl ModBanFromCommunityView {
       .order_by(mod_ban_from_community::when_.desc())
       .load::<ModBanFromCommunityViewTuple>(conn)?;
 
-    Ok(Self::from_tuple_to_vec(res))
+    let results = Self::from_tuple_to_vec(res);
+    Ok(results)
   }
 }
 
index 482d4c37b6992203aebbe37ce5390f33b3696b54..43e577a31ed44ff5b205a6b71fb5d02a0f910211 100644 (file)
@@ -1,4 +1,4 @@
-use crate::structs::ModBanView;
+use crate::structs::{ModBanView, ModlogListParams};
 use diesel::{result::Error, *};
 use lemmy_db_schema::{
   newtypes::PersonId,
@@ -11,30 +11,36 @@ use lemmy_db_schema::{
   utils::limit_and_offset,
 };
 
-type ModBanViewTuple = (ModBan, PersonSafe, PersonSafeAlias1);
+type ModBanViewTuple = (ModBan, Option<PersonSafe>, PersonSafeAlias1);
 
 impl ModBanView {
-  pub fn list(
-    conn: &PgConnection,
-    mod_person_id: Option<PersonId>,
-    page: Option<i64>,
-    limit: Option<i64>,
-  ) -> Result<Vec<Self>, Error> {
+  pub fn list(conn: &PgConnection, params: ModlogListParams) -> Result<Vec<Self>, Error> {
+    let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
+    let show_mod_names = !params.hide_modlog_names;
+    let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
+
+    let admin_names_join = mod_ban::mod_person_id
+      .eq(person::id)
+      .and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
     let mut query = mod_ban::table
-      .inner_join(person::table.on(mod_ban::mod_person_id.eq(person::id)))
+      .left_join(person::table.on(admin_names_join))
       .inner_join(person_alias_1::table.on(mod_ban::other_person_id.eq(person_alias_1::id)))
       .select((
         mod_ban::all_columns,
-        Person::safe_columns_tuple(),
+        Person::safe_columns_tuple().nullable(),
         PersonAlias1::safe_columns_tuple(),
       ))
       .into_boxed();
 
-    if let Some(mod_person_id) = mod_person_id {
+    if let Some(mod_person_id) = params.mod_person_id {
       query = query.filter(mod_ban::mod_person_id.eq(mod_person_id));
     };
 
-    let (limit, offset) = limit_and_offset(page, limit)?;
+    if let Some(other_person_id) = params.other_person_id {
+      query = query.filter(person_alias_1::id.eq(other_person_id));
+    };
+
+    let (limit, offset) = limit_and_offset(params.page, params.limit)?;
 
     let res = query
       .limit(limit)
@@ -42,7 +48,8 @@ impl ModBanView {
       .order_by(mod_ban::when_.desc())
       .load::<ModBanViewTuple>(conn)?;
 
-    Ok(Self::from_tuple_to_vec(res))
+    let results = Self::from_tuple_to_vec(res);
+    Ok(results)
   }
 }
 
index 10397076cc7d3aa8ef9e261ee5ac3190ada6d3f1..24514a3df9937d5303baf75bcbea1d8734677ccd 100644 (file)
@@ -1,7 +1,7 @@
-use crate::structs::ModHideCommunityView;
+use crate::structs::{ModHideCommunityView, ModlogListParams};
 use diesel::{result::Error, *};
 use lemmy_db_schema::{
-  newtypes::{CommunityId, PersonId},
+  newtypes::PersonId,
   schema::{community, mod_hide_community, person},
   source::{
     community::{Community, CommunitySafe},
@@ -12,36 +12,37 @@ use lemmy_db_schema::{
   utils::limit_and_offset,
 };
 
-type ModHideCommunityViewTuple = (ModHideCommunity, PersonSafe, CommunitySafe);
+type ModHideCommunityViewTuple = (ModHideCommunity, Option<PersonSafe>, CommunitySafe);
 
 impl ModHideCommunityView {
   // Pass in mod_id as admin_id because only admins can do this action
-  pub fn list(
-    conn: &PgConnection,
-    community_id: Option<CommunityId>,
-    admin_id: Option<PersonId>,
-    page: Option<i64>,
-    limit: Option<i64>,
-  ) -> Result<Vec<Self>, Error> {
+  pub fn list(conn: &PgConnection, params: ModlogListParams) -> Result<Vec<Self>, Error> {
+    let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
+    let show_mod_names = !params.hide_modlog_names;
+    let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
+
+    let admin_names_join = mod_hide_community::mod_person_id
+      .eq(person::id)
+      .and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
     let mut query = mod_hide_community::table
-      .inner_join(person::table)
+      .left_join(person::table.on(admin_names_join))
       .inner_join(community::table.on(mod_hide_community::community_id.eq(community::id)))
       .select((
         mod_hide_community::all_columns,
-        Person::safe_columns_tuple(),
+        Person::safe_columns_tuple().nullable(),
         Community::safe_columns_tuple(),
       ))
       .into_boxed();
 
-    if let Some(community_id) = community_id {
+    if let Some(community_id) = params.community_id {
       query = query.filter(mod_hide_community::community_id.eq(community_id));
     };
 
-    if let Some(admin_id) = admin_id {
+    if let Some(admin_id) = params.mod_person_id {
       query = query.filter(mod_hide_community::mod_person_id.eq(admin_id));
     };
 
-    let (limit, offset) = limit_and_offset(page, limit)?;
+    let (limit, offset) = limit_and_offset(params.page, params.limit)?;
 
     let res = query
       .limit(limit)
@@ -49,7 +50,8 @@ impl ModHideCommunityView {
       .order_by(mod_hide_community::when_.desc())
       .load::<ModHideCommunityViewTuple>(conn)?;
 
-    Ok(Self::from_tuple_to_vec(res))
+    let results = Self::from_tuple_to_vec(res);
+    Ok(results)
   }
 }
 
index dba2d5889e08d5faffc69ff458bb2611f4417ca1..dad5c5b59ab5c66f3d942b1ca2778c75f1998132 100644 (file)
@@ -1,8 +1,8 @@
-use crate::structs::ModLockPostView;
+use crate::structs::{ModLockPostView, ModlogListParams};
 use diesel::{result::Error, *};
 use lemmy_db_schema::{
-  newtypes::{CommunityId, PersonId},
-  schema::{community, mod_lock_post, person, post},
+  newtypes::PersonId,
+  schema::{community, mod_lock_post, person, person_alias_1, post},
   source::{
     community::{Community, CommunitySafe},
     moderator::ModLockPost,
@@ -13,37 +13,43 @@ use lemmy_db_schema::{
   utils::limit_and_offset,
 };
 
-type ModLockPostViewTuple = (ModLockPost, PersonSafe, Post, CommunitySafe);
+type ModLockPostViewTuple = (ModLockPost, Option<PersonSafe>, Post, CommunitySafe);
 
 impl ModLockPostView {
-  pub fn list(
-    conn: &PgConnection,
-    community_id: Option<CommunityId>,
-    mod_person_id: Option<PersonId>,
-    page: Option<i64>,
-    limit: Option<i64>,
-  ) -> Result<Vec<Self>, Error> {
+  pub fn list(conn: &PgConnection, params: ModlogListParams) -> Result<Vec<Self>, Error> {
+    let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
+    let show_mod_names = !params.hide_modlog_names;
+    let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
+
+    let admin_names_join = mod_lock_post::mod_person_id
+      .eq(person::id)
+      .and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
     let mut query = mod_lock_post::table
-      .inner_join(person::table)
+      .left_join(person::table.on(admin_names_join))
       .inner_join(post::table)
       .inner_join(community::table.on(post::community_id.eq(community::id)))
+      .inner_join(person_alias_1::table.on(post::creator_id.eq(person_alias_1::id)))
       .select((
         mod_lock_post::all_columns,
-        Person::safe_columns_tuple(),
+        Person::safe_columns_tuple().nullable(),
         post::all_columns,
         Community::safe_columns_tuple(),
       ))
       .into_boxed();
 
-    if let Some(community_id) = community_id {
+    if let Some(community_id) = params.community_id {
       query = query.filter(post::community_id.eq(community_id));
     };
 
-    if let Some(mod_person_id) = mod_person_id {
+    if let Some(mod_person_id) = params.mod_person_id {
       query = query.filter(mod_lock_post::mod_person_id.eq(mod_person_id));
     };
 
-    let (limit, offset) = limit_and_offset(page, limit)?;
+    if let Some(other_person_id) = params.other_person_id {
+      query = query.filter(person_alias_1::id.eq(other_person_id));
+    };
+
+    let (limit, offset) = limit_and_offset(params.page, params.limit)?;
 
     let res = query
       .limit(limit)
@@ -51,7 +57,8 @@ impl ModLockPostView {
       .order_by(mod_lock_post::when_.desc())
       .load::<ModLockPostViewTuple>(conn)?;
 
-    Ok(Self::from_tuple_to_vec(res))
+    let results = Self::from_tuple_to_vec(res);
+    Ok(results)
   }
 }
 
index 29d3a19c13407d19f361513e06d76c10b55b51cc..2ee230d112afe7a959f0ad4f64a574a015ffba23 100644 (file)
@@ -1,7 +1,7 @@
-use crate::structs::ModRemoveCommentView;
+use crate::structs::{ModRemoveCommentView, ModlogListParams};
 use diesel::{result::Error, *};
 use lemmy_db_schema::{
-  newtypes::{CommunityId, PersonId},
+  newtypes::PersonId,
   schema::{comment, community, mod_remove_comment, person, person_alias_1, post},
   source::{
     comment::Comment,
@@ -16,7 +16,7 @@ use lemmy_db_schema::{
 
 type ModRemoveCommentViewTuple = (
   ModRemoveComment,
-  PersonSafe,
+  Option<PersonSafe>,
   Comment,
   PersonSafeAlias1,
   Post,
@@ -24,22 +24,23 @@ type ModRemoveCommentViewTuple = (
 );
 
 impl ModRemoveCommentView {
-  pub fn list(
-    conn: &PgConnection,
-    community_id: Option<CommunityId>,
-    mod_person_id: Option<PersonId>,
-    page: Option<i64>,
-    limit: Option<i64>,
-  ) -> Result<Vec<Self>, Error> {
+  pub fn list(conn: &PgConnection, params: ModlogListParams) -> Result<Vec<Self>, Error> {
+    let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
+    let show_mod_names = !params.hide_modlog_names;
+    let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
+
+    let admin_names_join = mod_remove_comment::mod_person_id
+      .eq(person::id)
+      .and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
     let mut query = mod_remove_comment::table
-      .inner_join(person::table)
+      .left_join(person::table.on(admin_names_join))
       .inner_join(comment::table)
       .inner_join(person_alias_1::table.on(comment::creator_id.eq(person_alias_1::id)))
       .inner_join(post::table.on(comment::post_id.eq(post::id)))
       .inner_join(community::table.on(post::community_id.eq(community::id)))
       .select((
         mod_remove_comment::all_columns,
-        Person::safe_columns_tuple(),
+        Person::safe_columns_tuple().nullable(),
         comment::all_columns,
         PersonAlias1::safe_columns_tuple(),
         post::all_columns,
@@ -47,15 +48,19 @@ impl ModRemoveCommentView {
       ))
       .into_boxed();
 
-    if let Some(community_id) = community_id {
+    if let Some(community_id) = params.community_id {
       query = query.filter(post::community_id.eq(community_id));
     };
 
-    if let Some(mod_person_id) = mod_person_id {
+    if let Some(mod_person_id) = params.mod_person_id {
       query = query.filter(mod_remove_comment::mod_person_id.eq(mod_person_id));
     };
 
-    let (limit, offset) = limit_and_offset(page, limit)?;
+    if let Some(other_person_id) = params.other_person_id {
+      query = query.filter(person_alias_1::id.eq(other_person_id));
+    };
+
+    let (limit, offset) = limit_and_offset(params.page, params.limit)?;
 
     let res = query
       .limit(limit)
@@ -63,7 +68,8 @@ impl ModRemoveCommentView {
       .order_by(mod_remove_comment::when_.desc())
       .load::<ModRemoveCommentViewTuple>(conn)?;
 
-    Ok(Self::from_tuple_to_vec(res))
+    let results = Self::from_tuple_to_vec(res);
+    Ok(results)
   }
 }
 
index b49fa1d5d079690064ab3e24a4913fb3c6e25838..ec462df9fa311ab68b6a82915b85e1eedd7d7874 100644 (file)
@@ -1,4 +1,4 @@
-use crate::structs::ModRemoveCommunityView;
+use crate::structs::{ModRemoveCommunityView, ModlogListParams};
 use diesel::{result::Error, *};
 use lemmy_db_schema::{
   newtypes::PersonId,
@@ -12,30 +12,32 @@ use lemmy_db_schema::{
   utils::limit_and_offset,
 };
 
-type ModRemoveCommunityTuple = (ModRemoveCommunity, PersonSafe, CommunitySafe);
+type ModRemoveCommunityTuple = (ModRemoveCommunity, Option<PersonSafe>, CommunitySafe);
 
 impl ModRemoveCommunityView {
-  pub fn list(
-    conn: &PgConnection,
-    mod_person_id: Option<PersonId>,
-    page: Option<i64>,
-    limit: Option<i64>,
-  ) -> Result<Vec<Self>, Error> {
+  pub fn list(conn: &PgConnection, params: ModlogListParams) -> Result<Vec<Self>, Error> {
+    let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
+    let show_mod_names = !params.hide_modlog_names;
+    let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
+
+    let admin_names_join = mod_remove_community::mod_person_id
+      .eq(person::id)
+      .and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
     let mut query = mod_remove_community::table
-      .inner_join(person::table)
+      .left_join(person::table.on(admin_names_join))
       .inner_join(community::table)
       .select((
         mod_remove_community::all_columns,
-        Person::safe_columns_tuple(),
+        Person::safe_columns_tuple().nullable(),
         Community::safe_columns_tuple(),
       ))
       .into_boxed();
 
-    if let Some(mod_person_id) = mod_person_id {
+    if let Some(mod_person_id) = params.mod_person_id {
       query = query.filter(mod_remove_community::mod_person_id.eq(mod_person_id));
     };
 
-    let (limit, offset) = limit_and_offset(page, limit)?;
+    let (limit, offset) = limit_and_offset(params.page, params.limit)?;
 
     let res = query
       .limit(limit)
@@ -43,7 +45,8 @@ impl ModRemoveCommunityView {
       .order_by(mod_remove_community::when_.desc())
       .load::<ModRemoveCommunityTuple>(conn)?;
 
-    Ok(Self::from_tuple_to_vec(res))
+    let results = Self::from_tuple_to_vec(res);
+    Ok(results)
   }
 }
 
index e46f5ea19c4b25d4e4a7f8d39050ff4fa4c9203b..497305ecedfee1f192a31619983d50b36d0c5de3 100644 (file)
@@ -1,8 +1,8 @@
-use crate::structs::ModRemovePostView;
+use crate::structs::{ModRemovePostView, ModlogListParams};
 use diesel::{result::Error, *};
 use lemmy_db_schema::{
-  newtypes::{CommunityId, PersonId},
-  schema::{community, mod_remove_post, person, post},
+  newtypes::PersonId,
+  schema::{community, mod_remove_post, person, person_alias_1, post},
   source::{
     community::{Community, CommunitySafe},
     moderator::ModRemovePost,
@@ -13,37 +13,43 @@ use lemmy_db_schema::{
   utils::limit_and_offset,
 };
 
-type ModRemovePostViewTuple = (ModRemovePost, PersonSafe, Post, CommunitySafe);
+type ModRemovePostViewTuple = (ModRemovePost, Option<PersonSafe>, Post, CommunitySafe);
 
 impl ModRemovePostView {
-  pub fn list(
-    conn: &PgConnection,
-    community_id: Option<CommunityId>,
-    mod_person_id: Option<PersonId>,
-    page: Option<i64>,
-    limit: Option<i64>,
-  ) -> Result<Vec<Self>, Error> {
+  pub fn list(conn: &PgConnection, params: ModlogListParams) -> Result<Vec<Self>, Error> {
+    let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
+    let show_mod_names = !params.hide_modlog_names;
+    let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
+
+    let admin_names_join = mod_remove_post::mod_person_id
+      .eq(person::id)
+      .and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
     let mut query = mod_remove_post::table
-      .inner_join(person::table)
+      .left_join(person::table.on(admin_names_join))
       .inner_join(post::table)
       .inner_join(community::table.on(post::community_id.eq(community::id)))
+      .inner_join(person_alias_1::table.on(post::creator_id.eq(person_alias_1::id)))
       .select((
         mod_remove_post::all_columns,
-        Person::safe_columns_tuple(),
+        Person::safe_columns_tuple().nullable(),
         post::all_columns,
         Community::safe_columns_tuple(),
       ))
       .into_boxed();
 
-    if let Some(community_id) = community_id {
+    if let Some(community_id) = params.community_id {
       query = query.filter(post::community_id.eq(community_id));
     };
 
-    if let Some(mod_person_id) = mod_person_id {
+    if let Some(mod_person_id) = params.mod_person_id {
       query = query.filter(mod_remove_post::mod_person_id.eq(mod_person_id));
     };
 
-    let (limit, offset) = limit_and_offset(page, limit)?;
+    if let Some(other_person_id) = params.other_person_id {
+      query = query.filter(person_alias_1::id.eq(other_person_id));
+    };
+
+    let (limit, offset) = limit_and_offset(params.page, params.limit)?;
 
     let res = query
       .limit(limit)
@@ -51,7 +57,8 @@ impl ModRemovePostView {
       .order_by(mod_remove_post::when_.desc())
       .load::<ModRemovePostViewTuple>(conn)?;
 
-    Ok(Self::from_tuple_to_vec(res))
+    let results = Self::from_tuple_to_vec(res);
+    Ok(results)
   }
 }
 
index 5e0d205695e65bf062745613b3a2c9aad421833f..a47e1dc899af88e52b55ee89cf5d7bed5e9d0ef2 100644 (file)
@@ -1,8 +1,8 @@
-use crate::structs::ModStickyPostView;
+use crate::structs::{ModStickyPostView, ModlogListParams};
 use diesel::{result::Error, *};
 use lemmy_db_schema::{
-  newtypes::{CommunityId, PersonId},
-  schema::{community, mod_sticky_post, person, post},
+  newtypes::PersonId,
+  schema::{community, mod_sticky_post, person, person_alias_1, post},
   source::{
     community::{Community, CommunitySafe},
     moderator::ModStickyPost,
@@ -13,37 +13,43 @@ use lemmy_db_schema::{
   utils::limit_and_offset,
 };
 
-type ModStickyPostViewTuple = (ModStickyPost, PersonSafe, Post, CommunitySafe);
+type ModStickyPostViewTuple = (ModStickyPost, Option<PersonSafe>, Post, CommunitySafe);
 
 impl ModStickyPostView {
-  pub fn list(
-    conn: &PgConnection,
-    community_id: Option<CommunityId>,
-    mod_person_id: Option<PersonId>,
-    page: Option<i64>,
-    limit: Option<i64>,
-  ) -> Result<Vec<Self>, Error> {
+  pub fn list(conn: &PgConnection, params: ModlogListParams) -> Result<Vec<Self>, Error> {
+    let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
+    let show_mod_names = !params.hide_modlog_names;
+    let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
+
+    let admin_names_join = mod_sticky_post::mod_person_id
+      .eq(person::id)
+      .and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
     let mut query = mod_sticky_post::table
-      .inner_join(person::table)
+      .left_join(person::table.on(admin_names_join))
       .inner_join(post::table)
+      .inner_join(person_alias_1::table.on(post::creator_id.eq(person_alias_1::id)))
       .inner_join(community::table.on(post::community_id.eq(community::id)))
       .select((
         mod_sticky_post::all_columns,
-        Person::safe_columns_tuple(),
+        Person::safe_columns_tuple().nullable(),
         post::all_columns,
         Community::safe_columns_tuple(),
       ))
       .into_boxed();
 
-    if let Some(community_id) = community_id {
+    if let Some(community_id) = params.community_id {
       query = query.filter(post::community_id.eq(community_id));
     };
 
-    if let Some(mod_person_id) = mod_person_id {
+    if let Some(mod_person_id) = params.mod_person_id {
       query = query.filter(mod_sticky_post::mod_person_id.eq(mod_person_id));
     };
 
-    let (limit, offset) = limit_and_offset(page, limit)?;
+    if let Some(other_person_id) = params.other_person_id {
+      query = query.filter(person_alias_1::id.eq(other_person_id));
+    };
+
+    let (limit, offset) = limit_and_offset(params.page, params.limit)?;
 
     let res = query
       .limit(limit)
@@ -51,7 +57,8 @@ impl ModStickyPostView {
       .order_by(mod_sticky_post::when_.desc())
       .load::<ModStickyPostViewTuple>(conn)?;
 
-    Ok(Self::from_tuple_to_vec(res))
+    let results = Self::from_tuple_to_vec(res);
+    Ok(results)
   }
 }
 
index bc8ccd97dedc1634cc8758454180a0c7c3abcb73..bada7b39f5be9119ffb53cecf6c730d2b92936cb 100644 (file)
@@ -1,7 +1,7 @@
-use crate::structs::ModTransferCommunityView;
+use crate::structs::{ModTransferCommunityView, ModlogListParams};
 use diesel::{result::Error, *};
 use lemmy_db_schema::{
-  newtypes::{CommunityId, PersonId},
+  newtypes::PersonId,
   schema::{community, mod_transfer_community, person, person_alias_1},
   source::{
     community::{Community, CommunitySafe},
@@ -14,42 +14,47 @@ use lemmy_db_schema::{
 
 type ModTransferCommunityViewTuple = (
   ModTransferCommunity,
-  PersonSafe,
+  Option<PersonSafe>,
   CommunitySafe,
   PersonSafeAlias1,
 );
 
 impl ModTransferCommunityView {
-  pub fn list(
-    conn: &PgConnection,
-    community_id: Option<CommunityId>,
-    mod_person_id: Option<PersonId>,
-    page: Option<i64>,
-    limit: Option<i64>,
-  ) -> Result<Vec<Self>, Error> {
+  pub fn list(conn: &PgConnection, params: ModlogListParams) -> Result<Vec<Self>, Error> {
+    let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
+    let show_mod_names = !params.hide_modlog_names;
+    let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
+
+    let admin_names_join = mod_transfer_community::mod_person_id
+      .eq(person::id)
+      .and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
     let mut query = mod_transfer_community::table
-      .inner_join(person::table.on(mod_transfer_community::mod_person_id.eq(person::id)))
+      .left_join(person::table.on(admin_names_join))
       .inner_join(community::table)
       .inner_join(
         person_alias_1::table.on(mod_transfer_community::other_person_id.eq(person_alias_1::id)),
       )
       .select((
         mod_transfer_community::all_columns,
-        Person::safe_columns_tuple(),
+        Person::safe_columns_tuple().nullable(),
         Community::safe_columns_tuple(),
         PersonAlias1::safe_columns_tuple(),
       ))
       .into_boxed();
 
-    if let Some(mod_person_id) = mod_person_id {
+    if let Some(mod_person_id) = params.mod_person_id {
       query = query.filter(mod_transfer_community::mod_person_id.eq(mod_person_id));
     };
 
-    if let Some(community_id) = community_id {
+    if let Some(community_id) = params.community_id {
       query = query.filter(mod_transfer_community::community_id.eq(community_id));
     };
 
-    let (limit, offset) = limit_and_offset(page, limit)?;
+    if let Some(other_person_id) = params.other_person_id {
+      query = query.filter(person_alias_1::id.eq(other_person_id));
+    };
+
+    let (limit, offset) = limit_and_offset(params.page, params.limit)?;
 
     let res = query
       .limit(limit)
@@ -57,7 +62,8 @@ impl ModTransferCommunityView {
       .order_by(mod_transfer_community::when_.desc())
       .load::<ModTransferCommunityViewTuple>(conn)?;
 
-    Ok(Self::from_tuple_to_vec(res))
+    let results = Self::from_tuple_to_vec(res);
+    Ok(results)
   }
 }
 
index ebe93399c0063aba7cdb9c61d79ab15ba220a931..4f6fbbd3ea0125c8d0c86f2ba95b574372e3236d 100644 (file)
@@ -1,32 +1,35 @@
-use lemmy_db_schema::source::{
-  comment::Comment,
-  community::CommunitySafe,
-  moderator::{
-    AdminPurgeComment,
-    AdminPurgeCommunity,
-    AdminPurgePerson,
-    AdminPurgePost,
-    ModAdd,
-    ModAddCommunity,
-    ModBan,
-    ModBanFromCommunity,
-    ModHideCommunity,
-    ModLockPost,
-    ModRemoveComment,
-    ModRemoveCommunity,
-    ModRemovePost,
-    ModStickyPost,
-    ModTransferCommunity,
+use lemmy_db_schema::{
+  newtypes::{CommunityId, PersonId},
+  source::{
+    comment::Comment,
+    community::CommunitySafe,
+    moderator::{
+      AdminPurgeComment,
+      AdminPurgeCommunity,
+      AdminPurgePerson,
+      AdminPurgePost,
+      ModAdd,
+      ModAddCommunity,
+      ModBan,
+      ModBanFromCommunity,
+      ModHideCommunity,
+      ModLockPost,
+      ModRemoveComment,
+      ModRemoveCommunity,
+      ModRemovePost,
+      ModStickyPost,
+      ModTransferCommunity,
+    },
+    person::{PersonSafe, PersonSafeAlias1},
+    post::Post,
   },
-  person::{PersonSafe, PersonSafeAlias1},
-  post::Post,
 };
 use serde::{Deserialize, Serialize};
 
 #[derive(Debug, Serialize, Deserialize, Clone)]
 pub struct ModAddCommunityView {
   pub mod_add_community: ModAddCommunity,
-  pub moderator: PersonSafe,
+  pub moderator: Option<PersonSafe>,
   pub community: CommunitySafe,
   pub modded_person: PersonSafeAlias1,
 }
@@ -34,14 +37,14 @@ pub struct ModAddCommunityView {
 #[derive(Debug, Serialize, Deserialize, Clone)]
 pub struct ModAddView {
   pub mod_add: ModAdd,
-  pub moderator: PersonSafe,
+  pub moderator: Option<PersonSafe>,
   pub modded_person: PersonSafeAlias1,
 }
 
 #[derive(Debug, Serialize, Deserialize, Clone)]
 pub struct ModBanFromCommunityView {
   pub mod_ban_from_community: ModBanFromCommunity,
-  pub moderator: PersonSafe,
+  pub moderator: Option<PersonSafe>,
   pub community: CommunitySafe,
   pub banned_person: PersonSafeAlias1,
 }
@@ -49,21 +52,21 @@ pub struct ModBanFromCommunityView {
 #[derive(Debug, Serialize, Deserialize, Clone)]
 pub struct ModBanView {
   pub mod_ban: ModBan,
-  pub moderator: PersonSafe,
+  pub moderator: Option<PersonSafe>,
   pub banned_person: PersonSafeAlias1,
 }
 
 #[derive(Debug, Serialize, Deserialize, Clone)]
 pub struct ModHideCommunityView {
   pub mod_hide_community: ModHideCommunity,
-  pub admin: PersonSafe,
+  pub admin: Option<PersonSafe>,
   pub community: CommunitySafe,
 }
 
 #[derive(Debug, Serialize, Deserialize, Clone)]
 pub struct ModLockPostView {
   pub mod_lock_post: ModLockPost,
-  pub moderator: PersonSafe,
+  pub moderator: Option<PersonSafe>,
   pub post: Post,
   pub community: CommunitySafe,
 }
@@ -71,7 +74,7 @@ pub struct ModLockPostView {
 #[derive(Debug, Serialize, Deserialize, Clone)]
 pub struct ModRemoveCommentView {
   pub mod_remove_comment: ModRemoveComment,
-  pub moderator: PersonSafe,
+  pub moderator: Option<PersonSafe>,
   pub comment: Comment,
   pub commenter: PersonSafeAlias1,
   pub post: Post,
@@ -81,14 +84,14 @@ pub struct ModRemoveCommentView {
 #[derive(Debug, Serialize, Deserialize, Clone)]
 pub struct ModRemoveCommunityView {
   pub mod_remove_community: ModRemoveCommunity,
-  pub moderator: PersonSafe,
+  pub moderator: Option<PersonSafe>,
   pub community: CommunitySafe,
 }
 
 #[derive(Debug, Serialize, Deserialize, Clone)]
 pub struct ModRemovePostView {
   pub mod_remove_post: ModRemovePost,
-  pub moderator: PersonSafe,
+  pub moderator: Option<PersonSafe>,
   pub post: Post,
   pub community: CommunitySafe,
 }
@@ -96,7 +99,7 @@ pub struct ModRemovePostView {
 #[derive(Debug, Serialize, Deserialize, Clone)]
 pub struct ModStickyPostView {
   pub mod_sticky_post: ModStickyPost,
-  pub moderator: PersonSafe,
+  pub moderator: Option<PersonSafe>,
   pub post: Post,
   pub community: CommunitySafe,
 }
@@ -104,7 +107,7 @@ pub struct ModStickyPostView {
 #[derive(Debug, Serialize, Deserialize, Clone)]
 pub struct ModTransferCommunityView {
   pub mod_transfer_community: ModTransferCommunity,
-  pub moderator: PersonSafe,
+  pub moderator: Option<PersonSafe>,
   pub community: CommunitySafe,
   pub modded_person: PersonSafeAlias1,
 }
@@ -112,25 +115,35 @@ pub struct ModTransferCommunityView {
 #[derive(Debug, Serialize, Deserialize, Clone)]
 pub struct AdminPurgeCommentView {
   pub admin_purge_comment: AdminPurgeComment,
-  pub admin: PersonSafe,
+  pub admin: Option<PersonSafe>,
   pub post: Post,
 }
 
 #[derive(Debug, Serialize, Deserialize, Clone)]
 pub struct AdminPurgeCommunityView {
   pub admin_purge_community: AdminPurgeCommunity,
-  pub admin: PersonSafe,
+  pub admin: Option<PersonSafe>,
 }
 
 #[derive(Debug, Serialize, Deserialize, Clone)]
 pub struct AdminPurgePersonView {
   pub admin_purge_person: AdminPurgePerson,
-  pub admin: PersonSafe,
+  pub admin: Option<PersonSafe>,
 }
 
 #[derive(Debug, Serialize, Deserialize, Clone)]
 pub struct AdminPurgePostView {
   pub admin_purge_post: AdminPurgePost,
-  pub admin: PersonSafe,
+  pub admin: Option<PersonSafe>,
   pub community: CommunitySafe,
 }
+
+#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
+pub struct ModlogListParams {
+  pub community_id: Option<CommunityId>,
+  pub mod_person_id: Option<PersonId>,
+  pub other_person_id: Option<PersonId>,
+  pub page: Option<i64>,
+  pub limit: Option<i64>,
+  pub hide_modlog_names: bool,
+}
diff --git a/migrations/2022-06-12-012121_add_site_hide_modlog_names/down.sql b/migrations/2022-06-12-012121_add_site_hide_modlog_names/down.sql
new file mode 100644 (file)
index 0000000..c3f6581
--- /dev/null
@@ -0,0 +1 @@
+alter table site drop column hide_modlog_mod_names;
\ No newline at end of file
diff --git a/migrations/2022-06-12-012121_add_site_hide_modlog_names/up.sql b/migrations/2022-06-12-012121_add_site_hide_modlog_names/up.sql
new file mode 100644 (file)
index 0000000..329ad6f
--- /dev/null
@@ -0,0 +1 @@
+alter table site add column hide_modlog_mod_names boolean default true NOT NULL;
\ No newline at end of file
index 81a108b89f78ff24a4b2ed922321a8a8971e4d2d..07be683e9c574b71e40b53d16c53485d1b12c8f6 100644 (file)
@@ -70,6 +70,7 @@ async fn main() -> Result<(), LemmyError> {
   let manager = ConnectionManager::<PgConnection>::new(&db_url);
   let pool = Pool::builder()
     .max_size(settings.database.pool_size)
+    .min_idle(Some(1))
     .build(manager)
     .unwrap_or_else(|_| panic!("Error connecting to {}", db_url));