From bd49d4af1a19feb303f0658ae51bfeba81687519 Mon Sep 17 00:00:00 2001 From: Blake Erickson Date: Fri, 7 Feb 2020 16:26:33 -0700 Subject: [PATCH] FIX: Flair icon being removed when updating other profile info The commit: 75069ff17917f9b8969ae0e8e0e271cdf1e38c78 allows users to remove their primary group, but this introduced a bug where if you were to edit any other profile info like location or website which is a form on a separate page then the flair dropdown, would cause the selected flair to be removed. This fix ensures that if the `primary_group_id` parameter is missing from the update payload it does not remove the existing `primary_group_id`. It will only remove the `primary_group_id` if it is present in the payload and empty. --- app/services/user_updater.rb | 1 + spec/services/user_updater_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/app/services/user_updater.rb b/app/services/user_updater.rb index 30d6d46e915..5b3396f1017 100644 --- a/app/services/user_updater.rb +++ b/app/services/user_updater.rb @@ -90,6 +90,7 @@ class UserUpdater user.primary_group_id = attributes[:primary_group_id] elsif SiteSetting.user_selected_primary_groups && + attributes[:primary_group_id] && attributes[:primary_group_id].blank? user.primary_group_id = nil diff --git a/spec/services/user_updater_spec.rb b/spec/services/user_updater_spec.rb index 850de547fc3..5ca012fc135 100644 --- a/spec/services/user_updater_spec.rb +++ b/spec/services/user_updater_spec.rb @@ -273,6 +273,16 @@ describe UserUpdater do expect(user.primary_group_id).to eq nil end + it 'does not update when changing other profile data' do + SiteSetting.user_selected_primary_groups = true + user.groups << new_group + user.update(primary_group_id: new_group.id) + UserUpdater.new(acting_user, user).update(website: 'http://example.com') + + user.reload + expect(user.primary_group_id).to eq new_group.id + end + it 'can be removed by the user when setting is enabled' do SiteSetting.user_selected_primary_groups = true user.groups << new_group