mirror of
https://github.com/discourse/discourse.git
synced 2025-04-02 22:09:40 +08:00
FIX: better error message on username update from Admin user page.
This commit is contained in:
parent
a1a61fcd2d
commit
1481ea640c
@ -151,6 +151,12 @@ class UsersController < ApplicationController
|
|||||||
else
|
else
|
||||||
render_json_error(user.errors.full_messages.join(','))
|
render_json_error(user.errors.full_messages.join(','))
|
||||||
end
|
end
|
||||||
|
rescue Discourse::InvalidAccess
|
||||||
|
if current_user&.staff?
|
||||||
|
render_json_error(I18n.t('errors.messages.sso_overrides_username'))
|
||||||
|
else
|
||||||
|
render json: failed_json, status: 403
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_emails
|
def check_emails
|
||||||
|
@ -183,6 +183,7 @@ en:
|
|||||||
one: is the wrong length (should be %{count} character)
|
one: is the wrong length (should be %{count} character)
|
||||||
other: is the wrong length (should be %{count} characters)
|
other: is the wrong length (should be %{count} characters)
|
||||||
other_than: "must be other than %{count}"
|
other_than: "must be other than %{count}"
|
||||||
|
sso_overrides_username: "Username needs to be updated on SSO provider side, since `sso_overrides_username` setting is enabled."
|
||||||
template:
|
template:
|
||||||
body: ! "There were problems with the following fields:"
|
body: ! "There were problems with the following fields:"
|
||||||
header:
|
header:
|
||||||
|
@ -1227,6 +1227,18 @@ describe UsersController do
|
|||||||
|
|
||||||
expect(::JSON.parse(response.body)['username']).to eq(new_username)
|
expect(::JSON.parse(response.body)['username']).to eq(new_username)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should respond with proper error message if sso_overrides_username is enabled' do
|
||||||
|
SiteSetting.sso_url = 'http://someurl.com'
|
||||||
|
SiteSetting.enable_sso = true
|
||||||
|
SiteSetting.sso_overrides_username = true
|
||||||
|
acting_user = Fabricate(:admin)
|
||||||
|
sign_in(acting_user)
|
||||||
|
|
||||||
|
put "/u/#{user.username}/preferences/username.json", params: { new_username: new_username }
|
||||||
|
|
||||||
|
expect(response.status).to eq(422)
|
||||||
|
expect(::JSON.parse(response.body)['errors'].first).to include(I18n.t('errors.messages.sso_overrides_username'))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user