DEV: use new 'ignore allowed groups' site settings (#27670)

Instead of the deprecated 'min trust level to allow ignore' in order to reduce the number of deprecation notices in the logs.

This tweaks a few serializers so that the 'can_ignore_users?` property is always coming from the server and properly used on the client-side.
This commit is contained in:
Régis Hanol 2024-07-04 19:27:26 +02:00 committed by GitHub
parent a30a861546
commit 0dbcc54d4b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 83 additions and 76 deletions

View File

@ -1,26 +1,11 @@
import Controller from "@ember/controller";
import { action, computed } from "@ember/object";
import { alias, and } from "@ember/object/computed";
import { and } from "@ember/object/computed";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { makeArray } from "discourse-common/lib/helpers";
import discourseComputed from "discourse-common/utils/decorators";
export default Controller.extend({
ignoredUsernames: alias("model.ignored_usernames"),
@discourseComputed("model.trust_level", "model.groups")
userCanIgnore(trustLevel) {
return (
trustLevel >= this.siteSettings.min_trust_level_to_allow_ignore ||
this.currentUser.can_ignore_users
);
},
@discourseComputed("userCanIgnore", "model.staff")
ignoredEnabled(userCanIgnore, userIsStaff) {
return this.currentUser.staff || userCanIgnore || userIsStaff;
},
allowPmUsersEnabled: and(
"model.user_option.enable_allowed_pm_users",
"model.user_option.allow_private_messages"

View File

@ -1,5 +1,6 @@
<label class="control-label">{{i18n "user.users"}}</label>
{{#if this.ignoredEnabled}}
{{#if this.model.can_ignore_users}}
<div class="control-group user-ignore" data-setting-name="user-ignored-users">
<div class="controls tracking-controls user-notifications">
<label>{{d-icon "far-eye-slash" class="icon"}}
@ -13,22 +14,24 @@
</div>
{{/if}}
<div class="control-group user-mute" data-setting-name="user-muted-users">
<div class="controls tracking-controls">
<label>
{{d-icon "d-muted" class="icon"}}
<span>{{i18n "user.muted_users"}}</span>
</label>
<UserChooser
@value={{this.mutedUsernames}}
@onChange={{action "onChangeMutedUsernames"}}
@options={{hash excludeCurrentUser=true}}
/>
{{#if this.model.can_mute_users}}
<div class="control-group user-mute" data-setting-name="user-muted-users">
<div class="controls tracking-controls">
<label>
{{d-icon "d-muted" class="icon"}}
<span>{{i18n "user.muted_users"}}</span>
</label>
<UserChooser
@value={{this.mutedUsernames}}
@onChange={{action "onChangeMutedUsernames"}}
@options={{hash excludeCurrentUser=true}}
/>
</div>
<div class="instructions">{{i18n "user.muted_users_instructions"}}</div>
</div>
<div class="instructions">{{i18n "user.muted_users_instructions"}}</div>
</div>
{{/if}}
{{#if this.currentUser.can_send_private_messages}}
{{#if this.model.can_send_private_messages}}
<div class="control-group private-messages">
<label class="control-label">{{i18n "user.private_messages"}}</label>
<div

View File

@ -26,6 +26,8 @@ export default {
trust_level: 4,
can_edit: true,
can_invite_to_forum: true,
can_ignore_users: true,
can_mute_users: true,
can_send_private_messages: true,
custom_fields: {},
muted_category_ids: [],

View File

@ -147,7 +147,7 @@ class CurrentUserSerializer < BasicUserSerializer
end
def can_ignore_users
!is_anonymous && object.in_any_groups?(SiteSetting.ignore_allowed_groups_map)
scope.can_ignore_users?
end
def can_delete_all_posts_and_topics

View File

@ -51,7 +51,9 @@ class UserSerializer < UserCardSerializer
:custom_avatar_template,
:has_title_badges,
:muted_usernames,
:can_mute_users,
:ignored_usernames,
:can_ignore_users,
:allowed_pm_usernames,
:mailing_list_posts_per_day,
:can_change_bio,
@ -254,10 +256,18 @@ class UserSerializer < UserCardSerializer
MutedUser.where(user_id: object.id).joins(:muted_user).pluck(:username)
end
def can_mute_users
scope.can_mute_users?
end
def ignored_usernames
IgnoredUser.where(user_id: object.id).joins(:ignored_user).pluck(:username)
end
def can_ignore_users
scope.can_ignore_users?
end
def allowed_pm_usernames
AllowedPmUser.where(user_id: object.id).joins(:allowed_pm_user).pluck(:username)
end

View File

@ -559,8 +559,7 @@ class Guardian
def can_ignore_users?
return false if anonymous?
@user.staff? || @user.has_trust_level?(SiteSetting.min_trust_level_to_allow_ignore.to_i) ||
@user.in_any_groups?(SiteSetting.ignore_allowed_groups_map)
@user.staff? || @user.in_any_groups?(SiteSetting.ignore_allowed_groups_map)
end
def allowed_theme_repo_import?(repo)

View File

@ -47,9 +47,15 @@
"can_ignore_user": {
"type": "boolean"
},
"can_ignore_users": {
"type": "boolean"
},
"can_mute_user": {
"type": "boolean"
},
"can_mute_users": {
"type": "boolean"
},
"can_send_private_messages": {
"type": "boolean"
},

View File

@ -21,59 +21,61 @@ RSpec.describe WebHookUserSerializer do
it "should only include the required keys" do
expect(serializer.as_json.keys).to contain_exactly(
:id,
:username,
:name,
:avatar_template,
:email,
:secondary_emails,
:last_posted_at,
:last_seen_at,
:created_at,
:muted,
:trust_level,
:moderator,
:admin,
:title,
:allowed_pm_usernames,
:avatar_template,
:badge_count,
:time_read,
:recent_time_read,
:primary_group_id,
:primary_group_name,
:can_ignore_users,
:can_mute_users,
:can_upload_profile_header,
:can_upload_user_card_background,
:created_at,
:email,
:external_id,
:featured_topic,
:featured_user_badge_ids,
:flair_bg_color,
:flair_color,
:flair_group_id,
:flair_name,
:flair_url,
:flair_bg_color,
:flair_color,
:featured_topic,
:staged,
:pending_count,
:profile_view_count,
:second_factor_enabled,
:can_upload_profile_header,
:can_upload_user_card_background,
:post_count,
:groups,
:id,
:ignored_usernames,
:invited_by,
:last_posted_at,
:last_seen_at,
:locale,
:mailing_list_posts_per_day,
:moderator,
:muted_category_ids,
:regular_category_ids,
:watched_tags,
:watching_first_post_tags,
:tracked_tags,
:muted_tags,
:muted_usernames,
:muted,
:name,
:pending_count,
:post_count,
:primary_group_id,
:primary_group_name,
:profile_view_count,
:recent_time_read,
:regular_category_ids,
:second_factor_enabled,
:secondary_emails,
:staged,
:system_avatar_template,
:time_read,
:title,
:tracked_category_ids,
:tracked_tags,
:trust_level,
:user_notification_schedule,
:user_option,
:username,
:watched_category_ids,
:watched_first_post_category_ids,
:system_avatar_template,
:muted_usernames,
:ignored_usernames,
:allowed_pm_usernames,
:mailing_list_posts_per_day,
:user_notification_schedule,
:external_id,
:featured_user_badge_ids,
:invited_by,
:groups,
:user_option,
:watched_tags,
:watching_first_post_tags,
)
end
end