Fixes #3610 - Chat-Message references not cleared with data privacy task.
This commit is contained in:
parent
dba3689711
commit
a5c386cbb2
4 changed files with 21 additions and 3 deletions
|
@ -3,5 +3,8 @@
|
|||
class Chat::Message < ApplicationModel
|
||||
include ChecksHtmlSanitized
|
||||
|
||||
belongs_to :chat_session, class_name: 'Chat::Session'
|
||||
belongs_to :created_by, class_name: 'User', optional: true
|
||||
|
||||
sanitized_html :content
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@ class Chat::Session < ApplicationModel
|
|||
include Chat::Session::Assets
|
||||
|
||||
# rubocop:disable Rails/InverseOf
|
||||
has_many :messages, class_name: 'Chat::Message', foreign_key: 'chat_session_id'
|
||||
has_many :messages, class_name: 'Chat::Message', foreign_key: 'chat_session_id', dependent: :destroy
|
||||
belongs_to :user, class_name: 'User', optional: true
|
||||
belongs_to :chat, class_name: 'Chat'
|
||||
# rubocop:enable Rails/InverseOf
|
||||
|
|
9
spec/factories/chat/message.rb
Normal file
9
spec/factories/chat/message.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
||||
|
||||
FactoryBot.define do
|
||||
factory :'chat/message' do
|
||||
chat_session { create(:'chat/session') }
|
||||
content { 'test 1234' }
|
||||
created_by_id { 1 }
|
||||
end
|
||||
end
|
|
@ -879,9 +879,9 @@ RSpec.describe User, type: :model do
|
|||
'Taskbar' => { 'user_id' => 1 },
|
||||
'Sla' => { 'created_by_id' => 0, 'updated_by_id' => 0 },
|
||||
'UserDevice' => { 'user_id' => 1 },
|
||||
'Chat::Message' => { 'created_by_id' => 0 },
|
||||
'Chat::Message' => { 'created_by_id' => 1 },
|
||||
'Chat::Agent' => { 'created_by_id' => 1, 'updated_by_id' => 1 },
|
||||
'Chat::Session' => { 'user_id' => 0, 'created_by_id' => 0, 'updated_by_id' => 0 },
|
||||
'Chat::Session' => { 'user_id' => 1, 'created_by_id' => 0, 'updated_by_id' => 0 },
|
||||
'Tag' => { 'created_by_id' => 0 },
|
||||
'Karma::User' => { 'user_id' => 0 },
|
||||
'Karma::ActivityLog' => { 'user_id' => 1 },
|
||||
|
@ -930,6 +930,9 @@ RSpec.describe User, type: :model do
|
|||
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)
|
||||
chat_session = create(:'chat/session', user: user)
|
||||
chat_message = create(:'chat/message', chat_session: chat_session)
|
||||
chat_message2 = create(:'chat/message', chat_session: chat_session, created_by: user)
|
||||
expect(overview.reload.user_ids).to eq([user.id])
|
||||
|
||||
# create a chat agent for admin user (id=1) before agent user
|
||||
|
@ -970,6 +973,9 @@ RSpec.describe User, type: :model do
|
|||
expect { mention.reload }.to raise_exception(ActiveRecord::RecordNotFound)
|
||||
expect(mention_created_by.reload.created_by_id).not_to eq(user.id)
|
||||
expect(overview.reload.user_ids).to eq([])
|
||||
expect { chat_session.reload }.to raise_exception(ActiveRecord::RecordNotFound)
|
||||
expect { chat_message.reload }.to raise_exception(ActiveRecord::RecordNotFound)
|
||||
expect { chat_message2.reload }.to raise_exception(ActiveRecord::RecordNotFound)
|
||||
|
||||
# move ownership objects
|
||||
expect { group.reload }.to change(group, :created_by_id).to(1)
|
||||
|
|
Loading…
Reference in a new issue