Skip to content

A platform for community discussion. Free, open, simple.

FIX: log name changes only when the name is actually updated

Arpit Jalan059e36a6ff44
diff --git a/app/services/user_updater.rb b/app/services/user_updater.rb
index 755844f0ffe..558f08953c4 100644
--- a/app/services/user_updater.rb
+++ b/app/services/user_updater.rb
@@ -123,9 +123,9 @@ class UserUpdater
update_muted_users(attributes[:muted_usernames])
end
+ name_changed = user.name_changed?
if (saved = (!save_options || user.user_option.save) && user_profile.save && user.save) &&
- (attributes[:name].present? && old_user_name.casecmp(attributes.fetch(:name)) != 0) ||
- (attributes[:name].blank? && old_user_name.present?)
+ (name_changed && old_user_name.casecmp(attributes.fetch(:name)) != 0)
StaffActionLogger.new(@actor).log_name_change(
user.id,
diff --git a/spec/services/user_updater_spec.rb b/spec/services/user_updater_spec.rb
index bbec1f0c670..609099ad4af 100644
--- a/spec/services/user_updater_spec.rb
+++ b/spec/services/user_updater_spec.rb
@@ -308,6 +308,10 @@ describe UserUpdater do
UserUpdater.new(acting_user, user).update(name: 'JiM TOm')
end.to_not change { UserHistory.count }
+ expect do
+ UserUpdater.new(acting_user, user).update(bio_raw: 'foo bar')
+ end.to_not change { UserHistory.count }
+
expect do
UserUpdater.new(acting_user, user_without_name).update(bio_raw: 'foo bar')
end.to_not change { UserHistory.count }