From 9973839e44c8527f391c2c0683ec21c686479cd8 Mon Sep 17 00:00:00 2001 From: Mantas Masalskis Date: Tue, 26 Oct 2021 10:08:09 +0200 Subject: [PATCH] Fixes #2852 - Default Priority on ticket creation not changeable --- .../controllers/agent_ticket_create.coffee | 7 ++- .../controllers/customer_ticket_create.coffee | 5 --- .../javascripts/app/models/ticket.coffee | 2 +- spec/system/ticket/create_spec.rb | 44 +++++++++++++++++++ 4 files changed, 50 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/app/controllers/agent_ticket_create.coffee b/app/assets/javascripts/app/controllers/agent_ticket_create.coffee index 954aa8859..bd17a3122 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_create.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_create.coffee @@ -31,8 +31,9 @@ class App.TicketCreate extends App.Controller @sidebarState = {} # define default type and available types - @defaultType = @Config.get('ui_ticket_create_default_type') - @availableTypes = @Config.get('ui_ticket_create_available_types') || [] + @defaultType = @Config.get('ui_ticket_create_default_type') + @availableTypes = @Config.get('ui_ticket_create_available_types') || [] + if !_.isArray(@availableTypes) @availableTypes = [@availableTypes] @@ -295,6 +296,8 @@ class App.TicketCreate extends App.Controller if !_.isEmpty(params['form_id']) @formId = params['form_id'] + params.priority_id ||= App.TicketPriority.findByAttribute( 'default_create', true )?.id + @html(App.view('agent_ticket_create')( head: 'New Ticket' agent: @permissionCheck('ticket.agent') diff --git a/app/assets/javascripts/app/controllers/customer_ticket_create.coffee b/app/assets/javascripts/app/controllers/customer_ticket_create.coffee index c09dfdc8e..a3445ef18 100644 --- a/app/assets/javascripts/app/controllers/customer_ticket_create.coffee +++ b/app/assets/javascripts/app/controllers/customer_ticket_create.coffee @@ -119,11 +119,6 @@ class CustomerTicketCreate extends App.ControllerAppContent # set customer id params.customer_id = @Session.get('id') - # set prio - if !params.priority_id - priority = App.TicketPriority.findByAttribute( 'default_create', true ) - params.priority_id = priority.id - # set state if !params.state_id state = App.TicketState.findByAttribute( 'default_create', true ) diff --git a/app/assets/javascripts/app/models/ticket.coffee b/app/assets/javascripts/app/models/ticket.coffee index 0880e3552..267652178 100644 --- a/app/assets/javascripts/app/models/ticket.coffee +++ b/app/assets/javascripts/app/models/ticket.coffee @@ -11,7 +11,7 @@ class App.Ticket extends App.Model { name: 'owner_id', display: 'Owner', tag: 'select', multiple: false, limit: 100, null: true, relation: 'User', width: '12%', edit: true }, { name: 'state_id', display: 'State', tag: 'select', multiple: false, null: false, relation: 'TicketState', default: 'new', width: '12%', edit: true, customer: true }, { name: 'pending_time', display: 'Pending till', tag: 'datetime', null: true, width: '130px' }, - { name: 'priority_id', display: 'Priority', tag: 'select', multiple: false, null: false, relation: 'TicketPriority', default: '2 normal', width: '54px', edit: true, customer: true }, + { name: 'priority_id', display: 'Priority', tag: 'select', multiple: false, null: false, relation: 'TicketPriority', width: '54px', edit: true, customer: true }, { name: 'article_count', display: 'Article#', readonly: 1, width: '12%' }, { name: 'time_unit', display: 'Accounted Time', readonly: 1, width: '12%' }, { name: 'escalation_at', display: 'Escalation at', tag: 'datetime', null: true, readonly: 1, width: '110px', class: 'escalation' }, diff --git a/spec/system/ticket/create_spec.rb b/spec/system/ticket/create_spec.rb index 5bc6a7de5..d7a49121f 100644 --- a/spec/system/ticket/create_spec.rb +++ b/spec/system/ticket/create_spec.rb @@ -683,4 +683,48 @@ RSpec.describe 'Ticket Create', type: :system do expect(Ticket.last.pending_time).to be nil end end + + context 'default priority' 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]') } + + it 'shows default priority on load' do + visit 'ticket/create' + + expect(priority_field.value).to eq ticket_priority.id.to_s + end + + it 'does not reset to default priority on reload' do + visit 'ticket/create' + + taskbar_timestamp = Taskbar.last.updated_at + + priority_field.select another_priority.name + + wait.until { Taskbar.last.updated_at != taskbar_timestamp } + + refresh + + expect(priority_field.reload.value).to eq another_priority.id.to_s + end + + it 'saves default priority' do + visit 'ticket/create' + use_template template + click '.js-submit' + + expect(Ticket.last).to have_attributes(priority: ticket_priority) + end + + it 'saves different priority if overriden' do + visit 'ticket/create' + use_template template + priority_field.select another_priority.name + click '.js-submit' + + expect(Ticket.last).to have_attributes(priority: another_priority) + end + end end