Skip to content

Commit

Permalink
FIX: log name changes only when the name is actually updated
Browse files Browse the repository at this point in the history
  • Loading branch information
arpitjalan committed Nov 30, 2018
1 parent fc0b7c9 commit 059e36a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/services/user_updater.rb
Expand Up @@ -123,9 +123,9 @@ def update(attributes = {})
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,
Expand Down
4 changes: 4 additions & 0 deletions spec/services/user_updater_spec.rb
Expand Up @@ -308,6 +308,10 @@
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 }
Expand Down

3 comments on commit 059e36a

@coding-horror
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when was this bug introduced? how long have name changes been incorrectly logged?

@arpitjalan
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this bug was introduced when user preferences page was updated to use tabs (sub-sections) in April 2017. I am updating my local Discourse instance just prior to that commit to verify.

@arpitjalan
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "log user name changes" feature was regressed in this commit.

Please sign in to comment.