Fixed issue #542 - Cant add new articles via Macro.
This commit is contained in:
parent
0459023514
commit
8996134214
3 changed files with 138 additions and 53 deletions
|
@ -766,6 +766,7 @@ class App.TicketZoom extends App.Controller
|
||||||
return
|
return
|
||||||
|
|
||||||
ticketParams = @formParam(@$('.edit'))
|
ticketParams = @formParam(@$('.edit'))
|
||||||
|
articleParams = @articleNew.params()
|
||||||
|
|
||||||
# validate ticket
|
# validate ticket
|
||||||
# we need to use the full ticket because
|
# we need to use the full ticket because
|
||||||
|
@ -784,6 +785,7 @@ class App.TicketZoom extends App.Controller
|
||||||
App.Ticket.macro(
|
App.Ticket.macro(
|
||||||
macro: macro.perform
|
macro: macro.perform
|
||||||
ticket: ticket
|
ticket: ticket
|
||||||
|
article: articleParams
|
||||||
callback:
|
callback:
|
||||||
tagAdd: (tag) =>
|
tagAdd: (tag) =>
|
||||||
return if !@sidebarWidget
|
return if !@sidebarWidget
|
||||||
|
@ -832,7 +834,6 @@ class App.TicketZoom extends App.Controller
|
||||||
@autosaveStart()
|
@autosaveStart()
|
||||||
return
|
return
|
||||||
|
|
||||||
articleParams = @articleNew.params()
|
|
||||||
if articleParams && articleParams.body
|
if articleParams && articleParams.body
|
||||||
article = new App.TicketArticle
|
article = new App.TicketArticle
|
||||||
article.load(articleParams)
|
article.load(articleParams)
|
||||||
|
|
|
@ -114,6 +114,8 @@ class App.Ticket extends App.Model
|
||||||
@macro: (params) ->
|
@macro: (params) ->
|
||||||
for key, content of params.macro
|
for key, content of params.macro
|
||||||
attributes = key.split('.')
|
attributes = key.split('.')
|
||||||
|
|
||||||
|
# apply ticket changes
|
||||||
if attributes[0] is 'ticket'
|
if attributes[0] is 'ticket'
|
||||||
|
|
||||||
# apply tag changes
|
# apply tag changes
|
||||||
|
@ -142,6 +144,25 @@ class App.Ticket extends App.Model
|
||||||
else
|
else
|
||||||
params.ticket[attributes[1]] = content.value
|
params.ticket[attributes[1]] = content.value
|
||||||
|
|
||||||
|
# apply article changes
|
||||||
|
else if attributes[0] is 'article'
|
||||||
|
|
||||||
|
# preload required attributes
|
||||||
|
if attributes[1]
|
||||||
|
type = App.TicketArticleType.findByAttribute('name', attributes[1])
|
||||||
|
if type
|
||||||
|
params.article.type_id = type.id
|
||||||
|
if !content.sender_id
|
||||||
|
sender = App.TicketArticleSender.findByAttribute('name', 'Agent')
|
||||||
|
if sender
|
||||||
|
content.sender_id = sender.id
|
||||||
|
if !content.from
|
||||||
|
content.from = App.Session.get('login')
|
||||||
|
|
||||||
|
# apply direct value changes
|
||||||
|
for articleKey, aricleValue of content
|
||||||
|
params.article[articleKey] = aricleValue
|
||||||
|
|
||||||
# check if selector is matching
|
# check if selector is matching
|
||||||
@selector: (ticket, selector) ->
|
@selector: (ticket, selector) ->
|
||||||
return true if _.isEmpty(selector)
|
return true if _.isEmpty(selector)
|
||||||
|
|
|
@ -6,12 +6,13 @@ require 'system/examples/macros_examples'
|
||||||
RSpec.describe 'Ticket Update', type: :system do
|
RSpec.describe 'Ticket Update', type: :system do
|
||||||
|
|
||||||
let(:group) { Group.find_by(name: 'Users') }
|
let(:group) { Group.find_by(name: 'Users') }
|
||||||
|
let(:ticket) { create(:ticket, group: group) }
|
||||||
|
|
||||||
# Regression test for issue #2242 - mandatory fields can be empty (or "-") on ticket update
|
# Regression test for issue #2242 - mandatory fields can be empty (or "-") on ticket update
|
||||||
context 'when updating a ticket without its required select attributes' do
|
context 'when updating a ticket without its required select attributes' do
|
||||||
it 'frontend checks reject the update', db_strategy: :reset do
|
it 'frontend checks reject the update', db_strategy: :reset do
|
||||||
# setup and migrate a required select attribute
|
# setup and migrate a required select attribute
|
||||||
attribute = create_attribute :object_manager_attribute_select,
|
attribute = create_attribute(:object_manager_attribute_select,
|
||||||
screens: attributes_for(:required_screen),
|
screens: attributes_for(:required_screen),
|
||||||
data_option: {
|
data_option: {
|
||||||
options: {
|
options: {
|
||||||
|
@ -23,15 +24,14 @@ RSpec.describe 'Ticket Update', type: :system do
|
||||||
relation: '',
|
relation: '',
|
||||||
maxlength: 255,
|
maxlength: 255,
|
||||||
nulloption: true,
|
nulloption: true,
|
||||||
}
|
})
|
||||||
|
|
||||||
# create a new ticket and attempt to update its state without the required select attribute
|
# create a new ticket and attempt to update its state without the required select attribute
|
||||||
ticket = create :ticket, group: group
|
|
||||||
visit "#ticket/zoom/#{ticket.id}"
|
visit "#ticket/zoom/#{ticket.id}"
|
||||||
within(:active_content) do
|
within(:active_content) do
|
||||||
expect(page).to have_css('.js-objectNumber', wait: 2)
|
expect(page).to have_selector('.js-objectNumber', text: ticket.number)
|
||||||
|
|
||||||
select 'closed', from: 'state_id'
|
select('closed', from: 'state_id')
|
||||||
click('.js-attributeBar .js-submit')
|
click('.js-attributeBar .js-submit')
|
||||||
expect(page).to have_no_css('.js-submitDropdown .js-submit[disabled]', wait: 2)
|
expect(page).to have_no_css('.js-submitDropdown .js-submit[disabled]', wait: 2)
|
||||||
end
|
end
|
||||||
|
@ -50,10 +50,13 @@ RSpec.describe 'Ticket Update', type: :system do
|
||||||
expect(ticket[attribute.name]).to eq('name 2')
|
expect(ticket[attribute.name]).to eq('name 2')
|
||||||
expect(ticket.state.name).to eq('closed')
|
expect(ticket.state.name).to eq('closed')
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it 'with macro and required tree_select field', db_strategy: :reset do
|
context 'when updating a ticket with macro' do
|
||||||
|
context 'when required tree_select field is present' do
|
||||||
|
it 'performs no validation (#2492)', db_strategy: :reset do
|
||||||
# setup and migrate a required select attribute
|
# setup and migrate a required select attribute
|
||||||
attribute = create_attribute :object_manager_attribute_tree_select,
|
attribute = create_attribute(:object_manager_attribute_tree_select,
|
||||||
screens: attributes_for(:required_screen),
|
screens: attributes_for(:required_screen),
|
||||||
data_option: {
|
data_option: {
|
||||||
options: [
|
options: [
|
||||||
|
@ -71,7 +74,7 @@ RSpec.describe 'Ticket Update', type: :system do
|
||||||
relation: '',
|
relation: '',
|
||||||
maxlength: 255,
|
maxlength: 255,
|
||||||
nulloption: true,
|
nulloption: true,
|
||||||
}
|
})
|
||||||
|
|
||||||
attribute_value = 'name 2'
|
attribute_value = 'name 2'
|
||||||
state = Ticket::State.by_category(:closed).first
|
state = Ticket::State.by_category(:closed).first
|
||||||
|
@ -83,23 +86,33 @@ RSpec.describe 'Ticket Update', type: :system do
|
||||||
"ticket.#{attribute.name}" => {
|
"ticket.#{attribute.name}" => {
|
||||||
value: attribute_value,
|
value: attribute_value,
|
||||||
},
|
},
|
||||||
})
|
},
|
||||||
|
ux_flow_next_up: 'none',)
|
||||||
|
|
||||||
# refresh browser to get macro accessible
|
# refresh browser to get macro accessible
|
||||||
refresh
|
refresh
|
||||||
|
|
||||||
# create a new ticket and attempt to update its state without the required select attribute
|
# create a new ticket and attempt to update its state without the required select attribute
|
||||||
ticket = create(:ticket, group: group)
|
|
||||||
visit "#ticket/zoom/#{ticket.id}"
|
visit "#ticket/zoom/#{ticket.id}"
|
||||||
|
|
||||||
within(:active_content) do
|
within(:active_content) do
|
||||||
expect(page).to have_css('.js-objectNumber', wait: 2)
|
expect(page).to have_selector('.js-objectNumber', text: ticket.number)
|
||||||
|
|
||||||
|
expect(page).to have_field(attribute.name, with: '', visible: false)
|
||||||
|
expect(page).to have_select('state_id',
|
||||||
|
selected: 'new',
|
||||||
|
options: ['new', 'closed', 'open', 'pending close', 'pending reminder'])
|
||||||
|
|
||||||
click('.js-openDropdownMacro')
|
click('.js-openDropdownMacro')
|
||||||
click(".js-dropdownActionMacro[data-id=\"#{macro.id}\"]")
|
click(".js-dropdownActionMacro[data-id=\"#{macro.id}\"]")
|
||||||
expect(page).not_to have_css('.js-submitDropdown .js-submit[disabled]', wait: 2)
|
expect(page).not_to have_css('.js-submitDropdown .js-submit[disabled]', wait: 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
expect(page).to have_field(attribute.name, with: attribute_value, visible: false)
|
||||||
|
expect(page).to have_select('state_id',
|
||||||
|
selected: 'closed',
|
||||||
|
options: ['closed', 'open', 'pending close', 'pending reminder'])
|
||||||
|
|
||||||
# the update should not have failed and thus the ticket is in closed state
|
# the update should not have failed and thus the ticket is in closed state
|
||||||
ticket.reload
|
ticket.reload
|
||||||
expect(ticket[attribute.name]).to eq(attribute_value)
|
expect(ticket[attribute.name]).to eq(attribute_value)
|
||||||
|
@ -107,6 +120,56 @@ RSpec.describe 'Ticket Update', type: :system do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when macro has article configured' do
|
||||||
|
it 'creates an article with the configured attributes' do
|
||||||
|
state = Ticket::State.find_by(name: 'closed')
|
||||||
|
macro = create(:macro,
|
||||||
|
perform: {
|
||||||
|
'ticket.state_id' => {
|
||||||
|
value: state.id,
|
||||||
|
},
|
||||||
|
'article.note' => {
|
||||||
|
'body' => 'test body',
|
||||||
|
'internal' => 'true',
|
||||||
|
'subject' => 'test sub'
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ux_flow_next_up: 'none',)
|
||||||
|
|
||||||
|
# refresh browser to get macro accessible
|
||||||
|
refresh
|
||||||
|
|
||||||
|
# create a new ticket and attempt to update its state without the required select attribute
|
||||||
|
visit "#ticket/zoom/#{ticket.id}"
|
||||||
|
|
||||||
|
within(:active_content) do
|
||||||
|
expect(page).to have_selector('.js-objectNumber', text: ticket.number)
|
||||||
|
expect(page).to have_select('state_id',
|
||||||
|
selected: 'new',
|
||||||
|
options: ['new', 'closed', 'open', 'pending close', 'pending reminder'])
|
||||||
|
|
||||||
|
click('.js-openDropdownMacro')
|
||||||
|
click(".js-dropdownActionMacro[data-id=\"#{macro.id}\"]")
|
||||||
|
expect(page).not_to have_css('.js-submitDropdown .js-submit[disabled]', wait: 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(page).to have_selector('.content.active .article-content', text: 'test body')
|
||||||
|
expect(page).to have_select('state_id',
|
||||||
|
selected: 'closed',
|
||||||
|
options: ['closed', 'open', 'pending close', 'pending reminder'])
|
||||||
|
|
||||||
|
# the update should not have failed and thus the ticket is in closed state
|
||||||
|
ticket.reload
|
||||||
|
expect(ticket.state.name).to eq(state.name)
|
||||||
|
article = ticket.articles.last
|
||||||
|
expect(article).to be_present
|
||||||
|
expect(article.body).to eq('test body')
|
||||||
|
expect(article.subject).to eq('test sub')
|
||||||
|
expect(article.internal).to eq(true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Issue #2469 - Add information "Ticket merged" to History
|
# Issue #2469 - Add information "Ticket merged" to History
|
||||||
context 'when merging tickets' do
|
context 'when merging tickets' do
|
||||||
it 'tickets history of both tickets should show the merge event' do
|
it 'tickets history of both tickets should show the merge event' do
|
||||||
|
|
Loading…
Reference in a new issue