Fixes #3942 - New online notifications blocks data privacy user deletion.

This commit is contained in:
Rolf Schmidt 2022-02-04 16:43:28 +01:00 committed by Dominik Klein
parent 48cfdc8697
commit ceac28ce4d
2 changed files with 24 additions and 12 deletions

View file

@ -25,19 +25,38 @@ class DataPrivacyTask < ApplicationModel
handle_exception(e) handle_exception(e)
end end
# set user inactive before destroy to prevent
# new online notifications or other events while
# the deletion process is running
# https://github.com/zammad/zammad/issues/3942
def update_inactive(object)
object.update(active: false)
end
def perform_deletable def perform_deletable
return if deletable.blank? return if !deletable_type.constantize.exists?(id: deletable_id)
prepare_deletion_preview prepare_deletion_preview
save! save!
if delete_organization? if delete_organization?
deletable.organization.destroy(associations: true) perform_organization
else else
deletable.destroy perform_user
end end
end end
def perform_organization
update_inactive(deletable.organization)
deletable.organization.members.find_each { |user| update_inactive(user) }
deletable.organization.destroy(associations: true)
end
def perform_user
update_inactive(deletable)
deletable.destroy
end
def handle_exception(e) def handle_exception(e)
Rails.logger.error e Rails.logger.error e
preferences[:error] = "ERROR: #{e.inspect}" preferences[:error] = "ERROR: #{e.inspect}"

View file

@ -36,18 +36,11 @@ RSpec.describe DataPrivacyTask, type: :model do
expect(create(:data_privacy_task, deletable: admin)).to be_truthy expect(create(:data_privacy_task, deletable: admin)).to be_truthy
end end
it 'sets the failed state when task failed' do it 'sets no error message when user is already deleted' do
task = create(:data_privacy_task, deletable: user) task = create(:data_privacy_task, deletable: user)
user.destroy user.destroy
task.perform task.perform
expect(task.reload.state).to eq('failed') expect(task.reload.state).to eq('completed')
end
it 'sets an error message when task failed' do
task = create(:data_privacy_task, deletable: user)
user.destroy
task.perform
expect(task.reload.preferences[:error]).to eq("ERROR: #<ActiveRecord::RecordNotFound: Couldn't find User with 'id'=#{user.id}>")
end end
end end