mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06: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:
@@ -89,6 +89,10 @@ class UserUpdater
|
|||||||
guardian.can_use_primary_group?(user, attributes[:primary_group_id])
|
guardian.can_use_primary_group?(user, attributes[:primary_group_id])
|
||||||
|
|
||||||
user.primary_group_id = 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
|
end
|
||||||
|
|
||||||
CATEGORY_IDS.each do |attribute, level|
|
CATEGORY_IDS.each do |attribute, level|
|
||||||
|
|||||||
@@ -272,6 +272,26 @@ describe UserUpdater do
|
|||||||
user.reload
|
user.reload
|
||||||
expect(user.primary_group_id).to eq nil
|
expect(user.primary_group_id).to eq nil
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context 'when update fails' do
|
context 'when update fails' do
|
||||||
|
|||||||
Reference in New Issue
Block a user