From a2871cd74719a7a5a104daaa3dcc0e2670b7c2df Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 9 Jun 2022 21:57:36 +0200 Subject: Add administrative webhooks (#18510) * Add administrative webhooks * Fix error when webhook is deleted before delivery worker runs --- app/views/admin/webhooks/_form.html.haml | 11 ++++++++++ app/views/admin/webhooks/_webhook.html.haml | 19 ++++++++++++++++ app/views/admin/webhooks/edit.html.haml | 4 ++++ app/views/admin/webhooks/index.html.haml | 18 +++++++++++++++ app/views/admin/webhooks/new.html.haml | 4 ++++ app/views/admin/webhooks/show.html.haml | 34 +++++++++++++++++++++++++++++ app/views/layouts/admin.html.haml | 5 ++++- 7 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 app/views/admin/webhooks/_form.html.haml create mode 100644 app/views/admin/webhooks/_webhook.html.haml create mode 100644 app/views/admin/webhooks/edit.html.haml create mode 100644 app/views/admin/webhooks/index.html.haml create mode 100644 app/views/admin/webhooks/new.html.haml create mode 100644 app/views/admin/webhooks/show.html.haml (limited to 'app/views') diff --git a/app/views/admin/webhooks/_form.html.haml b/app/views/admin/webhooks/_form.html.haml new file mode 100644 index 000000000..c1e8f8979 --- /dev/null +++ b/app/views/admin/webhooks/_form.html.haml @@ -0,0 +1,11 @@ += simple_form_for @webhook, url: @webhook.new_record? ? admin_webhooks_path : admin_webhook_path(@webhook) do |f| + = render 'shared/error_messages', object: @webhook + + .fields-group + = f.input :url, wrapper: :with_block_label, input_html: { placeholder: 'https://' } + + .fields-group + = f.input :events, collection: Webhook::EVENTS, wrapper: :with_block_label, include_blank: false, as: :check_boxes, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li' + + .actions + = f.button :button, @webhook.new_record? ? t('admin.webhooks.add_new') : t('generic.save_changes'), type: :submit diff --git a/app/views/admin/webhooks/_webhook.html.haml b/app/views/admin/webhooks/_webhook.html.haml new file mode 100644 index 000000000..d94a41eb3 --- /dev/null +++ b/app/views/admin/webhooks/_webhook.html.haml @@ -0,0 +1,19 @@ +.applications-list__item + = link_to admin_webhook_path(webhook), class: 'announcements-list__item__title' do + = fa_icon 'inbox' + = webhook.url + + .announcements-list__item__action-bar + .announcements-list__item__meta + - if webhook.enabled? + %span.positive-hint= t('admin.webhooks.enabled') + - else + %span.negative-hint= t('admin.webhooks.disabled') + + • + + %abbr{ title: webhook.events.join(', ') }= t('admin.webhooks.enabled_events', count: webhook.events.size) + + %div + = table_link_to 'pencil', t('admin.webhooks.edit'), edit_admin_webhook_path(webhook) if can?(:update, webhook) + = table_link_to 'trash', t('admin.webhooks.delete'), admin_webhook_path(webhook), method: :delete, data: { confirm: t('admin.accounts.are_you_sure') } if can?(:destroy, webhook) diff --git a/app/views/admin/webhooks/edit.html.haml b/app/views/admin/webhooks/edit.html.haml new file mode 100644 index 000000000..3dc0ace9b --- /dev/null +++ b/app/views/admin/webhooks/edit.html.haml @@ -0,0 +1,4 @@ +- content_for :page_title do + = t('admin.webhooks.edit') + += render partial: 'form' diff --git a/app/views/admin/webhooks/index.html.haml b/app/views/admin/webhooks/index.html.haml new file mode 100644 index 000000000..e4499e078 --- /dev/null +++ b/app/views/admin/webhooks/index.html.haml @@ -0,0 +1,18 @@ +- content_for :page_title do + = t('admin.webhooks.title') + +- content_for :heading_actions do + = link_to t('admin.webhooks.add_new'), new_admin_webhook_path, class: 'button' if can?(:create, :webhook) + +%p= t('admin.webhooks.description_html') + +%hr.spacer/ + +- if @webhooks.empty? + %div.muted-hint.center-text + = t 'admin.webhooks.empty' +- else + .applications-list + = render partial: 'webhook', collection: @webhooks + + = paginate @webhooks diff --git a/app/views/admin/webhooks/new.html.haml b/app/views/admin/webhooks/new.html.haml new file mode 100644 index 000000000..1258df74a --- /dev/null +++ b/app/views/admin/webhooks/new.html.haml @@ -0,0 +1,4 @@ +- content_for :page_title do + = t('admin.webhooks.new') + += render partial: 'form' diff --git a/app/views/admin/webhooks/show.html.haml b/app/views/admin/webhooks/show.html.haml new file mode 100644 index 000000000..cc450de26 --- /dev/null +++ b/app/views/admin/webhooks/show.html.haml @@ -0,0 +1,34 @@ +- content_for :page_title do + = t('admin.webhooks.title') + +- content_for :heading do + %h2 + %small + = fa_icon 'inbox' + = t('admin.webhooks.webhook') + = @webhook.url + +- content_for :heading_actions do + = link_to t('admin.webhooks.edit'), edit_admin_webhook_path, class: 'button' if can?(:update, @webhook) + +.table-wrapper + %table.table.horizontal-table + %tbody + %tr + %th= t('admin.webhooks.status') + %td + - if @webhook.enabled? + %span.positive-hint= t('admin.webhooks.enabled') + = table_link_to 'power-off', t('admin.webhooks.disable'), disable_admin_webhook_path(@webhook), method: :post if can?(:disable, @webhook) + - else + %span.negative-hint= t('admin.webhooks.disabled') + = table_link_to 'power-off', t('admin.webhooks.enable'), enable_admin_webhook_path(@webhook), method: :post if can?(:enable, @webhook) + %tr + %th= t('admin.webhooks.events') + %td + %abbr{ title: @webhook.events.join(', ') }= t('admin.webhooks.enabled_events', count: @webhook.events.size) + %tr + %th= t('admin.webhooks.secret') + %td + %samp= @webhook.secret + = table_link_to 'refresh', t('admin.webhooks.rotate_secret'), rotate_admin_webhook_secret_path(@webhook), method: :post if can?(:rotate_secret, @webhook) diff --git a/app/views/layouts/admin.html.haml b/app/views/layouts/admin.html.haml index 62716ab1e..0f6433781 100644 --- a/app/views/layouts/admin.html.haml +++ b/app/views/layouts/admin.html.haml @@ -23,7 +23,10 @@ .content-wrapper .content .content-heading - %h2= yield :page_title + - if content_for?(:heading) + = yield :heading + - else + %h2= yield :page_title - if :heading_actions .content-heading-actions -- cgit