mirror of
https://github.com/discourse/discourse.git
synced 2025-02-23 07:40:54 +08:00
FIX: A much nicer error message if you can't ignore/mute a user
This commit is contained in:
parent
6cb6faff29
commit
494a27dc27
@ -1178,6 +1178,7 @@ class UsersController < ApplicationController
|
|||||||
user = fetch_user_from_params
|
user = fetch_user_from_params
|
||||||
|
|
||||||
if params[:notification_level] == "ignore"
|
if params[:notification_level] == "ignore"
|
||||||
|
@error_message = "ignore_error"
|
||||||
guardian.ensure_can_ignore_user!(user)
|
guardian.ensure_can_ignore_user!(user)
|
||||||
MutedUser.where(user: current_user, muted_user: user).delete_all
|
MutedUser.where(user: current_user, muted_user: user).delete_all
|
||||||
ignored_user = IgnoredUser.find_by(user: current_user, ignored_user: user)
|
ignored_user = IgnoredUser.find_by(user: current_user, ignored_user: user)
|
||||||
@ -1187,6 +1188,7 @@ class UsersController < ApplicationController
|
|||||||
IgnoredUser.create!(user: current_user, ignored_user: user, expiring_at: Time.parse(params[:expiring_at]))
|
IgnoredUser.create!(user: current_user, ignored_user: user, expiring_at: Time.parse(params[:expiring_at]))
|
||||||
end
|
end
|
||||||
elsif params[:notification_level] == "mute"
|
elsif params[:notification_level] == "mute"
|
||||||
|
@error_message = "mute_error"
|
||||||
guardian.ensure_can_mute_user!(user)
|
guardian.ensure_can_mute_user!(user)
|
||||||
IgnoredUser.where(user: current_user, ignored_user: user).delete_all
|
IgnoredUser.where(user: current_user, ignored_user: user).delete_all
|
||||||
MutedUser.find_or_create_by!(user: current_user, muted_user: user)
|
MutedUser.find_or_create_by!(user: current_user, muted_user: user)
|
||||||
@ -1196,6 +1198,8 @@ class UsersController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
render json: success_json
|
render json: success_json
|
||||||
|
rescue Discourse::InvalidAccess => e
|
||||||
|
render_json_error(I18n.t("notification_level.#{@error_message}"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_faq
|
def read_faq
|
||||||
|
@ -847,7 +847,7 @@ en:
|
|||||||
all: "All"
|
all: "All"
|
||||||
read: "Read"
|
read: "Read"
|
||||||
unread: "Unread"
|
unread: "Unread"
|
||||||
ignore_duration_title: "Ignore Timer"
|
ignore_duration_title: "Ignore User"
|
||||||
ignore_duration_username: "Username"
|
ignore_duration_username: "Username"
|
||||||
ignore_duration_when: "Duration:"
|
ignore_duration_when: "Duration:"
|
||||||
ignore_duration_save: "Ignore"
|
ignore_duration_save: "Ignore"
|
||||||
|
@ -4855,6 +4855,10 @@ en:
|
|||||||
email_style:
|
email_style:
|
||||||
html_missing_placeholder: "The html template must include %{placeholder}"
|
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:
|
discord:
|
||||||
not_in_allowed_guild: "Authentication failed. You are not a member of a permitted Discord guild."
|
not_in_allowed_guild: "Authentication failed. You are not a member of a permitted Discord guild."
|
||||||
|
|
||||||
|
@ -2414,6 +2414,22 @@ describe UsersController do
|
|||||||
let!(:ignored_user) { Fabricate(:ignored_user, user: user, ignored_user: another_user) }
|
let!(:ignored_user) { Fabricate(:ignored_user, user: user, ignored_user: another_user) }
|
||||||
let!(:muted_user) { Fabricate(:muted_user, user: user, muted_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' do
|
context 'when changing notification level to normal' do
|
||||||
it 'changes notification level to normal' do
|
it 'changes notification level to normal' do
|
||||||
put "/u/#{another_user.username}/notification_level.json", params: { notification_level: "normal" }
|
put "/u/#{another_user.username}/notification_level.json", params: { notification_level: "normal" }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user