FIX: Don't raise an exception if we can't update the user on demotion

This is causing issues when purging old users, if they are set up in the
exact condition where they will be demoted into another group, but also
do not have a primary email.
This commit is contained in:
Robin Ward 2020-06-22 15:43:59 -04:00
parent d473ddd02c
commit ac9577bcc7
2 changed files with 13 additions and 2 deletions

View File

@ -126,8 +126,8 @@ class Promotion
# Then consider the group locked level
user_group_granted_trust_level = user.group_granted_trust_level
unless user_group_granted_trust_level.blank?
return user.update!(
if user_group_granted_trust_level.present?
return user.update(
trust_level: user_group_granted_trust_level
)
end

View File

@ -390,6 +390,17 @@ describe UserDestroyer do
d.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)
UserEmail.where(user: user).delete_all
user.reload
expect {
UserDestroyer.new(admin).destroy(user)
}.to change { User.count }.by(-1)
end
end
context 'user has staff action logs' do