Removing hide_modlog_mod_names setting. (#5681)

* Simplify modlog name removals.

- #5614

* Removing hide_modlog_mod_names setting.

* Addressing PR comments 2
This commit is contained in:
Dessalines 2025-05-21 03:49:22 -04:00 committed by GitHub
parent 546372b163
commit 5095092d3a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 262 additions and 59 deletions

View file

@ -2,7 +2,7 @@ use actix_web::web::{Data, Json, Query};
use lemmy_api_common::{
context::LemmyContext,
site::GetModlog,
utils::{check_community_mod_of_any_or_admin_action, check_private_instance},
utils::{check_private_instance, is_mod_or_admin_opt},
};
use lemmy_db_schema::traits::PaginationCursorBuilder;
use lemmy_db_views_local_user::LocalUserView;
@ -23,15 +23,26 @@ pub async fn get_mod_log(
check_private_instance(&local_user_view, &local_site)?;
let is_mod_or_admin = if let Some(local_user_view) = &local_user_view {
check_community_mod_of_any_or_admin_action(local_user_view, &mut context.pool())
// Only show the modlog names if:
// You're an admin or
// You're fetching the modlog for a single community, and you're a mod
// (Alternatively !admin/mod)
let hide_modlog_names = if let Some(community_id) = data.community_id {
is_mod_or_admin_opt(
&mut context.pool(),
local_user_view.as_ref(),
Some(community_id),
)
.await
.is_ok()
.is_err()
} else {
false
!local_user_view
.as_ref()
.map(|l| l.local_user.admin)
.unwrap_or_default()
};
let hide_modlog_names = local_site.hide_modlog_mod_names && !is_mod_or_admin;
// Only allow mod person id filters if its not hidden
let mod_person_id = if hide_modlog_names {
None
} else {

View file

@ -145,8 +145,6 @@ pub struct CreateSite {
#[cfg_attr(feature = "full", ts(optional))]
pub application_email_admins: Option<bool>,
#[cfg_attr(feature = "full", ts(optional))]
pub hide_modlog_mod_names: Option<bool>,
#[cfg_attr(feature = "full", ts(optional))]
pub discussion_languages: Option<Vec<LanguageId>>,
#[cfg_attr(feature = "full", ts(optional))]
pub slur_filter_regex: Option<String>,
@ -252,9 +250,6 @@ pub struct EditSite {
/// Whether to email admins when receiving a new application.
#[cfg_attr(feature = "full", ts(optional))]
pub application_email_admins: Option<bool>,
/// Whether to hide moderator names from the modlog.
#[cfg_attr(feature = "full", ts(optional))]
pub hide_modlog_mod_names: Option<bool>,
/// A list of allowed discussion languages.
#[cfg_attr(feature = "full", ts(optional))]
pub discussion_languages: Option<Vec<LanguageId>>,

View file

@ -123,6 +123,7 @@ pub async fn is_mod_or_admin_opt(
community_id: Option<CommunityId>,
) -> LemmyResult<()> {
if let Some(local_user_view) = local_user_view {
check_local_user_valid(local_user_view)?;
if let Some(community_id) = community_id {
is_mod_or_admin(pool, local_user_view, community_id).await
} else {
@ -282,7 +283,7 @@ pub fn check_community_deleted_removed(community: &Community) -> LemmyResult<()>
/// Check that the given user can perform a mod action in the community.
///
/// In particular it checks that he is an admin or mod, wasn't banned and the community isn't
/// In particular it checks that they're an admin or mod, wasn't banned and the community isn't
/// removed/deleted.
pub async fn check_community_mod_action(
local_user_view: &LocalUserView,

View file

@ -92,7 +92,6 @@ pub async fn create_site(
default_comment_sort_type: data.default_comment_sort_type,
legal_information: diesel_string_update(data.legal_information.as_deref()),
application_email_admins: data.application_email_admins,
hide_modlog_mod_names: data.hide_modlog_mod_names,
updated: Some(Some(Utc::now())),
slur_filter_regex: diesel_string_update(data.slur_filter_regex.as_deref()),
actor_name_max_length: data.actor_name_max_length,

View file

@ -99,7 +99,6 @@ pub async fn update_site(
default_comment_sort_type: data.default_comment_sort_type,
legal_information: diesel_string_update(data.legal_information.as_deref()),
application_email_admins: data.application_email_admins,
hide_modlog_mod_names: data.hide_modlog_mod_names,
updated: Some(Some(Utc::now())),
slur_filter_regex: diesel_string_update(data.slur_filter_regex.as_deref()),
actor_name_max_length: data.actor_name_max_length,

View file

@ -43,8 +43,6 @@ pub struct LocalSite {
/// An optional legal disclaimer page.
#[cfg_attr(feature = "full", ts(optional))]
pub legal_information: Option<String>,
/// Whether to hide mod names on the modlog.
pub hide_modlog_mod_names: bool,
/// Whether new applications email admins.
pub application_email_admins: bool,
/// An optional regex to filter words.
@ -126,8 +124,6 @@ pub struct LocalSiteInsertForm {
#[new(default)]
pub legal_information: Option<String>,
#[new(default)]
pub hide_modlog_mod_names: Option<bool>,
#[new(default)]
pub application_email_admins: Option<bool>,
#[new(default)]
pub slur_filter_regex: Option<String>,
@ -181,7 +177,6 @@ pub struct LocalSiteUpdateForm {
pub default_theme: Option<String>,
pub default_post_listing_type: Option<ListingType>,
pub legal_information: Option<Option<String>>,
pub hide_modlog_mod_names: Option<bool>,
pub application_email_admins: Option<bool>,
pub slur_filter_regex: Option<Option<String>>,
pub actor_name_max_length: Option<i32>,

View file

@ -420,7 +420,6 @@ diesel::table! {
default_theme -> Text,
default_post_listing_type -> ListingTypeEnum,
legal_information -> Nullable<Text>,
hide_modlog_mod_names -> Bool,
application_email_admins -> Bool,
slur_filter_regex -> Nullable<Text>,
actor_name_max_length -> Int4,

View file

@ -22,7 +22,6 @@ use crate::{
use diesel::{
BoolExpressionMethods,
ExpressionMethods,
IntoSql,
JoinOnDsl,
NullableExpressionMethods,
QueryDsl,
@ -81,24 +80,14 @@ use lemmy_utils::error::{LemmyErrorType, LemmyResult};
impl ModlogCombinedViewInternal {
#[diesel::dsl::auto_type(no_type_alias)]
fn joins(
mod_person_id: Option<PersonId>,
hide_modlog_names: Option<bool>,
my_person_id: Option<PersonId>,
) -> _ {
fn joins(my_person_id: Option<PersonId>) -> _ {
// The modded / other person
let other_person = aliases::person1.field(person::id);
let show_mod_names: bool = !(hide_modlog_names.unwrap_or_default());
let show_mod_names_expr = show_mod_names.into_sql::<diesel::sql_types::Bool>();
// The query for the admin / mod person
// It needs an OR condition to every mod table
// After this you can use person::id to refer to the moderator
let moderator_names_join = person::table.on(
show_mod_names_expr
.or(person::id.nullable().eq(mod_person_id))
.and(
let moderator_join = person::table.on(
admin_allow_instance::admin_person_id
.eq(person::id)
.or(admin_block_instance::admin_person_id.eq(person::id))
@ -117,7 +106,6 @@ impl ModlogCombinedViewInternal {
.or(mod_remove_community::mod_person_id.eq(person::id))
.or(mod_remove_post::mod_person_id.eq(person::id))
.or(mod_transfer_community::mod_person_id.eq(person::id)),
),
);
let other_person_join = aliases::person1.on(
@ -225,7 +213,7 @@ impl ModlogCombinedViewInternal {
.left_join(mod_remove_community::table)
.left_join(mod_remove_post::table)
.left_join(mod_transfer_community::table)
.left_join(moderator_names_join)
.left_join(moderator_join)
.left_join(comment_join)
.left_join(post_join)
.left_join(community_join)
@ -328,8 +316,7 @@ impl ModlogCombinedQuery<'_> {
let other_person = aliases::person1.field(person::id);
let my_person_id = self.local_user.person_id();
let mut query =
ModlogCombinedViewInternal::joins(self.mod_person_id, self.hide_modlog_names, my_person_id)
let mut query = ModlogCombinedViewInternal::joins(my_person_id)
.select(ModlogCombinedViewInternal::as_select())
.limit(limit)
.into_boxed();
@ -411,9 +398,12 @@ impl ModlogCombinedQuery<'_> {
.load::<ModlogCombinedViewInternal>(conn)
.await?;
let hide_modlog_names = self.hide_modlog_names.unwrap_or_default();
// Map the query results to the enum
let out = res
.into_iter()
.map(|u| u.hide_mod_name(hide_modlog_names))
.filter_map(InternalToCombinedView::map_to_enum)
.collect();
@ -421,6 +411,20 @@ impl ModlogCombinedQuery<'_> {
}
}
impl ModlogCombinedViewInternal {
/// Hides modlog names by setting the moderator to None.
fn hide_mod_name(self, hide_modlog_names: bool) -> Self {
if hide_modlog_names {
Self {
moderator: None,
..self
}
} else {
self
}
}
}
impl InternalToCombinedView for ModlogCombinedViewInternal {
type CombinedView = ModlogCombinedView;

View file

@ -0,0 +1,197 @@
-- You need to remake all the columns after the changed one.
--
-- 1. Create old column, and add _new to every one after
-- 2. Update the _new to the old
-- 3. Drop the old
-- 4. Rename the new
ALTER TABLE local_site
ADD COLUMN hide_modlog_mod_names boolean DEFAULT TRUE NOT NULL,
ADD COLUMN application_email_admins_new boolean DEFAULT FALSE NOT NULL,
ADD COLUMN slur_filter_regex_new text,
ADD COLUMN actor_name_max_length_new integer DEFAULT 20 NOT NULL,
ADD COLUMN federation_enabled_new boolean DEFAULT TRUE NOT NULL,
ADD COLUMN captcha_enabled_new boolean DEFAULT FALSE NOT NULL,
ADD COLUMN captcha_difficulty_new character varying(255) DEFAULT 'medium'::character varying NOT NULL,
ADD COLUMN published_new timestamp with time zone DEFAULT now() NOT NULL,
ADD COLUMN updated_new timestamp with time zone,
ADD COLUMN registration_mode_new public.registration_mode_enum DEFAULT 'RequireApplication'::public.registration_mode_enum NOT NULL,
ADD COLUMN reports_email_admins_new boolean DEFAULT FALSE NOT NULL,
ADD COLUMN federation_signed_fetch_new boolean DEFAULT TRUE NOT NULL,
ADD COLUMN default_post_listing_mode_new public.post_listing_mode_enum DEFAULT 'List'::public.post_listing_mode_enum NOT NULL,
ADD COLUMN default_post_sort_type_new public.post_sort_type_enum DEFAULT 'Active'::public.post_sort_type_enum NOT NULL,
ADD COLUMN default_comment_sort_type_new public.comment_sort_type_enum DEFAULT 'Hot'::public.comment_sort_type_enum NOT NULL,
ADD COLUMN oauth_registration_new boolean DEFAULT FALSE NOT NULL,
ADD COLUMN post_upvotes_new public.federation_mode_enum DEFAULT 'All'::public.federation_mode_enum NOT NULL,
ADD COLUMN post_downvotes_new public.federation_mode_enum DEFAULT 'All'::public.federation_mode_enum NOT NULL,
ADD COLUMN comment_upvotes_new public.federation_mode_enum DEFAULT 'All'::public.federation_mode_enum NOT NULL,
ADD COLUMN comment_downvotes_new public.federation_mode_enum DEFAULT 'All'::public.federation_mode_enum NOT NULL,
ADD COLUMN default_post_time_range_seconds_new integer,
ADD COLUMN disallow_nsfw_content_new boolean DEFAULT FALSE NOT NULL,
ADD COLUMN users_new bigint DEFAULT 1 NOT NULL,
ADD COLUMN posts_new bigint DEFAULT 0 NOT NULL,
ADD COLUMN comments_new bigint DEFAULT 0 NOT NULL,
ADD COLUMN communities_new bigint DEFAULT 0 NOT NULL,
ADD COLUMN users_active_day_new bigint DEFAULT 0 NOT NULL,
ADD COLUMN users_active_week_new bigint DEFAULT 0 NOT NULL,
ADD COLUMN users_active_month_new bigint DEFAULT 0 NOT NULL,
ADD COLUMN users_active_half_year_new bigint DEFAULT 0 NOT NULL,
ADD COLUMN disable_email_notifications_new boolean DEFAULT FALSE NOT NULL;
-- Update
UPDATE
local_site
SET
(application_email_admins_new,
slur_filter_regex_new,
actor_name_max_length_new,
federation_enabled_new,
captcha_enabled_new,
captcha_difficulty_new,
published_new,
updated_new,
registration_mode_new,
reports_email_admins_new,
federation_signed_fetch_new,
default_post_listing_mode_new,
default_post_sort_type_new,
default_comment_sort_type_new,
oauth_registration_new,
post_upvotes_new,
post_downvotes_new,
comment_upvotes_new,
comment_downvotes_new,
default_post_time_range_seconds_new,
disallow_nsfw_content_new,
users_new,
posts_new,
comments_new,
communities_new,
users_active_day_new,
users_active_week_new,
users_active_month_new,
users_active_half_year_new,
disable_email_notifications_new) = (application_email_admins,
slur_filter_regex,
actor_name_max_length,
federation_enabled,
captcha_enabled,
captcha_difficulty,
published,
updated,
registration_mode,
reports_email_admins,
federation_signed_fetch,
default_post_listing_mode,
default_post_sort_type,
default_comment_sort_type,
oauth_registration,
post_upvotes,
post_downvotes,
comment_upvotes,
comment_downvotes,
default_post_time_range_seconds,
disallow_nsfw_content,
users,
posts,
comments,
communities,
users_active_day,
users_active_week,
users_active_month,
users_active_half_year,
disable_email_notifications);
-- Drop
ALTER TABLE local_site
DROP COLUMN application_email_admins,
DROP COLUMN slur_filter_regex,
DROP COLUMN actor_name_max_length,
DROP COLUMN federation_enabled,
DROP COLUMN captcha_enabled,
DROP COLUMN captcha_difficulty,
DROP COLUMN published,
DROP COLUMN updated,
DROP COLUMN registration_mode,
DROP COLUMN reports_email_admins,
DROP COLUMN federation_signed_fetch,
DROP COLUMN default_post_listing_mode,
DROP COLUMN default_post_sort_type,
DROP COLUMN default_comment_sort_type,
DROP COLUMN oauth_registration,
DROP COLUMN post_upvotes,
DROP COLUMN post_downvotes,
DROP COLUMN comment_upvotes,
DROP COLUMN comment_downvotes,
DROP COLUMN default_post_time_range_seconds,
DROP COLUMN disallow_nsfw_content,
DROP COLUMN users,
DROP COLUMN posts,
DROP COLUMN comments,
DROP COLUMN communities,
DROP COLUMN users_active_day,
DROP COLUMN users_active_week,
DROP COLUMN users_active_month,
DROP COLUMN users_active_half_year,
DROP COLUMN disable_email_notifications;
-- Rename
ALTER TABLE local_site RENAME COLUMN application_email_admins_new TO application_email_admins;
ALTER TABLE local_site RENAME COLUMN slur_filter_regex_new TO slur_filter_regex;
ALTER TABLE local_site RENAME COLUMN actor_name_max_length_new TO actor_name_max_length;
ALTER TABLE local_site RENAME COLUMN federation_enabled_new TO federation_enabled;
ALTER TABLE local_site RENAME COLUMN captcha_enabled_new TO captcha_enabled;
ALTER TABLE local_site RENAME COLUMN captcha_difficulty_new TO captcha_difficulty;
ALTER TABLE local_site RENAME COLUMN published_new TO published;
ALTER TABLE local_site RENAME COLUMN updated_new TO updated;
ALTER TABLE local_site RENAME COLUMN registration_mode_new TO registration_mode;
ALTER TABLE local_site RENAME COLUMN reports_email_admins_new TO reports_email_admins;
ALTER TABLE local_site RENAME COLUMN federation_signed_fetch_new TO federation_signed_fetch;
ALTER TABLE local_site RENAME COLUMN default_post_listing_mode_new TO default_post_listing_mode;
ALTER TABLE local_site RENAME COLUMN default_post_sort_type_new TO default_post_sort_type;
ALTER TABLE local_site RENAME COLUMN default_comment_sort_type_new TO default_comment_sort_type;
ALTER TABLE local_site RENAME COLUMN oauth_registration_new TO oauth_registration;
ALTER TABLE local_site RENAME COLUMN post_upvotes_new TO post_upvotes;
ALTER TABLE local_site RENAME COLUMN post_downvotes_new TO post_downvotes;
ALTER TABLE local_site RENAME COLUMN comment_upvotes_new TO comment_upvotes;
ALTER TABLE local_site RENAME COLUMN comment_downvotes_new TO comment_downvotes;
ALTER TABLE local_site RENAME COLUMN default_post_time_range_seconds_new TO default_post_time_range_seconds;
ALTER TABLE local_site RENAME COLUMN disallow_nsfw_content_new TO disallow_nsfw_content;
ALTER TABLE local_site RENAME COLUMN users_new TO users;
ALTER TABLE local_site RENAME COLUMN posts_new TO posts;
ALTER TABLE local_site RENAME COLUMN comments_new TO comments;
ALTER TABLE local_site RENAME COLUMN communities_new TO communities;
ALTER TABLE local_site RENAME COLUMN users_active_day_new TO users_active_day;
ALTER TABLE local_site RENAME COLUMN users_active_week_new TO users_active_week;
ALTER TABLE local_site RENAME COLUMN users_active_month_new TO users_active_month;
ALTER TABLE local_site RENAME COLUMN users_active_half_year_new TO users_active_half_year;
ALTER TABLE local_site RENAME COLUMN disable_email_notifications_new TO disable_email_notifications;

View file

@ -0,0 +1,3 @@
ALTER TABLE local_site
DROP COLUMN hide_modlog_mod_names;