FIX: Avoid validation error when deleting users with locked trust level

This commit is contained in:
David Taylor 2020-07-27 17:40:10 +01:00
parent f32cc04ddc
commit 407bb96a22
No known key found for this signature in database
GPG Key ID: 46904C18B1D3F434
2 changed files with 12 additions and 1 deletions

View File

@ -60,6 +60,7 @@ class GroupUser < ActiveRecord::Base
def recalculate_trust_level
return if group.grant_trust_level.nil?
return if self.destroyed_by_association&.active_record == User # User is being destroyed, so don't try to recalculate
Promotion.recalculate(user)
end

View File

@ -378,7 +378,7 @@ describe UserDestroyer do
end
context 'user belongs to groups that grant trust level' do
let(:group) { Fabricate(:group, grant_trust_level: 2) }
let(:group) { Fabricate(:group, grant_trust_level: 4) }
before do
group.add(user)
@ -391,6 +391,16 @@ describe UserDestroyer do
}.to change { User.count }.by(-1)
end
it 'can delete the user if they have a manual locked trust level and have no email' do
user.update(manual_locked_trust_level: 3)
UserEmail.where(user: user).delete_all
user.reload
expect {
UserDestroyer.new(admin).destroy(user)
}.to change { User.count }.by(-1)
end
it 'can delete the user if they were to fall into another trust level and have no email' do
g2 = Fabricate(:group, grant_trust_level: 1)
g2.add(user)