Fixed issue #3220 - DataPrivacyTask - Can't remove user if still referenced in Overview(s).

This commit is contained in:
Rolf Schmidt 2020-10-15 08:37:21 +02:00 committed by Martin Edenhofer
parent 87d55bdfed
commit 275a97cc4f
2 changed files with 6 additions and 2 deletions

View file

@ -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'

View file

@ -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)