From 275a97cc4f33e7fe775ff40f34b06ed7aa816885 Mon Sep 17 00:00:00 2001 From: Rolf Schmidt Date: Thu, 15 Oct 2020 08:37:21 +0200 Subject: [PATCH] Fixed issue #3220 - DataPrivacyTask - Can't remove user if still referenced in Overview(s). --- app/models/user.rb | 3 ++- spec/models/user_spec.rb | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 1b49a9d0b..2ee0e3720 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -21,6 +21,7 @@ class User < ApplicationModel include User::SearchIndex has_and_belongs_to_many :organizations, after_add: :cache_update, after_remove: :cache_update, class_name: 'Organization' + has_and_belongs_to_many :overviews, dependent: :nullify has_many :tokens, after_add: :cache_update, after_remove: :cache_update, dependent: :destroy has_many :authorizations, after_add: :cache_update, after_remove: :cache_update, dependent: :destroy has_many :online_notifications, dependent: :destroy @@ -52,7 +53,7 @@ class User < ApplicationModel store :preferences - association_attributes_ignored :online_notifications, :templates, :taskbars, :user_devices, :chat_sessions, :karma_activity_logs, :cti_caller_ids, :text_modules, :customer_tickets, :owner_tickets, :created_recent_views, :chat_agents, :data_privacy_tasks + association_attributes_ignored :online_notifications, :templates, :taskbars, :user_devices, :chat_sessions, :karma_activity_logs, :cti_caller_ids, :text_modules, :customer_tickets, :owner_tickets, :created_recent_views, :chat_agents, :data_privacy_tasks, :overviews activity_stream_permission 'admin.user' diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 57cc81834..c30d2c236 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -870,7 +870,7 @@ RSpec.describe User, type: :model do 'Channel' => { 'created_by_id' => 0, 'updated_by_id' => 0 }, 'Role' => { 'created_by_id' => 0, 'updated_by_id' => 0 }, 'History' => { 'created_by_id' => 1 }, - 'Overview' => { 'created_by_id' => 0, 'updated_by_id' => 0 }, + 'Overview' => { 'created_by_id' => 1, 'updated_by_id' => 0 }, 'ActivityStream' => { 'created_by_id' => 0 }, 'StatsStore' => { 'created_by_id' => 0 }, 'TextModule' => { 'user_id' => 1, 'created_by_id' => 0, 'updated_by_id' => 0 }, @@ -891,6 +891,8 @@ RSpec.describe User, type: :model do authorization = create(:twitter_authorization, user: user) recent_view = create(:recent_view, created_by: user) avatar = create(:avatar, o_id: user.id) + overview = create(:overview, created_by_id: user.id, user_ids: [user.id]) + expect(overview.reload.user_ids).to eq([user.id]) # create a chat agent for admin user (id=1) before agent user # to be sure that the data gets removed and not mapped which @@ -929,6 +931,7 @@ RSpec.describe User, type: :model do expect { customer_ticket2.reload }.to raise_exception(ActiveRecord::RecordNotFound) expect { customer_ticket3.reload }.to raise_exception(ActiveRecord::RecordNotFound) expect { chat_agent_user.reload }.to raise_exception(ActiveRecord::RecordNotFound) + expect(overview.reload.user_ids).to eq([]) # move ownership objects expect { group.reload }.to change(group, :created_by_id).to(1)