A platform for community discussion. Free, open, simple.
FIX: User can change name when auth_overrides_name is enabled.
Alan Guo Xiang Tan32951ca2f4c0
diff --git a/app/services/user_updater.rb b/app/services/user_updater.rbindex adb2cc6dba1..84446b98794 100644--- a/app/services/user_updater.rb+++ b/app/services/user_updater.rb@@ -97,7 +97,10 @@ class UserUpdaterendold_user_name = user.name.present? ? user.name : ""- user.name = attributes.fetch(:name) { user.name }++ if guardian.can_edit_name?(user)+ user.name = attributes.fetch(:name) { user.name }+ enduser.locale = attributes.fetch(:locale) { user.locale }user.date_of_birth = attributes.fetch(:date_of_birth) { user.date_of_birth }diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rbindex 5fa9eb0a714..78fc05a68cd 100644--- a/spec/requests/users_controller_spec.rb+++ b/spec/requests/users_controller_spec.rb@@ -1083,8 +1083,11 @@ describe UsersController doexpect(response.status).to eq(200)json = response.parsed_bodyexpect(json['success']).to eq(true)- expect(User.last.username).to eq('testosama')- expect(User.last.name).to eq('Osama Test')++ user = User.last++ expect(user.username).to eq('testosama')+ expect(user.name).to eq('Osama Test')endend@@ -1821,6 +1824,17 @@ describe UsersController doendend+ it "does not allow name to be updated if auth auth_overrides_name is enabled" do+ SiteSetting.auth_overrides_name = true++ sign_in(user)++ put "/u/#{user.username}", params: { name: 'test.test' }++ expect(response.status).to eq(200)+ expect(user.reload.name).to_not eq('test.test')+ end+context "when username contains a period" dobefore dosign_in(user)diff --git a/spec/services/user_updater_spec.rb b/spec/services/user_updater_spec.rbindex 4f9545d803d..9d52d1c1317 100644--- a/spec/services/user_updater_spec.rb+++ b/spec/services/user_updater_spec.rb@@ -43,7 +43,7 @@ describe UserUpdater doit 'saves user' douser = Fabricate(:user, name: 'Billy Bob')- updater = UserUpdater.new(acting_user, user)+ updater = UserUpdater.new(user, user)updater.update(name: 'Jim Tom')@@ -547,11 +547,10 @@ describe UserUpdater doendit "logs the action" do- user_without_name = Fabricate(:user, name: nil)user = Fabricate(:user, name: 'Billy Bob')expect do- UserUpdater.new(acting_user, user).update(name: 'Jim Tom')+ UserUpdater.new(user, user).update(name: 'Jim Tom')end.to change { UserHistory.count }.by(1)expect(UserHistory.last.action).to eq(@@ -559,19 +558,21 @@ describe UserUpdater do)expect do- UserUpdater.new(acting_user, user).update(name: 'JiM TOm')+ UserUpdater.new(user, user).update(name: 'JiM TOm')end.to_not change { UserHistory.count }expect do- UserUpdater.new(acting_user, user).update(bio_raw: 'foo bar')+ UserUpdater.new(user, user).update(bio_raw: 'foo bar')end.to_not change { UserHistory.count }+ user_without_name = Fabricate(:user, name: nil)+expect do- UserUpdater.new(acting_user, user_without_name).update(bio_raw: 'foo bar')+ UserUpdater.new(user_without_name, user_without_name).update(bio_raw: 'foo bar')end.to_not change { UserHistory.count }expect do- UserUpdater.new(acting_user, user_without_name).update(name: 'Jim Tom')+ UserUpdater.new(user_without_name, user_without_name).update(name: 'Jim Tom')end.to change { UserHistory.count }.by(1)expect(UserHistory.last.action).to eq(@@ -579,7 +580,7 @@ describe UserUpdater do)expect do- UserUpdater.new(acting_user, user).update(name: '')+ UserUpdater.new(user, user).update(name: '')end.to change { UserHistory.count }.by(1)expect(UserHistory.last.action).to eq(