From 43d4859d3018e87fd354ae385225ec4d2c93bbc7 Mon Sep 17 00:00:00 2001 From: Bianca Nenciu Date: Fri, 9 Jul 2021 07:41:26 +0300 Subject: [PATCH] FIX: Let user clear their flair group (#13669) Users were able to select their flair, but were not able to clear it by selecting (none). --- app/services/user_updater.rb | 3 ++- spec/services/user_updater_spec.rb | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/services/user_updater.rb b/app/services/user_updater.rb index 7635b90fcc8..7c56d8eebef 100644 --- a/app/services/user_updater.rb +++ b/app/services/user_updater.rb @@ -123,7 +123,8 @@ class UserUpdater if attributes[:flair_group_id] && attributes[:flair_group_id] != user.flair_group_id && - guardian.can_use_primary_group?(user, attributes[:flair_group_id]) + (attributes[:flair_group_id].blank? || + guardian.can_use_primary_group?(user, attributes[:flair_group_id])) user.flair_group_id = attributes[:flair_group_id] end diff --git a/spec/services/user_updater_spec.rb b/spec/services/user_updater_spec.rb index b9af1c7a95a..415375e802e 100644 --- a/spec/services/user_updater_spec.rb +++ b/spec/services/user_updater_spec.rb @@ -370,6 +370,21 @@ describe UserUpdater do end end + context 'when updating flair group' do + let(:group) { Fabricate(:group, name: "Group", flair_bg_color: "#111111", flair_color: "#999999", flair_icon: "icon") } + let(:user) { Fabricate(:user) } + + it 'updates when setting is enabled' do + group.add(user) + + UserUpdater.new(acting_user, user).update(flair_group_id: group.id) + expect(user.reload.flair_group_id).to eq(group.id) + + UserUpdater.new(acting_user, user).update(flair_group_id: "") + expect(user.reload.flair_group_id).to eq(nil) + end + end + context 'when update fails' do it 'returns false' do user = Fabricate(:user)