Fixes #2852 - Default Priority on ticket creation not changeable

This commit is contained in:
Mantas Masalskis 2021-10-26 10:08:09 +02:00
parent d0e5614689
commit 9973839e44
4 changed files with 50 additions and 8 deletions

View file

@ -33,6 +33,7 @@ class App.TicketCreate extends App.Controller
# define default type and available types # define default type and available types
@defaultType = @Config.get('ui_ticket_create_default_type') @defaultType = @Config.get('ui_ticket_create_default_type')
@availableTypes = @Config.get('ui_ticket_create_available_types') || [] @availableTypes = @Config.get('ui_ticket_create_available_types') || []
if !_.isArray(@availableTypes) if !_.isArray(@availableTypes)
@availableTypes = [@availableTypes] @availableTypes = [@availableTypes]
@ -295,6 +296,8 @@ class App.TicketCreate extends App.Controller
if !_.isEmpty(params['form_id']) if !_.isEmpty(params['form_id'])
@formId = params['form_id'] @formId = params['form_id']
params.priority_id ||= App.TicketPriority.findByAttribute( 'default_create', true )?.id
@html(App.view('agent_ticket_create')( @html(App.view('agent_ticket_create')(
head: 'New Ticket' head: 'New Ticket'
agent: @permissionCheck('ticket.agent') agent: @permissionCheck('ticket.agent')

View file

@ -119,11 +119,6 @@ class CustomerTicketCreate extends App.ControllerAppContent
# set customer id # set customer id
params.customer_id = @Session.get('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 # set state
if !params.state_id if !params.state_id
state = App.TicketState.findByAttribute( 'default_create', true ) state = App.TicketState.findByAttribute( 'default_create', true )

View file

@ -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: '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: '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: '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: 'article_count', display: 'Article#', readonly: 1, width: '12%' },
{ name: 'time_unit', display: 'Accounted Time', 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' }, { name: 'escalation_at', display: 'Escalation at', tag: 'datetime', null: true, readonly: 1, width: '110px', class: 'escalation' },

View file

@ -683,4 +683,48 @@ RSpec.describe 'Ticket Create', type: :system do
expect(Ticket.last.pending_time).to be nil expect(Ticket.last.pending_time).to be nil
end end
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 end