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).
This commit is contained in:
Bianca Nenciu 2021-07-09 07:41:26 +03:00 committed by GitHub
parent ba62ecac68
commit 43d4859d30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -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

View File

@ -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)