Fixed #2424 - Unavailable ticket template attributes get applied
This commit is contained in:
parent
a159eaf882
commit
74ec8912bd
7 changed files with 125 additions and 16 deletions
|
@ -119,7 +119,7 @@ class App.UiElement.ApplicationUiElement
|
||||||
list.push record
|
list.push record
|
||||||
|
|
||||||
# check if current value need to be added
|
# check if current value need to be added
|
||||||
if params[ attribute.name ]
|
if params[ attribute.name ] && !attribute.rejectNonExistentValues
|
||||||
hit = false
|
hit = false
|
||||||
for value in list
|
for value in list
|
||||||
if value['id'].toString() is params[ attribute.name ].toString()
|
if value['id'].toString() is params[ attribute.name ].toString()
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# coffeelint: disable=camel_case_classes
|
# coffeelint: disable=camel_case_classes
|
||||||
class App.UiElement.select extends App.UiElement.ApplicationUiElement
|
class App.UiElement.select extends App.UiElement.ApplicationUiElement
|
||||||
@render: (attribute, params) ->
|
@render: (attribute, params, form = {}) ->
|
||||||
|
|
||||||
# set multiple option
|
# set multiple option
|
||||||
if attribute.multiple
|
if attribute.multiple
|
||||||
|
@ -8,6 +8,9 @@ class App.UiElement.select extends App.UiElement.ApplicationUiElement
|
||||||
else
|
else
|
||||||
attribute.multiple = ''
|
attribute.multiple = ''
|
||||||
|
|
||||||
|
if form.rejectNonExistentValues
|
||||||
|
attribute.rejectNonExistentValues = true
|
||||||
|
|
||||||
# add deleted historical options if required
|
# add deleted historical options if required
|
||||||
@addDeletedOptions(attribute, params)
|
@addDeletedOptions(attribute, params)
|
||||||
|
|
||||||
|
@ -39,6 +42,7 @@ class App.UiElement.select extends App.UiElement.ApplicationUiElement
|
||||||
# 2. If attribute.value is not among current and historical options, then add the value itself as an option
|
# 2. If attribute.value is not among current and historical options, then add the value itself as an option
|
||||||
@addDeletedOptions: (attribute) ->
|
@addDeletedOptions: (attribute) ->
|
||||||
return if !_.isEmpty(attribute.relation) # do not apply for attributes with relation, relations will fill options automatically
|
return if !_.isEmpty(attribute.relation) # do not apply for attributes with relation, relations will fill options automatically
|
||||||
|
return if attribute.rejectNonExistentValues
|
||||||
value = attribute.value
|
value = attribute.value
|
||||||
return if !value
|
return if !value
|
||||||
return if _.isArray(value)
|
return if _.isArray(value)
|
||||||
|
|
|
@ -329,6 +329,7 @@ class App.TicketCreate extends App.Controller
|
||||||
params: params
|
params: params
|
||||||
noFieldset: true
|
noFieldset: true
|
||||||
taskKey: @taskKey
|
taskKey: @taskKey
|
||||||
|
rejectNonExistentValues: true
|
||||||
)
|
)
|
||||||
new App.ControllerForm(
|
new App.ControllerForm(
|
||||||
el: @$('.ticket-form-bottom')
|
el: @$('.ticket-form-bottom')
|
||||||
|
|
|
@ -78,6 +78,7 @@ class Index extends App.ControllerContent
|
||||||
params: defaults
|
params: defaults
|
||||||
noFieldset: true
|
noFieldset: true
|
||||||
handlersConfig: handlers
|
handlersConfig: handlers
|
||||||
|
rejectNonExistentValues: true
|
||||||
)
|
)
|
||||||
if !_.isEmpty(App.Ticket.attributesGet('create_bottom', false, true))
|
if !_.isEmpty(App.Ticket.attributesGet('create_bottom', false, true))
|
||||||
new App.ControllerForm(
|
new App.ControllerForm(
|
||||||
|
|
|
@ -1339,6 +1339,70 @@ test("object manager form 3", function() {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("check if select value is not existing but is shown", function() {
|
||||||
|
|
||||||
|
$('#forms').append('<hr><h1>check if select value is not existing but is shown</h1><form id="form17"></form>')
|
||||||
|
var el = $('#form17')
|
||||||
|
var defaults = {
|
||||||
|
select1: 'NOT EXISTING',
|
||||||
|
}
|
||||||
|
new App.ControllerForm({
|
||||||
|
el: el,
|
||||||
|
model: {
|
||||||
|
configure_attributes: [
|
||||||
|
{ name: 'select1', display: 'Select1', tag: 'select', null: true, default: 'XY', options: { 'XX': 'AA', 'A': 'XX', 'B': 'B', 'XY': 'b', '': 'äöü' } },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
params: defaults,
|
||||||
|
});
|
||||||
|
|
||||||
|
params = App.ControllerForm.params(el)
|
||||||
|
test_params = {
|
||||||
|
select1: 'NOT EXISTING',
|
||||||
|
}
|
||||||
|
deepEqual(params, test_params)
|
||||||
|
|
||||||
|
equal('AA', el.find('[name=select1] option')[0].text)
|
||||||
|
equal('äöü', el.find('[name=select1] option')[1].text)
|
||||||
|
equal('b', el.find('[name=select1] option')[2].text)
|
||||||
|
equal('B', el.find('[name=select1] option')[3].text)
|
||||||
|
equal('NOT EXISTING', el.find('[name=select1] option')[4].text)
|
||||||
|
equal('XX', el.find('[name=select1] option')[5].text)
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
test("check if select value is not existing and is not shown", function() {
|
||||||
|
|
||||||
|
$('#forms').append('<hr><h1>check if select value is not existing and is not shown</h1><form id="form18"></form>')
|
||||||
|
var el = $('#form18')
|
||||||
|
var defaults = {
|
||||||
|
select1: 'NOT EXISTING',
|
||||||
|
}
|
||||||
|
new App.ControllerForm({
|
||||||
|
el: el,
|
||||||
|
model: {
|
||||||
|
configure_attributes: [
|
||||||
|
{ name: 'select1', display: 'Select1', tag: 'select', null: true, default: 'XY', options: { 'XX': 'AA', 'A': 'XX', 'B': 'B', 'XY': 'b', '': 'äöü' } },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
params: defaults,
|
||||||
|
rejectNonExistentValues: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
params = App.ControllerForm.params(el)
|
||||||
|
test_params = {
|
||||||
|
select1: 'XY',
|
||||||
|
}
|
||||||
|
deepEqual(params, test_params)
|
||||||
|
|
||||||
|
equal('AA', el.find('[name=select1] option')[0].text)
|
||||||
|
equal('äöü', el.find('[name=select1] option')[1].text)
|
||||||
|
equal('b', el.find('[name=select1] option')[2].text)
|
||||||
|
equal('B', el.find('[name=select1] option')[3].text)
|
||||||
|
equal('XX', el.find('[name=select1] option')[4].text)
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
test("time range form 1", function() {
|
test("time range form 1", function() {
|
||||||
|
|
||||||
$('#forms').append('<hr><h1>time range form 1</h1><form id="form14"></form>')
|
$('#forms').append('<hr><h1>time range form 1</h1><form id="form14"></form>')
|
||||||
|
|
8
spec/factories/template.rb
Normal file
8
spec/factories/template.rb
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
FactoryBot.define do
|
||||||
|
factory :template do
|
||||||
|
name { Faker::Name.unique.name }
|
||||||
|
options { {} }
|
||||||
|
updated_by_id { 1 }
|
||||||
|
created_by_id { 1 }
|
||||||
|
end
|
||||||
|
end
|
31
spec/system/ticket/create_spec.rb
Normal file
31
spec/system/ticket/create_spec.rb
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe 'Ticket Create', type: :system do
|
||||||
|
context 'when applying ticket templates' do
|
||||||
|
# Regression test for issue #2424 - Unavailable ticket template attributes get applied
|
||||||
|
scenario 'unavailable attributes do not get applied', authenticated: false do
|
||||||
|
# create a new agent with permissions for only group "some group1"
|
||||||
|
user = create :agent_user
|
||||||
|
user.group_names_access_map = {
|
||||||
|
'some group1' => 'full',
|
||||||
|
}
|
||||||
|
|
||||||
|
# create a template that sets the group to Users and ticket owner to user id 1
|
||||||
|
template = create :template, options: {
|
||||||
|
'title' => 'Template Title',
|
||||||
|
'group_id' => '1',
|
||||||
|
'owner_id' => '2',
|
||||||
|
}
|
||||||
|
|
||||||
|
# apply the ticket template and confirm that the group_id dropdown does not appear
|
||||||
|
login(
|
||||||
|
username: user.email,
|
||||||
|
password: 'test',
|
||||||
|
)
|
||||||
|
visit 'ticket/create'
|
||||||
|
find('#form-template select[name="id"]').find(:option, template.name).select_option
|
||||||
|
click '.sidebar-content .js-apply'
|
||||||
|
expect(page).not_to have_selector 'select[name="group_id"]'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue