diff --git a/app/assets/javascripts/app/controllers/_ui_element/ticket_perform_action.coffee b/app/assets/javascripts/app/controllers/_ui_element/ticket_perform_action.coffee
index 325da089b..429c17d21 100644
--- a/app/assets/javascripts/app/controllers/_ui_element/ticket_perform_action.coffee
+++ b/app/assets/javascripts/app/controllers/_ui_element/ticket_perform_action.coffee
@@ -94,7 +94,8 @@ class App.UiElement.ticket_perform_action
item.on('change', '.js-attributeSelector select', (e) =>
elementRow = $(e.target).closest('.js-filterElement')
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)
)
@@ -416,14 +417,18 @@ class App.UiElement.ticket_perform_action
notificationElement.find('.js-recipient select').replaceWith(selectionRecipient)
- webhookSelection = App.UiElement.select.render(
- name: "#{name}::webhook_id"
- multiple: false
- null: false
- relation: 'Webhook'
- value: meta.webhook_id
- translate: false
- )
+
+ if App.Webhook.search(filter: { active: true }).length isnt 0 || !_.isEmpty(meta.webhook_id)
+ webhookSelection = App.UiElement.select.render(
+ name: "#{name}::webhook_id"
+ multiple: false
+ null: false
+ relation: 'Webhook'
+ value: meta.webhook_id
+ translate: false
+ )
+ else
+ webhookSelection = App.view('generic/ticket_perform_action/webhook_not_available')( attribute: attribute )
notificationElement.find('.js-webhooks').html(webhookSelection)
diff --git a/app/assets/javascripts/app/models/webhook.coffee b/app/assets/javascripts/app/models/webhook.coffee
index fead97e46..ea77bf0d1 100644
--- a/app/assets/javascripts/app/models/webhook.coffee
+++ b/app/assets/javascripts/app/models/webhook.coffee
@@ -26,4 +26,6 @@ You can use Webhooks in Zammad to send Ticket, Article and Attachment data whene
displayName: ->
return @name if !@endpoint
+ if @active is false
+ return "#{@name} (#{@endpoint}) (#{App.i18n.translateInline('inactive')})"
"#{@name} (#{@endpoint})"
diff --git a/app/assets/javascripts/app/views/generic/ticket_perform_action/webhook_not_available.jst.eco b/app/assets/javascripts/app/views/generic/ticket_perform_action/webhook_not_available.jst.eco
new file mode 100644
index 000000000..188d3e9bf
--- /dev/null
+++ b/app/assets/javascripts/app/views/generic/ticket_perform_action/webhook_not_available.jst.eco
@@ -0,0 +1 @@
+
<%- @T('No available webhook, please create a new one or activate an existing one at "Manage > Webhook"') %>
diff --git a/public/assets/tests/form_ticket_perform_action.js b/public/assets/tests/form_ticket_perform_action.js
index 778f17050..166e8b388 100644
--- a/public/assets/tests/form_ticket_perform_action.js
+++ b/public/assets/tests/form_ticket_perform_action.js
@@ -605,3 +605,161 @@ test( "ticket_perform_action check possible owner selection", function() {
deepEqual(params, test_params, 'form param check')
});
+
+test( "ticket_perform_action check when there's no available webhook", function() {
+
+ $('#forms').append('
ticket_perform_action check when there\'s no available webhook
')
+ 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('
ticket_perform_action check when there\'s an available webhook
')
+ 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('
ticket_perform_action check when there\'s an available webhook
')
+ 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')
+});