Move reactivation out of edit

This commit is contained in:
Stanko K.R.
2025-09-11 13:31:38 +02:00
parent 5c6cad057f
commit 4da69fb69f
7 changed files with 39 additions and 19 deletions
@@ -0,0 +1,13 @@
class Webhooks::ActivationsController < ApplicationController
before_action :set_webhook
def create
@webhook.activate unless @webhook.active?
redirect_to @webhook, status: :see_other
end
private
def set_webhook
@webhook = Webhook.find(params[:webhook_id])
end
end
+1 -1
View File
@@ -46,6 +46,6 @@ class WebhooksController < ApplicationController
end
def webhook_params
params.require(:webhook).permit(:name, :url, :active, subscribed_actions: [])
params.require(:webhook).permit(:name, :url, subscribed_actions: [])
end
end
+4 -2
View File
@@ -31,10 +31,12 @@ class Webhook < ApplicationRecord
normalizes :subscribed_actions, with: ->(value) { Array.wrap(value).map { |e| e.to_s.strip.presence }.uniq & PERMITTED_ACTIONS }
validates :name, presence: true
validates :subscribed_actions, presence: true
validate :validate_url
def activate
update_columns active: true
end
def deactivate
update_columns active: false
end
+1 -1
View File
@@ -19,7 +19,7 @@ class Webhook::Delivery < ApplicationRecord
enum :state, %w[ pending in_progress completed errored ].index_by(&:itself), default: :pending
scope :chronologically, -> { order created_at: :asc, id: :asc }
scope :ordered, -> { order created_at: :desc, id: :desc }
after_create_commit :deliver_later
-5
View File
@@ -11,11 +11,6 @@
<%= form.text_field :name, required: true, autofocus: true, class: "input", placeholder: "Name your Webhook…", data: { action: "keydown.esc@document->form#cancel" } %>
</h2>
<div class="flex flex-column align-start full-width">
<%= form.label :active %>
<%= form.check_box :active %>
</div>
<div class="flex flex-column align-start full-width">
<%= form.label :actions %>
<%= render "webhooks/form/actions", form: form %>
+15 -9
View File
@@ -26,9 +26,11 @@
<%= @webhook.url %>
</div>
<div>
<%= @webhook.active ? "Active" : "Disabled" %>
</div>
<% unless @webhook.active? %>
<div>
<%= button_to "Reactivate", webhook_activation_path(@webhook), method: :post %>
</div>
<% end %>
<div>
<h2 class="margin-none">Secret</h2>
@@ -44,11 +46,15 @@
<div class="flex flex-column gap-half margin-block-end">
<h2 class="margin-none">Subscribed to</h2>
<ul>
<% @webhook.subscribed_actions.each do |action| %>
<li><%= action.humanize %></li>
<% end %>
</ul>
<% if @webhook.subscribed_actions.empty? %>
<p>This Webhook doesn't subscribe to any actions. It will never trigger.<p/>
<% else %>
<ul>
<% @webhook.subscribed_actions.each do |action| %>
<li><%= action.humanize %></li>
<% end %>
</ul>
<% end %>
</div>
<div class="flex flex-column gap-half margin-block-end">
@@ -57,7 +63,7 @@
<p>This Webhook hasn't been triggered yet<p/>
<% else %>
<ul>
<%= render partial: "webhooks/delivery", collection: @webhook.deliveries.chronologically.limit(20), as: :delivery %>
<%= render partial: "webhooks/delivery", collection: @webhook.deliveries.ordered.limit(20), as: :delivery %>
</ul>
<% end %>
</div>
+5 -1
View File
@@ -86,7 +86,11 @@ Rails.application.routes.draw do
resources :stages, module: :workflows
end
resources :webhooks
resources :webhooks do
scope module: "webhooks" do
resource :activation, only: %i[ create ]
end
end
resources :uploads, only: :create
get "/u/*slug" => "uploads#show", as: :upload