Fixes #3421: Webhook action should display hint in Scheduler and Trigger

This commit is contained in:
Bola Ahmed Buari 2021-03-09 13:19:22 +00:00 committed by Martin Edenhofer
parent 3efacf186c
commit 20d3c5027f
4 changed files with 175 additions and 9 deletions

View file

@ -94,7 +94,8 @@ class App.UiElement.ticket_perform_action
item.on('change', '.js-attributeSelector select', (e) => item.on('change', '.js-attributeSelector select', (e) =>
elementRow = $(e.target).closest('.js-filterElement') elementRow = $(e.target).closest('.js-filterElement')
groupAndAttribute = elementRow.find('.js-attributeSelector option:selected').attr('value') groupAndAttribute = elementRow.find('.js-attributeSelector option:selected').attr('value')
@rebuildAttributeSelectors(item, elementRow, groupAndAttribute, elements, {}, attribute) meta = params[attribute.name] && params[attribute.name][groupAndAttribute] || {}
@rebuildAttributeSelectors(item, elementRow, groupAndAttribute, elements, meta, attribute)
@updateAttributeSelectors(item) @updateAttributeSelectors(item)
) )
@ -416,6 +417,8 @@ class App.UiElement.ticket_perform_action
notificationElement.find('.js-recipient select').replaceWith(selectionRecipient) notificationElement.find('.js-recipient select').replaceWith(selectionRecipient)
if App.Webhook.search(filter: { active: true }).length isnt 0 || !_.isEmpty(meta.webhook_id)
webhookSelection = App.UiElement.select.render( webhookSelection = App.UiElement.select.render(
name: "#{name}::webhook_id" name: "#{name}::webhook_id"
multiple: false multiple: false
@ -424,6 +427,8 @@ class App.UiElement.ticket_perform_action
value: meta.webhook_id value: meta.webhook_id
translate: false translate: false
) )
else
webhookSelection = App.view('generic/ticket_perform_action/webhook_not_available')( attribute: attribute )
notificationElement.find('.js-webhooks').html(webhookSelection) notificationElement.find('.js-webhooks').html(webhookSelection)

View file

@ -26,4 +26,6 @@ You can use Webhooks in Zammad to send Ticket, Article and Attachment data whene
displayName: -> displayName: ->
return @name if !@endpoint return @name if !@endpoint
if @active is false
return "#{@name} (#{@endpoint}) (#{App.i18n.translateInline('inactive')})"
"#{@name} (#{@endpoint})" "#{@name} (#{@endpoint})"

View file

@ -0,0 +1 @@
<div><%- @T('No available webhook, please create a new one or activate an existing one at "Manage > Webhook"') %></div>

View file

@ -605,3 +605,161 @@ test( "ticket_perform_action check possible owner selection", function() {
deepEqual(params, test_params, 'form param check') deepEqual(params, test_params, 'form param check')
}); });
test( "ticket_perform_action check when there's no available webhook", function() {
$('#forms').append('<hr><h1>ticket_perform_action check when there\'s no available webhook</h1><form id="form6"></form>')
var el = $('#form6')
var defaults = {
ticket_perform_action6: {
'notification.webhook': {
value: undefined
}
}
}
new App.ControllerForm({
el: el,
model: {
configure_attributes: [
{
name: 'ticket_perform_action6',
display: 'TicketPerformAction6',
tag: 'ticket_perform_action',
null: true,
notification: true,
},
]
},
params: defaults,
autofocus: true
})
var params = App.ControllerForm.params(el)
deepEqual(params, {}, 'form param check')
var testNoticeMessage = 'No available webhook, please create a new one or activate an existing one at "Manage > Webhook"'
var noticeMessage = el.find('.controls.js-webhooks div').text()
equal(noticeMessage, testNoticeMessage, 'form shows message when webhook is not available')
});
test( "ticket_perform_action check when there's an available webhook", function() {
$('#forms').append('<hr><h1>ticket_perform_action check when there\'s an available webhook</h1><form id="form7"></form>')
var el = $('#form7')
var defaults = {
ticket_perform_action7: {
'notification.webhook': {
webhook_id: 'c-1'
}
}
}
App.Webhook.refresh([
{
name: 'Webhook test',
endpoint: 'https://target.example.com/webhook',
active: true,
id: 'c-1'
}
], { clear: true })
new App.ControllerForm({
el: el,
model: {
configure_attributes: [
{
name: 'ticket_perform_action7',
display: 'TicketPerformAction7',
tag: 'ticket_perform_action',
null: true,
notification: true,
},
]
},
params: defaults,
autofocus: true
})
var params = App.ControllerForm.params(el)
var test_params = {
'ticket_perform_action7': {
'notification.webhook': {
'webhook_id': 'c-1'
}
}
}
deepEqual(params, test_params, 'form param check')
var testNoticeMessage = 'No available webhook, please create a new one or activate an existing one at "Manage > Webhook"'
var noticeMessage = el.find('.controls.js-webhooks').text()
notEqual(noticeMessage, testNoticeMessage, 'form shows message when webhook is not available')
var noticeMessage = el.find('.controls.js-webhooks select option').first().text()
equal(noticeMessage, 'Webhook test (https://target.example.com/webhook)', 'form shows message when webhook is not available')
});
test( "ticket_perform_action check when there's no available webhook but an inactive is already selected", function() {
$('#forms').append('<hr><h1>ticket_perform_action check when there\'s an available webhook</h1><form id="form8"></form>')
var el = $('#form8')
var defaults = {
ticket_perform_action8: {
'notification.webhook': {
webhook_id: 'c-2'
}
}
}
App.Webhook.refresh([
{
name: 'Webhook test',
endpoint: 'https://target.example.com/webhook',
active: false,
id: 'c-2'
}
], { clear: true })
new App.ControllerForm({
el: el,
model: {
configure_attributes: [
{
name: 'ticket_perform_action8',
display: 'TicketPerformAction8',
tag: 'ticket_perform_action',
null: true,
notification: true,
},
]
},
params: defaults,
autofocus: true
})
var params = App.ControllerForm.params(el)
var test_params = {
'ticket_perform_action8': {
'notification.webhook': {
'webhook_id': 'c-2'
}
}
}
deepEqual(params, test_params, 'form param check')
var testNoticeMessage = 'No available webhook, please create a new one or activate an existing one at "Manage > Webhook"'
var noticeMessage = el.find('.controls.js-webhooks div').text()
notEqual(noticeMessage, testNoticeMessage, 'form does not show notice message when inactive webhook is previously selected')
var noticeMessage = el.find('.controls.js-webhooks select option').first().text()
equal(noticeMessage, 'Webhook test (https://target.example.com/webhook) (inactive)', 'form shows previously selected inactive webhook')
// when other option are changed
el.find('select:first').val('notification.email').trigger('change')
el.find('select:first').val('notification.webhook').trigger('change')
var noticeMessage = el.find('.controls.js-webhooks div').text()
notEqual(noticeMessage, testNoticeMessage, 'form does not show notice message when inactive webhook is previously selected')
var noticeMessage = el.find('.controls.js-webhooks select option').first().text()
equal(noticeMessage, 'Webhook test (https://target.example.com/webhook) (inactive)', 'form shows previously selected inactive webhook')
});