A platform for community discussion. Free, open, simple.
FIX: A much nicer error message if you can't ignore/mute a user
Robin Ward494a27dc27c7
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rbindex a17245096da..886b0d20ce5 100644--- a/app/controllers/users_controller.rb+++ b/app/controllers/users_controller.rb@@ -1178,6 +1178,7 @@ class UsersController < ApplicationControlleruser = fetch_user_from_paramsif params[:notification_level] == "ignore"+ @error_message = "ignore_error"guardian.ensure_can_ignore_user!(user)MutedUser.where(user: current_user, muted_user: user).delete_allignored_user = IgnoredUser.find_by(user: current_user, ignored_user: user)@@ -1187,6 +1188,7 @@ class UsersController < ApplicationControllerIgnoredUser.create!(user: current_user, ignored_user: user, expiring_at: Time.parse(params[:expiring_at]))endelsif params[:notification_level] == "mute"+ @error_message = "mute_error"guardian.ensure_can_mute_user!(user)IgnoredUser.where(user: current_user, ignored_user: user).delete_allMutedUser.find_or_create_by!(user: current_user, muted_user: user)@@ -1196,6 +1198,8 @@ class UsersController < ApplicationControllerendrender json: success_json+ rescue Discourse::InvalidAccess => e+ render_json_error(I18n.t("notification_level.#{@error_message}"))enddef read_faqdiff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex febb6a61ac7..aacd7c256bc 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -847,7 +847,7 @@ en:all: "All"read: "Read"unread: "Unread"- ignore_duration_title: "Ignore Timer"+ ignore_duration_title: "Ignore User"ignore_duration_username: "Username"ignore_duration_when: "Duration:"ignore_duration_save: "Ignore"diff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex 5a3bc5ada40..eb5ae6820aa 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -4855,6 +4855,10 @@ en:email_style:html_missing_placeholder: "The html template must include %{placeholder}"+ notification_level:+ ignore_error: "Sorry, you can't ignore that user."+ mute_error: "Sorry, you can't mute that user."+discord:not_in_allowed_guild: "Authentication failed. You are not a member of a permitted Discord guild."diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rbindex ec5adf4018a..add1d7af01a 100644--- a/spec/requests/users_controller_spec.rb+++ b/spec/requests/users_controller_spec.rb@@ -2414,6 +2414,22 @@ describe UsersController dolet!(:ignored_user) { Fabricate(:ignored_user, user: user, ignored_user: another_user) }let!(:muted_user) { Fabricate(:muted_user, user: user, muted_user: another_user) }+ context "when you can't change the notification" do+ fab!(:staff_user) { Fabricate(:admin) }++ it "ignoring includes a helpful error message" do+ put "/u/#{staff_user.username}/notification_level.json", params: { notification_level: 'ignore' }+ expect(response.status).to eq(422)+ expect(response.parsed_body['errors'][0]).to eq(I18n.t("notification_level.ignore_error"))+ end++ it "muting includes a helpful error message" do+ put "/u/#{staff_user.username}/notification_level.json", params: { notification_level: 'mute' }+ expect(response.status).to eq(422)+ expect(response.parsed_body['errors'][0]).to eq(I18n.t("notification_level.mute_error"))+ end+ end+context 'when changing notification level to normal' doit 'changes notification level to normal' doput "/u/#{another_user.username}/notification_level.json", params: { notification_level: "normal" }