mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 02:50:00 +08:00
FIX: Users should be able to remove their primary group
This fix allows a user to remove their currently assigned primary group if the Site Setting `user selected primary groups` is enabled. Before this fix, if a user selected "none" for their primary group it would silently fail and never be updated.
This commit is contained in:
parent
3fc589f875
commit
75069ff179
|
@ -89,6 +89,10 @@ class UserUpdater
|
|||
guardian.can_use_primary_group?(user, attributes[:primary_group_id])
|
||||
|
||||
user.primary_group_id = attributes[:primary_group_id]
|
||||
elsif SiteSetting.user_selected_primary_groups &&
|
||||
!attributes[:primary_group_id].present?
|
||||
|
||||
user.primary_group_id = nil
|
||||
end
|
||||
|
||||
CATEGORY_IDS.each do |attribute, level|
|
||||
|
|
|
@ -272,6 +272,26 @@ describe UserUpdater do
|
|||
user.reload
|
||||
expect(user.primary_group_id).to eq nil
|
||||
end
|
||||
|
||||
it 'can be removed by the user when setting is enabled' 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(primary_group_id: '')
|
||||
|
||||
user.reload
|
||||
expect(user.primary_group_id).to eq nil
|
||||
end
|
||||
|
||||
it 'cannot be removed by the user when setting is disabled' do
|
||||
SiteSetting.user_selected_primary_groups = false
|
||||
user.groups << new_group
|
||||
user.update(primary_group_id: new_group.id)
|
||||
UserUpdater.new(acting_user, user).update(primary_group_id: '')
|
||||
|
||||
user.reload
|
||||
expect(user.primary_group_id).to eq new_group.id
|
||||
end
|
||||
end
|
||||
|
||||
context 'when update fails' do
|
||||
|
|
Loading…
Reference in New Issue
Block a user