Skip to content

Commit

Permalink
Fixes zammad#4891 - Setting a group via CoreWorkflow in the ticket cr…
Browse files Browse the repository at this point in the history
…eation mask...

Co-authored-by: Florian Liebe <[email protected]>
  • Loading branch information
rolfschmidt and fliebe92 committed Oct 19, 2023
1 parent 8f4bda4 commit 057e90b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,12 @@ class App.ControllerForm extends App.Controller
item_bind = item.find('.richtext-content')
item_event = 'blur'

item_bind.on(item_event, (e) =>
item_bind.on(item_event, (e, args) =>
@lastChangedAttribute = attribute.name
params = App.ControllerForm.params(@form)
dispatchID = Math.floor( Math.random() * 999999 ).toString()
for handler in @handlers
continue if _.isObject(args) && args.skip_core_worfklow && handler is App.FormHandlerCoreWorkflow.run
handler(params, attribute, @attributes, idPrefix, form, @, dispatchID)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class App.TicketCreate extends App.Controller

# force changing signature
# skip on initialization because it will trigger core workflow
@$('[name="group_id"]').trigger('change', true)
@$('[name="group_id"]').trigger('change', non_interactive: true)

# add observer to change options
@$('[name="cc"], [name="group_id"], [name="customer_id"]').on('change', =>
Expand Down Expand Up @@ -236,7 +236,7 @@ class App.TicketCreate extends App.Controller
dirtyMonitorStart: =>
@dirty = {}

update = (e, nonInteractive) =>
update = (e, args) =>
{ target } = e

field = target.getAttribute('name') || target.getAttribute('data-name')
Expand All @@ -247,7 +247,7 @@ class App.TicketCreate extends App.Controller
return

# Skip tracking of non-interactive fields
if nonInteractive || field == 'id'
if (_.isObject(args) && args.non_interactive) || field == 'id'
@log 'debug', 'ticket create dirty monitor', 'non-interactive change', field
return

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ class App.FormHandlerCoreWorkflow
else
ui.optional(field, form)

if data.select[item.name] isnt undefined
form.find('[name="' + field + '"]').trigger('change', skip_core_worfklow: true)

# fill in data in input fields
@fillIn: (classname, form, ui, attributes, params, data) ->
return if _.isEmpty(data)
Expand All @@ -192,6 +195,7 @@ class App.FormHandlerCoreWorkflow
fieldElement.val(data[field])

coreWorkflowParams[classname][field] = data[field]
fieldElement.trigger('change', skip_core_worfklow: true)

# changes the visibility of form elements
@changeVisibility: (form, ui, data) ->
Expand Down
34 changes: 34 additions & 0 deletions spec/system/ticket/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1476,4 +1476,38 @@ def authenticate
expect(Ticket.last).to have_attributes(field_name => 1.day.from_now.to_date)
end
end

describe 'Setting a group via CoreWorkflow in the ticket creation mask does not update text module filters and email signatures #4891', authenticated_as: :authenticate do
let(:group_1) { create(:group, signature: create(:signature, body: SecureRandom.uuid)) }
let(:group_2) { create(:group, signature: create(:signature, body: SecureRandom.uuid)) }
let(:workflow_1) do
create(:core_workflow,
object: 'Ticket',
condition_selected: { 'ticket.priority_id'=>{ 'operator' => 'is', 'value' => Ticket::Priority.find_by(name: '3 high').id.to_s } },
perform: { 'ticket.group_id' => { 'operator' => 'select', 'select' => group_1.id.to_s } })
end
let(:workflow_2) do
create(:core_workflow,
object: 'Ticket',
condition_selected: { 'ticket.priority_id'=>{ 'operator' => 'is', 'value' => Ticket::Priority.find_by(name: '1 low').id.to_s } },
perform: { 'ticket.group_id' => { 'operator' => 'select', 'select' => group_2.id.to_s } })
end

def authenticate
workflow_1 && workflow_2
group_1 && group_2
create(:agent, groups: Group.all)
end

it 'does change the signature when switching group via core workflow' do
visit 'ticket/create'
find('[data-type=email-out]').click

page.find('[name=priority_id]').select '3 high'
expect(page).to have_text(group_1.signature.body)

page.find('[name=priority_id]').select '1 low'
expect(page).to have_text(group_2.signature.body)
end
end
end

0 comments on commit 057e90b

Please sign in to comment.