Follow up 189ccb21db - Fixes #3827 - Remove ticket create screen job because it is not needed anymore dropdown data will get updated on action by core workflow.

This commit is contained in:
Rolf Schmidt 2021-11-03 17:13:13 +01:00
parent 71d6b9e413
commit 52aa34bb20
20 changed files with 23 additions and 553 deletions

View file

@ -49,12 +49,7 @@ class App.TicketCreate extends App.Controller
if @ticket_id && @article_id
@split = "/#{@ticket_id}/#{@article_id}"
load = (data) =>
App.Collection.loadAssets(data.assets)
@formMeta = data.form_meta
@buildScreen(params)
@bindId = App.TicketCreateCollection.bind(load, false)
App.TicketCreateCollection.fetch()
@buildScreen(params)
# rerender view, e. g. on langauge change
@controllerBind('ui:rerender', =>
@ -70,9 +65,6 @@ class App.TicketCreate extends App.Controller
@sidebarWidget.render(@params())
)
release: =>
App.TicketCreateCollection.unbindById(@bindId)
currentChannel: =>
if !type
type = @$('.type-tabs .tab.active').data('type')
@ -280,7 +272,6 @@ class App.TicketCreate extends App.Controller
localeRender = =>
@render(template)
App.QueueManager.add(@queueKey, localeRender)
return if !@formMeta
App.QueueManager.run(@queueKey)
updateTaskManagerAttachments: (attribute, attachments) =>
@ -291,7 +282,7 @@ class App.TicketCreate extends App.Controller
App.TaskManager.update(@taskKey, taskData)
render: (template = {}) ->
return if !@formMeta
# get params
params = @prefilledParams || {}
if template && !_.isEmpty(template.options)
@ -340,8 +331,6 @@ class App.TicketCreate extends App.Controller
model: App.Ticket
screen: 'create_middle'
handlersConfig: handlers
filter: @formMeta.filter
formMeta: @formMeta
params: params
noFieldset: true
taskKey: @taskKey
@ -369,8 +358,6 @@ class App.TicketCreate extends App.Controller
events:
'change [name=customer_id]': @localUserInfo
handlersConfig: handlersTunnel
filter: @formMeta.filter
formMeta: @formMeta
autofocus: true
params: params
taskKey: @taskKey
@ -395,8 +382,6 @@ class App.TicketCreate extends App.Controller
model: App.Ticket
screen: 'create_bottom'
handlersConfig: handlersTunnel
filter: @formMeta.filter
formMeta: @formMeta
params: params
taskKey: @taskKey
)

View file

@ -13,13 +13,7 @@ class CustomerTicketCreate extends App.ControllerAppContent
@form_id = App.ControllerForm.formId()
@navupdate '#customer_ticket_new'
load = (data) =>
App.Collection.loadAssets(data.assets)
@formMeta = data.form_meta
@render()
@bindId = App.TicketCreateCollection.bind(load, false)
App.TicketCreateCollection.fetch()
@render()
render: (template = {}) ->
if !@Config.get('customer_ticket_create')
@ -43,8 +37,6 @@ class CustomerTicketCreate extends App.ControllerAppContent
form_id: @form_id
model: App.Ticket
screen: 'create_middle'
filter: @formMeta.filter
formMeta: @formMeta
params: defaults
noFieldset: true
handlersConfig: handlers
@ -70,8 +62,6 @@ class CustomerTicketCreate extends App.ControllerAppContent
model: App.Ticket
screen: 'create_top'
handlersConfig: handlersTunnel
filter: @formMeta.filter
formMeta: @formMeta
autofocus: true
params: defaults
)
@ -83,8 +73,6 @@ class CustomerTicketCreate extends App.ControllerAppContent
events:
'fileUploadStart .richtext': => @submitDisable()
'fileUploadStop .richtext': => @submitEnable()
filter: @formMeta.filter
formMeta: @formMeta
params: defaults
handlersConfig: handlersTunnel
)
@ -95,8 +83,6 @@ class CustomerTicketCreate extends App.ControllerAppContent
model: App.Ticket
screen: 'create_bottom'
handlersConfig: handlersTunnel
filter: @formMeta.filter
formMeta: @formMeta
params: defaults
)

View file

@ -79,6 +79,12 @@ class App.FormHandlerCoreWorkflow
return if !App.WebSocket.channel()
return !App.Config.get('core_workflow_ajax_mode')
@restrictValuesAttributeCache: (attribute, values) ->
result = { values: values }
return result if !attribute.relation
result.lastUpdatedAt = App[attribute.relation].lastUpdatedAt()
return result
# restricts the dropdown and tree select values of a form
@restrictValues: (classname, form, ui, attributes, params, data) ->
return if _.isEmpty(data.restrict_values)
@ -111,11 +117,11 @@ class App.FormHandlerCoreWorkflow
# cache state for performance and only run
# if values or param differ
if coreWorkflowRestrictions?[classname]?[item.name]
compare = values
compare = App.FormHandlerCoreWorkflow.restrictValuesAttributeCache(attribute, values)
continue if _.isEqual(coreWorkflowRestrictions[classname][item.name], compare)
coreWorkflowRestrictions[classname] ||= {}
coreWorkflowRestrictions[classname][item.name] = values
coreWorkflowRestrictions[classname][item.name] = App.FormHandlerCoreWorkflow.restrictValuesAttributeCache(attribute, values)
valueFound = false
for value in values

View file

@ -1,27 +0,0 @@
class _Singleton extends App._CollectionSingletonBase
event: 'ticket_create_attributes'
restEndpoint: '/ticket_create'
class App.TicketCreateCollection
_instance = new _Singleton
@get: ->
_instance.get()
@one: (callback, init = true) ->
_instance.bind(callback, init, true)
@bind: (callback, init = true) ->
_instance.bind(callback, init, false)
@unbind: (callback) ->
_instance.unbind(callback)
@unbindById: (id) ->
_instance.unbindById(id)
@trigger: ->
_instance.trigger()
@fetch: ->
_instance.fetch()

View file

@ -1,31 +0,0 @@
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
class TicketCreateScreenJob < ApplicationJob
include HasActiveJobLock
def perform
Sessions.list.each do |client_id, data|
next if client_id.blank?
user_id = data&.dig(:user, 'id')
next if user_id.blank?
user = User.lookup(id: user_id)
next if !user&.permissions?('ticket.agent')
# get attributes to update
ticket_create_attributes = Ticket::ScreenOptions.attributes_to_change(
current_user: user,
)
# no data exists
next if ticket_create_attributes.blank?
Rails.logger.debug { "push ticket_create for user #{user.id}" }
Sessions.send(client_id, {
event: 'ticket_create_attributes',
data: ticket_create_attributes,
})
end
end
end

View file

@ -251,7 +251,6 @@ module HasGroups
yield
self.group_access_buffer = nil
cache_delete
push_ticket_create_screen_background_job
end
def process_group_access_buffer

View file

@ -6,9 +6,9 @@ module HasRoles
included do
has_and_belongs_to_many :roles,
before_add: %i[validate_agent_limit_by_role validate_roles],
after_add: %i[cache_update check_notifications push_ticket_create_screen_for_role_change],
after_add: %i[cache_update check_notifications],
before_remove: :last_admin_check_by_role,
after_remove: %i[cache_update push_ticket_create_screen_for_role_change]
after_remove: %i[cache_update]
end
# Checks a given Group( ID) for given access(es) for the instance associated roles.
@ -45,15 +45,6 @@ module HasRoles
)
end
def push_ticket_create_screen_for_role_change(role)
return if Setting.get('import_mode')
permission = Permission.lookup(name: 'ticket.agent')
return if !role.permissions.exists?(id: permission.id)
push_ticket_create_screen_background_job
end
# methods defined here are going to extend the class, not the instance of it
class_methods do

View file

@ -1,28 +0,0 @@
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
module HasTicketCreateScreenImpact
extend ActiveSupport::Concern
included do
after_commit :push_ticket_create_screen
end
def push_ticket_create_screen?
return true if destroyed?
%w[id name active updated_at].any? do |attribute|
saved_change_to_attribute?(attribute)
end
end
def push_ticket_create_screen
return if Setting.get('import_mode')
return if !push_ticket_create_screen?
push_ticket_create_screen_background_job
end
def push_ticket_create_screen_background_job
TicketCreateScreenJob.set(wait: 10.seconds).perform_later
end
end

View file

@ -9,7 +9,6 @@ class Group < ApplicationModel
include HasHistory
include HasObjectManagerAttributes
include HasCollectionUpdate
include HasTicketCreateScreenImpact
include HasSearchIndexBackend
include Group::Assets

View file

@ -8,7 +8,6 @@ class Role < ApplicationModel
include ChecksLatestChangeObserved
include HasGroups
include HasCollectionUpdate
include HasTicketCreateScreenImpact
include Role::Assets

View file

@ -12,9 +12,7 @@ class User < ApplicationModel
include HasGroups
include HasRoles
include HasObjectManagerAttributes
include ::HasTicketCreateScreenImpact
include HasTaskbars
include User::HasTicketCreateScreenImpact
include User::Assets
include User::Avatar
include User::Search

View file

@ -1,14 +0,0 @@
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
module User::HasTicketCreateScreenImpact
extend ActiveSupport::Concern
def push_ticket_create_screen?
return true if destroyed?
return false if %w[id login firstname lastname preferences active].none? do |attribute|
saved_change_to_attribute?(attribute)
end
permissions?('ticket.agent')
end
end

View file

@ -1,184 +0,0 @@
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
require 'rails_helper'
RSpec.describe HasTicketCreateScreenImpact, type: :job do
context 'with groups' do
let!(:group) { create(:group) }
it 'create should enqueue no job' do
collection_jobs = enqueued_jobs.select do |job|
job[:job] == TicketCreateScreenJob
end
expect(collection_jobs.count).to be(1)
end
context 'updating attribute' do
before do
clear_jobs
end
context 'name' do
it 'enqueues a job' do
expect { group.update!(name: 'new name') }.to have_enqueued_job(TicketCreateScreenJob)
end
end
context 'active' do
it 'enqueues a job' do
expect { group.update!(active: false) }.to have_enqueued_job(TicketCreateScreenJob)
end
end
context 'updated_at' do
it 'enqueues a job' do
expect { group.touch }.to have_enqueued_job(TicketCreateScreenJob)
end
end
end
it 'delete should enqueue no job' do
clear_jobs
expect { group.destroy! }.to have_enqueued_job(TicketCreateScreenJob)
end
end
context 'with roles' do
let!(:role) { create(:role) }
it 'create should enqueue no job' do
collection_jobs = enqueued_jobs.select do |job|
job[:job] == TicketCreateScreenJob
end
expect(collection_jobs.count).to be(1)
end
context 'updating attribute' do
before do
clear_jobs
end
context 'name' do
it 'enqueues a job' do
expect { role.update!(name: 'new name') }.to have_enqueued_job(TicketCreateScreenJob)
end
end
context 'active' do
it 'enqueues a job' do
expect { role.update!(active: false) }.to have_enqueued_job(TicketCreateScreenJob)
end
end
context 'updated_at' do
it 'enqueues no job' do
expect { role.touch }.to have_enqueued_job(TicketCreateScreenJob)
end
end
end
it 'delete should enqueue no job' do
clear_jobs
expect { role.destroy! }.to have_enqueued_job(TicketCreateScreenJob)
end
end
context 'with users' do
let!(:customer) { create(:user, roles: Role.where(name: 'Customer')) }
let!(:agent) { create(:user, roles: Role.where(name: 'Agent')) }
let!(:admin) { create(:user, roles: Role.where(name: 'Admin')) }
let(:customer_new) { create(:user, roles: Role.where(name: 'Customer')) }
let(:agent_new) { create(:user, roles: Role.where(name: 'Agent')) }
let(:admin_new) { create(:user, roles: Role.where(name: 'Admin')) }
context 'creating' do
before do
clear_jobs
end
it 'customer should enqueue no job' do
customer_new
collection_jobs = enqueued_jobs.select do |job|
job[:job] == TicketCreateScreenJob
end
expect(collection_jobs.count).to be(0)
end
it 'agent should enqueue a job' do
agent_new
collection_jobs = enqueued_jobs.select do |job|
job[:job] == TicketCreateScreenJob
end
expect(collection_jobs.count).to be(1)
end
it 'admin should enqueue no job' do
admin_new
collection_jobs = enqueued_jobs.select do |job|
job[:job] == TicketCreateScreenJob
end
expect(collection_jobs.count).to be(0)
end
end
context 'updating attribute' do
before do
clear_jobs
end
context 'firstname field for' do
it 'customer should enqueue no job' do
expect { customer.update!(firstname: 'new firstname') }.not_to have_enqueued_job(TicketCreateScreenJob)
end
it 'agent should enqueue a job' do
expect { agent.update!(firstname: 'new firstname') }.to have_enqueued_job(TicketCreateScreenJob)
end
it 'admin should enqueue no job' do
expect { admin.update!(firstname: 'new firstname') }.not_to have_enqueued_job(TicketCreateScreenJob)
end
end
context 'active field for' do
it 'customer should enqueue no job' do
expect { customer.update!(active: false) }.not_to have_enqueued_job(TicketCreateScreenJob)
end
it 'agent should enqueue a job' do
expect { agent.update!(active: false) }.to have_enqueued_job(TicketCreateScreenJob)
end
it 'admin should enqueue no job' do
admin_new # Prevend "Minimum one user needs to have admin permissions."
clear_jobs
expect { admin.update!(active: false) }.not_to have_enqueued_job(TicketCreateScreenJob)
end
end
end
context 'deleting' do
before do
clear_jobs
end
it 'customer should enqueue a job' do
expect { customer.destroy! }.to have_enqueued_job(TicketCreateScreenJob)
end
it 'agent should enqueue a job' do
expect { agent.destroy! }.to have_enqueued_job(TicketCreateScreenJob)
end
it 'admin should enqueue a job' do
expect { admin.destroy! }.to have_enqueued_job(TicketCreateScreenJob)
end
end
end
end

View file

@ -1,46 +0,0 @@
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
RSpec.shared_examples 'HasTicketCreateScreenImpact' do |create_screen_factory:|
describe '#push_ticket_create_screen', performs_jobs: true do
subject { create(create_screen_factory) }
context 'creating a record' do
it 'enqueues a TicketCreateScreenJob job' do
expect { subject }.to have_enqueued_job(TicketCreateScreenJob)
end
end
context 'record exists' do
before do
subject
clear_jobs
end
context 'attribute updated' do
context 'name' do
it 'enqueues a TicketCreateScreenJob job' do
expect do
subject.name = 'New name'
subject.save!
end.to have_enqueued_job(TicketCreateScreenJob)
end
end
context 'updated_at' do
it 'enqueues a TicketCreateScreenJob job' do
expect { subject.touch }.to have_enqueued_job(TicketCreateScreenJob)
end
end
end
context 'record is deleted' do
it 'enqueues a TicketCreateScreenJob job' do
expect { subject.destroy! }.to have_enqueued_job(TicketCreateScreenJob)
end
end
end
end
end

View file

@ -5,7 +5,6 @@ require 'models/application_model_examples'
require 'models/concerns/can_be_imported_examples'
require 'models/concerns/has_object_manager_attributes_examples'
require 'models/concerns/has_collection_update_examples'
require 'models/concerns/has_ticket_create_screen_impact_examples'
require 'models/concerns/has_xss_sanitized_note_examples'
RSpec.describe Group, type: :model do
@ -15,6 +14,5 @@ RSpec.describe Group, type: :model do
it_behaves_like 'CanBeImported'
it_behaves_like 'HasObjectManagerAttributes'
it_behaves_like 'HasCollectionUpdate', collection_factory: :group
it_behaves_like 'HasTicketCreateScreenImpact', create_screen_factory: :group
it_behaves_like 'HasXssSanitizedNote', model_factory: :group
end

View file

@ -5,7 +5,6 @@ require 'models/application_model_examples'
require 'models/concerns/can_be_imported_examples'
require 'models/concerns/has_groups_examples'
require 'models/concerns/has_collection_update_examples'
require 'models/concerns/has_ticket_create_screen_impact_examples'
require 'models/concerns/has_xss_sanitized_note_examples'
RSpec.describe Role do
@ -15,7 +14,6 @@ RSpec.describe Role do
it_behaves_like 'CanBeImported'
it_behaves_like 'HasGroups', group_access_factory: :role
it_behaves_like 'HasCollectionUpdate', collection_factory: :role
it_behaves_like 'HasTicketCreateScreenImpact', create_screen_factory: :role
it_behaves_like 'HasXssSanitizedNote', model_factory: :role
describe 'Default state' do

View file

@ -1,163 +0,0 @@
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
RSpec.shared_examples 'User::HasTicketCreateScreenImpact' do
describe '#push_ticket_create_screen', performs_jobs: true do
shared_examples 'relevant User Role' do |role|
context "relevant User Role is '#{role}'" do
subject { create(:user, roles: Role.where(name: role)) }
context 'creating a record' do
it 'enqueues TicketCreateScreenJob' do
expect { subject }.to have_enqueued_job(TicketCreateScreenJob)
end
end
context 'record exists' do
before do
subject
clear_jobs
end
context 'attribute updated' do
it 'enqueues TicketCreateScreenJob' do
expect { subject.update!(firstname: 'new firstname') }.to have_enqueued_job(TicketCreateScreenJob)
end
context 'permission association changes' do
context 'Group' do
let!(:group) { create(:group) }
before { clear_jobs }
it 'enqueues TicketCreateScreenJob' do
expect do
subject.group_names_access_map = {
group.name => ['full'],
}
end.to have_enqueued_job(TicketCreateScreenJob)
end
end
context 'Role' do
context 'to relevant' do
let!(:roles) { create_list(:agent_role, 1) }
before { clear_jobs }
it 'enqueues TicketCreateScreenJob' do
expect { subject.update!(roles: roles) }.to have_enqueued_job(TicketCreateScreenJob)
end
end
context 'to irrelevant' do
let!(:roles) { create_list(:role, 3) }
before { clear_jobs }
it 'enqueues TicketCreateScreenJob' do
expect { subject.update!(roles: roles) }.to have_enqueued_job(TicketCreateScreenJob)
end
end
end
end
end
context 'record is deleted' do
it 'enqueues TicketCreateScreenJob' do
expect { subject.destroy! }.to have_enqueued_job(TicketCreateScreenJob)
end
end
end
end
end
shared_examples 'irrelevant User Role' do |role|
context "irrelevant User Role is '#{role}'" do
subject { create(:user, roles: Role.where(name: role)) }
context 'creating a record' do
it 'does not enqueue TicketCreateScreenJob job' do
expect { subject }.not_to have_enqueued_job(TicketCreateScreenJob)
end
end
context 'record exists' do
before do
subject
clear_jobs
end
context 'attribute updated' do
it 'enqueues no TicketCreateScreenJob job' do
expect { subject.update!(firstname: 'new firstname') }.not_to have_enqueued_job(TicketCreateScreenJob)
end
context 'permission association changes', last_admin_check: false do
context 'Group' do
let!(:group) { create(:group) }
before { clear_jobs }
it 'enqueues TicketCreateScreenJob' do
expect do
subject.group_names_access_map = {
group.name => ['full'],
}
end.to have_enqueued_job(TicketCreateScreenJob)
end
end
context 'Role' do
context 'to relevant' do
let!(:roles) { create_list(:agent_role, 3) }
before { clear_jobs }
it 'enqueues TicketCreateScreenJob' do
expect { subject.update!(roles: roles) }.to have_enqueued_job(TicketCreateScreenJob)
end
end
context 'to irrelevant' do
let!(:roles) { create_list(:role, 3) }
before { clear_jobs }
it 'does not enqueue TicketCreateScreenJob' do
expect { subject.update!(roles: roles) }.not_to have_enqueued_job(TicketCreateScreenJob)
end
end
end
end
end
context 'record is deleted' do
it 'enqueues TicketCreateScreenJob job' do
expect { subject.destroy! }.to have_enqueued_job(TicketCreateScreenJob)
end
end
end
end
end
include_examples 'relevant User Role', 'Agent'
include_examples 'irrelevant User Role', 'Customer'
include_examples 'irrelevant User Role', 'Admin'
end
end

View file

@ -10,7 +10,6 @@ require 'models/concerns/has_xss_sanitized_note_examples'
require 'models/concerns/can_be_imported_examples'
require 'models/concerns/has_object_manager_attributes_examples'
require 'models/user/can_lookup_search_index_attributes_examples'
require 'models/user/has_ticket_create_screen_impact_examples'
require 'models/user/performs_geo_lookup_examples'
require 'models/concerns/has_taskbars_examples'
@ -29,7 +28,6 @@ RSpec.describe User, type: :model do
it_behaves_like 'HasGroups and Permissions', group_access_no_permission_factory: :user
it_behaves_like 'CanBeImported'
it_behaves_like 'HasObjectManagerAttributes'
it_behaves_like 'User::HasTicketCreateScreenImpact'
it_behaves_like 'CanLookupSearchIndexAttributes'
it_behaves_like 'HasTaskbars'
it_behaves_like 'UserPerformsGeoLookup'

View file

@ -90,7 +90,7 @@ module BrowserTestHelper
end
wait(5, interval: 0.1).until_constant do
page.evaluate_script('App.Ajax.queue().length').zero?
page.evaluate_script('App.Ajax.queue().length').zero? && page.evaluate_script('Object.keys(App.FormHandlerCoreWorkflow.getRequests()).length').zero?
end
rescue
nil

View file

@ -684,12 +684,18 @@ RSpec.describe 'Ticket Create', type: :system do
end
end
context 'default priority' do
let!(:template) { create(:template, :dummy_data) }
let!(:ticket_priority) { create(:ticket_priority, default_create: true) }
context 'default priority', authenticated_as: :authenticate do
let(:template) { create(:template, :dummy_data) }
let(:ticket_priority) { create(:ticket_priority, default_create: true) }
let(:another_priority) { Ticket::Priority.find(1) }
let(:priority_field) { find('[name=priority_id]') }
def authenticate
template
ticket_priority
true
end
it 'shows default priority on load' do
visit 'ticket/create'