Fixes #3983 - Draft Sharing: Add history entry for updating and deleting of a draft.

This commit is contained in:
Rolf Schmidt 2022-03-02 13:55:30 +01:00
parent 0fcbb11684
commit 6e42aeb1ee
12 changed files with 71 additions and 14 deletions

View file

@ -54,7 +54,9 @@ and check if there are reset_column_information function calls existing for the
end
def reset_class(node)
node.children[0].children[1].to_s
# simplify namespaced class names
# Rubocop can't reliably convert table names to namespaced class names
node.children[0].const_name.gsub '::', ''
end
def table_class(node)

View file

@ -44,6 +44,8 @@ class App.GenericHistory extends App.ControllerModal
if item.object is 'Ticket::Article'
item.object = 'Article'
if item.object is 'Ticket::SharedDraftZoom'
item.object = 'Draft'
data = item
data.created_by = App.User.find( item.created_by_id )

View file

@ -71,7 +71,7 @@ class Ticket < ApplicationModel
:article_count,
:preferences
history_relation_object 'Ticket::Article', 'Mention'
history_relation_object 'Ticket::Article', 'Mention', 'Ticket::SharedDraftZoom'
sanitized_html :note

View file

@ -5,6 +5,8 @@ class Ticket::SharedDraftStart < ApplicationModel
include ChecksClientNotification
belongs_to :group
belongs_to :created_by, class_name: 'User'
belongs_to :updated_by, class_name: 'User'
validates :name, presence: true

View file

@ -3,14 +3,31 @@
class Ticket::SharedDraftZoom < ApplicationModel
include CanCloneAttachments
include ChecksClientNotification
include HasHistory
belongs_to :ticket, touch: true
belongs_to :created_by, class_name: 'User'
belongs_to :updated_by, class_name: 'User'
store :new_article
store :ticket_attributes
history_attributes_ignored :new_article,
:ticket_attributes
# required by CanCloneAttachments
def content_type
'text/html'
end
def history_log_attributes
{
related_o_id: self['ticket_id'],
related_history_object: 'Ticket',
}
end
def history_destroy
history_log('removed', created_by_id)
end
end

View file

@ -593,10 +593,8 @@ class CreateTicket < ActiveRecord::Migration[4.2]
t.references :ticket, null: false, foreign_key: { to_table: :tickets }
t.text :new_article
t.text :ticket_attributes
t.column :created_by_id, :integer, null: true
t.column :updated_by_id, :integer, null: true
t.column :created_by_id, :integer, null: false
t.column :updated_by_id, :integer, null: false
t.timestamps limit: 3
end
@ -604,10 +602,8 @@ class CreateTicket < ActiveRecord::Migration[4.2]
t.references :group, null: false, foreign_key: { to_table: :groups }
t.string :name
t.text :content
t.column :created_by_id, :integer, null: true
t.column :updated_by_id, :integer, null: true
t.column :created_by_id, :integer, null: false
t.column :updated_by_id, :integer, null: false
t.timestamps limit: 3
end
end

View file

@ -0,0 +1,16 @@
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
class FixDraftUserRequired < ActiveRecord::Migration[6.0]
def change
# return if it's a new setup
return if !Setting.exists?(name: 'system_init_done')
change_column :ticket_shared_draft_zooms, :created_by_id, :integer, null: false
change_column :ticket_shared_draft_zooms, :updated_by_id, :integer, null: false
change_column :ticket_shared_draft_starts, :created_by_id, :integer, null: false
change_column :ticket_shared_draft_starts, :updated_by_id, :integer, null: false
Ticket::SharedDraftStart.reset_column_information
Ticket::SharedDraftZoom.reset_column_information
end
end

View file

@ -5,5 +5,7 @@ FactoryBot.define do
name { Faker::Name.unique.name }
group { create(:group) }
content { { content: true } }
updated_by_id { 1 }
created_by_id { 1 }
end
end

View file

@ -5,5 +5,7 @@ FactoryBot.define do
ticket { create(:ticket) }
new_article { { new_article: true } }
ticket_attributes { { ticket_attributes: true } }
updated_by_id { 1 }
created_by_id { 1 }
end
end

View file

@ -8,4 +8,18 @@ RSpec.describe Ticket::SharedDraftZoom, type: :model do
it { is_expected.to belong_to :ticket }
it { expect(shared_draft_zoom.new_article).to be_a(Hash) }
it { expect(shared_draft_zoom.ticket_attributes).to be_a(Hash) }
describe 'Draft Sharing: Add history entry for updating and deleting of a draft #3983' do
it 'does create a history entry for the new draft' do
expect(shared_draft_zoom.ticket.history_get)
.to include(include('object' => 'Ticket::SharedDraftZoom', 'type' => 'created'))
end
it 'does add a history entry for removing the draft' do
shared_draft_zoom.destroy
expect(shared_draft_zoom.ticket.history_get)
.to include(include('object' => 'Ticket::SharedDraftZoom', 'type' => 'removed'))
end
end
end

View file

@ -26,7 +26,7 @@ RSpec.describe Ticket, type: :model do
it_behaves_like 'CanBeImported'
it_behaves_like 'CanCsvImport'
it_behaves_like 'ChecksCoreWorkflow'
it_behaves_like 'HasHistory', history_relation_object: ['Ticket::Article', 'Mention']
it_behaves_like 'HasHistory', history_relation_object: ['Ticket::Article', 'Mention', 'Ticket::SharedDraftZoom']
it_behaves_like 'HasTags'
it_behaves_like 'TagWritesToTicketHistory'
it_behaves_like 'HasTaskbars'

View file

@ -961,8 +961,8 @@ RSpec.describe User, type: :model do
'Ticket::Article::Type' => { 'created_by_id' => 0, 'updated_by_id' => 0 },
'Ticket::Article::Flag' => { 'created_by_id' => 0 },
'Ticket::Priority' => { 'created_by_id' => 0, 'updated_by_id' => 0 },
'Ticket::SharedDraftStart' => { 'created_by_id' => 0, 'updated_by_id' => 0 },
'Ticket::SharedDraftZoom' => { 'created_by_id' => 0, 'updated_by_id' => 0 },
'Ticket::SharedDraftStart' => { 'created_by_id' => 1, 'updated_by_id' => 0 },
'Ticket::SharedDraftZoom' => { 'created_by_id' => 1, 'updated_by_id' => 0 },
'Ticket::TimeAccounting' => { 'created_by_id' => 0 },
'Ticket::State' => { 'created_by_id' => 0, 'updated_by_id' => 0 },
'Ticket::Flag' => { 'created_by_id' => 0 },
@ -1006,7 +1006,7 @@ RSpec.describe User, type: :model do
'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' => 4 },
'History' => { 'created_by_id' => 5 },
'Webhook' => { 'created_by_id' => 0, 'updated_by_id' => 0 },
'Overview' => { 'created_by_id' => 1, 'updated_by_id' => 0 },
'ActivityStream' => { 'created_by_id' => 0 },
@ -1034,6 +1034,8 @@ RSpec.describe User, type: :model do
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)
draft_start = create(:ticket_shared_draft_start, created_by: user)
draft_zoom = create(:ticket_shared_draft_zoom, created_by: user)
expect(overview.reload.user_ids).to eq([user.id])
# create a chat agent for admin user (id=1) before agent user
@ -1094,6 +1096,8 @@ RSpec.describe User, type: :model do
.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)
expect { draft_start.reload }.to change(draft_start, :created_by_id).to(1)
expect { draft_zoom.reload }.to change(draft_zoom, :created_by_id).to(1)
end
it 'does delete cache after user deletion' do