From 649dff172eda2eb6c9af8b529caacc5d4b68aa7b Mon Sep 17 00:00:00 2001 From: Rolf Schmidt Date: Wed, 2 Jun 2021 11:25:12 +0100 Subject: [PATCH] Fixes #3585 - DataPrivacy may fail to clear user relations. --- app/models/user.rb | 2 +- lib/models.rb | 1 + spec/models/user_spec.rb | 9 +++++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 3b282bae6..dbf0063f2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1176,7 +1176,7 @@ raise 'Minimum one user need to have admin permissions' def destroy_move_dependency_ownership result = Models.references(self.class.to_s, id) - user_columns = %w[created_by_id updated_by_id origin_by_id owner_id archived_by_id published_by_id internal_by_id] + user_columns = %w[created_by_id updated_by_id out_of_office_replacement_id origin_by_id owner_id archived_by_id published_by_id internal_by_id] result.each do |class_name, references| next if class_name.blank? next if references.blank? diff --git a/lib/models.rb b/lib/models.rb index 43fd02c6a..cd910930a 100644 --- a/lib/models.rb +++ b/lib/models.rb @@ -133,6 +133,7 @@ returns if object_name == 'User' ref_attributes.push 'created_by_id' ref_attributes.push 'updated_by_id' + ref_attributes.push 'out_of_office_replacement_id' end list.each do |model_class, model_attributes| if !references[model_class.to_s] diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 1560c4b8a..e5622f833 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -868,13 +868,13 @@ RSpec.describe User, type: :model do 'Trigger' => { 'created_by_id' => 0, 'updated_by_id' => 0 }, 'Translation' => { 'created_by_id' => 0, 'updated_by_id' => 0 }, 'ObjectManager::Attribute' => { 'created_by_id' => 0, 'updated_by_id' => 0 }, - 'User' => { 'created_by_id' => 0, 'updated_by_id' => 0 }, + 'User' => { 'created_by_id' => 1, 'out_of_office_replacement_id' => 1, 'updated_by_id' => 1 }, 'Organization' => { 'created_by_id' => 0, 'updated_by_id' => 0 }, 'Macro' => { 'created_by_id' => 0, 'updated_by_id' => 0 }, 'Mention' => { 'created_by_id' => 1, 'updated_by_id' => 0, 'user_id' => 1 }, 'Channel' => { 'created_by_id' => 0, 'updated_by_id' => 0 }, 'Role' => { 'created_by_id' => 0, 'updated_by_id' => 0 }, - 'History' => { 'created_by_id' => 3 }, + 'History' => { 'created_by_id' => 4 }, 'Webhook' => { 'created_by_id' => 0, 'updated_by_id' => 0 }, 'Overview' => { 'created_by_id' => 1, 'updated_by_id' => 0 }, 'ActivityStream' => { 'created_by_id' => 0 }, @@ -898,6 +898,7 @@ RSpec.describe User, type: :model do overview = create(:overview, created_by_id: user.id, user_ids: [user.id]) mention = create(:mention, mentionable: create(:ticket), user: user) mention_created_by = create(:mention, mentionable: create(:ticket), user: create(:agent), created_by: user) + user_created_by = create(:customer, created_by_id: user.id, updated_by_id: user.id, out_of_office_replacement_id: user.id) expect(overview.reload.user_ids).to eq([user.id]) # create a chat agent for admin user (id=1) before agent user @@ -951,6 +952,10 @@ RSpec.describe User, type: :model do .to change(knowledge_base_answer, :archived_by_id).to(1) .and change(knowledge_base_answer, :published_by_id).to(1) .and change(knowledge_base_answer, :internal_by_id).to(1) + expect { user_created_by.reload } + .to change(user_created_by, :created_by_id).to(1) + .and change(user_created_by, :updated_by_id).to(1) + .and change(user_created_by, :out_of_office_replacement_id).to(1) end it 'does delete cache after user deletion' do