diff --git a/app/assets/javascripts/admin/templates/modal/admin-suspend-user.hbs b/app/assets/javascripts/admin/templates/modal/admin-suspend-user.hbs index afb7525fb59..e97eb0989ba 100644 --- a/app/assets/javascripts/admin/templates/modal/admin-suspend-user.hbs +++ b/app/assets/javascripts/admin/templates/modal/admin-suspend-user.hbs @@ -4,7 +4,12 @@ {{text-field value=duration maxlength="5" autofocus="autofocus"}} {{i18n 'admin.user.suspend_duration_units'}}

- {{{i18n 'admin.user.suspend_reason_label'}}}
+ {{#if siteSettings.hide_suspension_reasons}} + {{{i18n 'admin.user.suspend_reason_hidden_label'}}}
+ {{else}} + {{{i18n 'admin.user.suspend_reason_label'}}}
+ {{/if}} +
{{text-field value=reason class="span8"}} diff --git a/app/assets/javascripts/discourse/templates/user.hbs b/app/assets/javascripts/discourse/templates/user.hbs index c2897679c6e..7c654823ef8 100644 --- a/app/assets/javascripts/discourse/templates/user.hbs +++ b/app/assets/javascripts/discourse/templates/user.hbs @@ -84,8 +84,10 @@ {{#if model.isSuspended}}
{{d-icon "ban"}} - {{i18n 'user.suspended_notice' date=model.suspendedTillDate}}
- {{i18n 'user.suspended_reason'}} {{model.suspend_reason}} + {{i18n 'user.suspended_notice' date=model.suspendedTillDate}}
+ {{#if model.suspend_reason}} + {{i18n 'user.suspended_reason'}} {{model.suspend_reason}} + {{/if}}
{{/if}} {{#if isNotSuspendedOrIsStaff}} diff --git a/app/serializers/user_serializer.rb b/app/serializers/user_serializer.rb index 036b49434e6..9f3356f2d47 100644 --- a/app/serializers/user_serializer.rb +++ b/app/serializers/user_serializer.rb @@ -251,7 +251,7 @@ class UserSerializer < BasicUserSerializer end def include_suspend_reason? - object.suspended? + scope.can_see_suspension_reason?(object) && object.suspended? end def include_suspended_till? diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index c7d6fc8ed84..19f3108f0f4 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -3266,6 +3266,7 @@ en: suspend_duration: "How long will the user be suspended for?" suspend_duration_units: "(days)" suspend_reason_label: "Why are you suspending? This text will be visible to everyone on this user's profile page, and will be shown to the user when they try to log in. Keep it short." + suspend_reason_hidden_label: "Why are you suspending? This text will be shown to the user when they try to log in. Keep it short." suspend_reason: "Reason" suspended_by: "Suspended by" delete_all_posts: "Delete all posts" diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index cfa15f741fc..e2d912f049d 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1441,6 +1441,7 @@ en: hide_user_profiles_from_public: "Disable user cards, user profiles and user directory for anonymous users." + hide_suspension_reasons: "Don't display suspension reasons publically on user profiles." user_website_domains_whitelist: "User website will be verified against these domains. Pipe-delimited list." allow_profile_backgrounds: "Allow users to upload profile backgrounds." diff --git a/config/site_settings.yml b/config/site_settings.yml index 52363b76122..ab296981597 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -422,6 +422,9 @@ users: user_website_domains_whitelist: default: '' type: list + hide_suspension_reasons: + default: false + client: true groups: enable_group_directory: diff --git a/lib/guardian/user_guardian.rb b/lib/guardian/user_guardian.rb index 3eca04f589b..616020aa98d 100644 --- a/lib/guardian/user_guardian.rb +++ b/lib/guardian/user_guardian.rb @@ -67,4 +67,9 @@ module UserGuardian user && is_staff? end + def can_see_suspension_reason?(user) + return true unless SiteSetting.hide_suspension_reasons? + user == @user || is_staff? + end + end diff --git a/spec/components/guardian_spec.rb b/spec/components/guardian_spec.rb index 03f6d9a75b5..9b43ac97651 100644 --- a/spec/components/guardian_spec.rb +++ b/spec/components/guardian_spec.rb @@ -2541,4 +2541,32 @@ describe Guardian do end end end + + context "suspension reasons" do + let(:user) { Fabricate(:user) } + + it "will be shown by default" do + expect(Guardian.new.can_see_suspension_reason?(user)).to eq(true) + end + + context "with hide suspension reason enabled" do + let(:moderator) { Fabricate(:moderator) } + + before do + SiteSetting.hide_suspension_reasons = true + end + + it "will not be shown to anonymous users" do + expect(Guardian.new.can_see_suspension_reason?(user)).to eq(false) + end + + it "users can see their own suspensions" do + expect(Guardian.new(user).can_see_suspension_reason?(user)).to eq(true) + end + + it "staff can see suspensions" do + expect(Guardian.new(moderator).can_see_suspension_reason?(user)).to eq(true) + end + end + end end