mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
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:
parent
a30a861546
commit
0dbcc54d4b
|
@ -1,26 +1,11 @@
|
||||||
import Controller from "@ember/controller";
|
import Controller from "@ember/controller";
|
||||||
import { action, computed } from "@ember/object";
|
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 { popupAjaxError } from "discourse/lib/ajax-error";
|
||||||
import { makeArray } from "discourse-common/lib/helpers";
|
import { makeArray } from "discourse-common/lib/helpers";
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
|
|
||||||
export default Controller.extend({
|
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(
|
allowPmUsersEnabled: and(
|
||||||
"model.user_option.enable_allowed_pm_users",
|
"model.user_option.enable_allowed_pm_users",
|
||||||
"model.user_option.allow_private_messages"
|
"model.user_option.allow_private_messages"
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<label class="control-label">{{i18n "user.users"}}</label>
|
<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="control-group user-ignore" data-setting-name="user-ignored-users">
|
||||||
<div class="controls tracking-controls user-notifications">
|
<div class="controls tracking-controls user-notifications">
|
||||||
<label>{{d-icon "far-eye-slash" class="icon"}}
|
<label>{{d-icon "far-eye-slash" class="icon"}}
|
||||||
|
@ -13,22 +14,24 @@
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
<div class="control-group user-mute" data-setting-name="user-muted-users">
|
{{#if this.model.can_mute_users}}
|
||||||
<div class="controls tracking-controls">
|
<div class="control-group user-mute" data-setting-name="user-muted-users">
|
||||||
<label>
|
<div class="controls tracking-controls">
|
||||||
{{d-icon "d-muted" class="icon"}}
|
<label>
|
||||||
<span>{{i18n "user.muted_users"}}</span>
|
{{d-icon "d-muted" class="icon"}}
|
||||||
</label>
|
<span>{{i18n "user.muted_users"}}</span>
|
||||||
<UserChooser
|
</label>
|
||||||
@value={{this.mutedUsernames}}
|
<UserChooser
|
||||||
@onChange={{action "onChangeMutedUsernames"}}
|
@value={{this.mutedUsernames}}
|
||||||
@options={{hash excludeCurrentUser=true}}
|
@onChange={{action "onChangeMutedUsernames"}}
|
||||||
/>
|
@options={{hash excludeCurrentUser=true}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="instructions">{{i18n "user.muted_users_instructions"}}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="instructions">{{i18n "user.muted_users_instructions"}}</div>
|
{{/if}}
|
||||||
</div>
|
|
||||||
|
|
||||||
{{#if this.currentUser.can_send_private_messages}}
|
{{#if this.model.can_send_private_messages}}
|
||||||
<div class="control-group private-messages">
|
<div class="control-group private-messages">
|
||||||
<label class="control-label">{{i18n "user.private_messages"}}</label>
|
<label class="control-label">{{i18n "user.private_messages"}}</label>
|
||||||
<div
|
<div
|
||||||
|
|
|
@ -26,6 +26,8 @@ export default {
|
||||||
trust_level: 4,
|
trust_level: 4,
|
||||||
can_edit: true,
|
can_edit: true,
|
||||||
can_invite_to_forum: true,
|
can_invite_to_forum: true,
|
||||||
|
can_ignore_users: true,
|
||||||
|
can_mute_users: true,
|
||||||
can_send_private_messages: true,
|
can_send_private_messages: true,
|
||||||
custom_fields: {},
|
custom_fields: {},
|
||||||
muted_category_ids: [],
|
muted_category_ids: [],
|
||||||
|
|
|
@ -147,7 +147,7 @@ class CurrentUserSerializer < BasicUserSerializer
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_ignore_users
|
def can_ignore_users
|
||||||
!is_anonymous && object.in_any_groups?(SiteSetting.ignore_allowed_groups_map)
|
scope.can_ignore_users?
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_delete_all_posts_and_topics
|
def can_delete_all_posts_and_topics
|
||||||
|
|
|
@ -51,7 +51,9 @@ class UserSerializer < UserCardSerializer
|
||||||
:custom_avatar_template,
|
:custom_avatar_template,
|
||||||
:has_title_badges,
|
:has_title_badges,
|
||||||
:muted_usernames,
|
:muted_usernames,
|
||||||
|
:can_mute_users,
|
||||||
:ignored_usernames,
|
:ignored_usernames,
|
||||||
|
:can_ignore_users,
|
||||||
:allowed_pm_usernames,
|
:allowed_pm_usernames,
|
||||||
:mailing_list_posts_per_day,
|
:mailing_list_posts_per_day,
|
||||||
:can_change_bio,
|
:can_change_bio,
|
||||||
|
@ -254,10 +256,18 @@ class UserSerializer < UserCardSerializer
|
||||||
MutedUser.where(user_id: object.id).joins(:muted_user).pluck(:username)
|
MutedUser.where(user_id: object.id).joins(:muted_user).pluck(:username)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def can_mute_users
|
||||||
|
scope.can_mute_users?
|
||||||
|
end
|
||||||
|
|
||||||
def ignored_usernames
|
def ignored_usernames
|
||||||
IgnoredUser.where(user_id: object.id).joins(:ignored_user).pluck(:username)
|
IgnoredUser.where(user_id: object.id).joins(:ignored_user).pluck(:username)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def can_ignore_users
|
||||||
|
scope.can_ignore_users?
|
||||||
|
end
|
||||||
|
|
||||||
def allowed_pm_usernames
|
def allowed_pm_usernames
|
||||||
AllowedPmUser.where(user_id: object.id).joins(:allowed_pm_user).pluck(:username)
|
AllowedPmUser.where(user_id: object.id).joins(:allowed_pm_user).pluck(:username)
|
||||||
end
|
end
|
||||||
|
|
|
@ -559,8 +559,7 @@ class Guardian
|
||||||
|
|
||||||
def can_ignore_users?
|
def can_ignore_users?
|
||||||
return false if anonymous?
|
return false if anonymous?
|
||||||
@user.staff? || @user.has_trust_level?(SiteSetting.min_trust_level_to_allow_ignore.to_i) ||
|
@user.staff? || @user.in_any_groups?(SiteSetting.ignore_allowed_groups_map)
|
||||||
@user.in_any_groups?(SiteSetting.ignore_allowed_groups_map)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def allowed_theme_repo_import?(repo)
|
def allowed_theme_repo_import?(repo)
|
||||||
|
|
|
@ -47,9 +47,15 @@
|
||||||
"can_ignore_user": {
|
"can_ignore_user": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
|
"can_ignore_users": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"can_mute_user": {
|
"can_mute_user": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
|
"can_mute_users": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"can_send_private_messages": {
|
"can_send_private_messages": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
|
|
|
@ -21,59 +21,61 @@ RSpec.describe WebHookUserSerializer do
|
||||||
|
|
||||||
it "should only include the required keys" do
|
it "should only include the required keys" do
|
||||||
expect(serializer.as_json.keys).to contain_exactly(
|
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,
|
:admin,
|
||||||
:title,
|
:allowed_pm_usernames,
|
||||||
|
:avatar_template,
|
||||||
:badge_count,
|
:badge_count,
|
||||||
:time_read,
|
:can_ignore_users,
|
||||||
:recent_time_read,
|
:can_mute_users,
|
||||||
:primary_group_id,
|
:can_upload_profile_header,
|
||||||
:primary_group_name,
|
: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_group_id,
|
||||||
:flair_name,
|
:flair_name,
|
||||||
:flair_url,
|
:flair_url,
|
||||||
:flair_bg_color,
|
:groups,
|
||||||
:flair_color,
|
:id,
|
||||||
:featured_topic,
|
:ignored_usernames,
|
||||||
:staged,
|
:invited_by,
|
||||||
:pending_count,
|
:last_posted_at,
|
||||||
:profile_view_count,
|
:last_seen_at,
|
||||||
:second_factor_enabled,
|
|
||||||
:can_upload_profile_header,
|
|
||||||
:can_upload_user_card_background,
|
|
||||||
:post_count,
|
|
||||||
:locale,
|
:locale,
|
||||||
|
:mailing_list_posts_per_day,
|
||||||
|
:moderator,
|
||||||
:muted_category_ids,
|
:muted_category_ids,
|
||||||
:regular_category_ids,
|
|
||||||
:watched_tags,
|
|
||||||
:watching_first_post_tags,
|
|
||||||
:tracked_tags,
|
|
||||||
:muted_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_category_ids,
|
||||||
|
:tracked_tags,
|
||||||
|
:trust_level,
|
||||||
|
:user_notification_schedule,
|
||||||
|
:user_option,
|
||||||
|
:username,
|
||||||
:watched_category_ids,
|
:watched_category_ids,
|
||||||
:watched_first_post_category_ids,
|
:watched_first_post_category_ids,
|
||||||
:system_avatar_template,
|
:watched_tags,
|
||||||
:muted_usernames,
|
:watching_first_post_tags,
|
||||||
:ignored_usernames,
|
|
||||||
:allowed_pm_usernames,
|
|
||||||
:mailing_list_posts_per_day,
|
|
||||||
:user_notification_schedule,
|
|
||||||
:external_id,
|
|
||||||
:featured_user_badge_ids,
|
|
||||||
:invited_by,
|
|
||||||
:groups,
|
|
||||||
:user_option,
|
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user