FIX: Avoid validation error when deleting users with locked trust level
This commit is contained in:
parent
f32cc04ddc
commit
407bb96a22
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue