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)