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

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

From 059e36a6ff4478208ccfaa6029bfe1cbb239a7fb Mon Sep 17 00:00:00 2001
From: Arpit Jalan <arpit@techapj.com>
Date: Fri, 30 Nov 2018 15:30:34 +0530
Subject: [PATCH] FIX: log name changes only when the name is actually updated


diff --git a/app/services/user_updater.rb b/app/services/user_updater.rb
index 755844f..558f089 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 bbec1f0..609099a 100644
--- a/spec/services/user_updater_spec.rb
+++ b/spec/services/user_updater_spec.rb
@@ -309,6 +309,10 @@ describe UserUpdater do
       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 }

GitHub

1 Like

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

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.

1 Like

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

3 Likes