From 8762f968106ec15b75844b01ce02b05dccf889d5 Mon Sep 17 00:00:00 2001 From: Martin Gruner Date: Fri, 8 Oct 2021 08:23:20 +0200 Subject: [PATCH] Fixes #3794 - Example payload in webhook view leads to 500 error --- app/controllers/webhooks_controller.rb | 4 +--- spec/system/manage/webhooks_spec.rb | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/controllers/webhooks_controller.rb b/app/controllers/webhooks_controller.rb index 722931f2c..fc55e3586 100644 --- a/app/controllers/webhooks_controller.rb +++ b/app/controllers/webhooks_controller.rb @@ -4,9 +4,7 @@ class WebhooksController < ApplicationController prepend_before_action { authentication_check && authorize! } def preview - access_condition = Ticket.access_condition(current_user, 'read') - - ticket = Ticket.where(access_condition).last + ticket = TicketPolicy::ReadScope.new(current_user).resolve.last render json: JSON.pretty_generate({ ticket: TriggerWebhookJob::RecordPayload.generate(ticket), diff --git a/spec/system/manage/webhooks_spec.rb b/spec/system/manage/webhooks_spec.rb index 34081fa87..a257d8ebe 100644 --- a/spec/system/manage/webhooks_spec.rb +++ b/spec/system/manage/webhooks_spec.rb @@ -3,7 +3,23 @@ require 'rails_helper' RSpec.describe 'Manage > Webhook', type: :system do - context 'deleting' do + + context 'when showing the example payload' do + + it 'shows correctly' do + visit '/#manage/webhook' + + within :active_content do + click 'a[data-type="payload"]' + end + + in_modal disappears: false do + expect(page).to have_text('X-Zammad-Trigger:') + end + end + end + + context 'when deleting' do let!(:webhook) { create(:webhook) } let!(:trigger) { create(:trigger, perform: { 'notification.webhook' => { 'webhook_id' => webhook.id.to_s } }) }