mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-27 22:49:02 +08:00
Merge pull request #3629 from artoscinote/ma_SCI_6193
Added optional webhook secret key [SCI-6193]
This commit is contained in:
commit
f11a4701d0
6 changed files with 66 additions and 31 deletions
|
|
@ -71,23 +71,35 @@
|
|||
}
|
||||
|
||||
.webhook-form {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
.webhook-form-row {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
|
||||
.form-group {
|
||||
margin: 0;
|
||||
}
|
||||
.form-group {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.form-text {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.form-text {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.webhook-method-container {
|
||||
margin: .5em;
|
||||
}
|
||||
.webhook-form-trigger-text,
|
||||
.webhook-form-secret-key-text {
|
||||
flex-basis: 120px;
|
||||
}
|
||||
|
||||
.url-input-container {
|
||||
margin: .5em;
|
||||
.webhook-method-container,
|
||||
.webhook-secret-key-container {
|
||||
margin: .5em;
|
||||
}
|
||||
|
||||
.webhook-secret-key-container {
|
||||
flex-basis: 400px;
|
||||
}
|
||||
|
||||
.url-input-container {
|
||||
margin: .5em;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ module Users
|
|||
end
|
||||
|
||||
def webhook_params
|
||||
params.require(:webhook).permit(:http_method, :url, :active)
|
||||
params.require(:webhook).permit(:http_method, :url, :active, :secret_key)
|
||||
end
|
||||
|
||||
def load_filter_elements(filter)
|
||||
|
|
|
|||
|
|
@ -18,11 +18,14 @@ class WebhookService
|
|||
)
|
||||
end
|
||||
|
||||
headers = { 'Content-Type' => 'application/json' }
|
||||
headers['Webhook-Secret-Key'] = @webhook.secret_key if @webhook.secret_key.present?
|
||||
|
||||
response = HTTParty.public_send(
|
||||
@webhook.http_method,
|
||||
@webhook.url,
|
||||
{
|
||||
headers: { 'Content-Type' => 'application/json' },
|
||||
headers: headers,
|
||||
body: @payload.to_json
|
||||
}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,16 +1,27 @@
|
|||
<span class="form-text"><%= t("webhooks.index.webhook_trigger") %></span>
|
||||
<div class="webhook-method-container">
|
||||
<%= f.select :http_method, options_for_select(Webhook.http_methods.map{ |k,_v| [k.upcase, k] }, f.object.http_method) %>
|
||||
<div class="webhook-form-row">
|
||||
<span class="form-text webhook-form-trigger-text"><%= t("webhooks.index.webhook_trigger") %></span>
|
||||
<div class="webhook-method-container">
|
||||
<%= f.select :http_method, options_for_select(Webhook.http_methods.map{ |k,_v| [k.upcase, k] }, f.object.http_method) %>
|
||||
</div>
|
||||
<span class="form-text"><%= t("webhooks.index.target") %></span>
|
||||
<div class="sci-input-container url-input-container form-group">
|
||||
<%= f.text_field :url, class: "sci-input-field url-input", placeholder: t("webhooks.index.url_placeholder"), data: {original_value: f.object.url } %>
|
||||
</div>
|
||||
<button class="btn btn-light cancel-action">
|
||||
<i class="fas fa-times"></i>
|
||||
<%= t('general.cancel') %>
|
||||
</button>
|
||||
<%= f.button class: "btn btn-primary save-webhook" do %>
|
||||
<i class="fas fa-save"></i>
|
||||
<%= t('general.save') %>
|
||||
<% end %>
|
||||
</div>
|
||||
<span class="form-text"><%= t("webhooks.index.target") %></span>
|
||||
<div class="sci-input-container url-input-container form-group">
|
||||
<%= f.text_field :url, class: "sci-input-field url-input", placeholder: t("webhooks.index.url_placeholder"), data: {original_value: f.object.url } %>
|
||||
<div class="webhook-form-row">
|
||||
<span class="form-text webhook-form-secret-key-text"><%= t("webhooks.index.secret_key") %></span>
|
||||
<div class="webhook-secret-key-container">
|
||||
<div class="sci-input-container form-group">
|
||||
<%= f.text_field :secret_key, class: "sci-input-field" %>
|
||||
<small><%= t("webhooks.index.secret_key_hint") %></small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button class="btn btn-light cancel-action">
|
||||
<i class="fas fa-times"></i>
|
||||
<%= t('general.cancel') %>
|
||||
</button>
|
||||
<%= f.button class: "btn btn-primary save-webhook" do %>
|
||||
<i class="fas fa-save"></i>
|
||||
<%= t('general.save') %>
|
||||
<% end %>
|
||||
|
|
|
|||
7
db/migrate/20211103115450_add_secret_key_to_webhooks.rb
Normal file
7
db/migrate/20211103115450_add_secret_key_to_webhooks.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddSecretKeyToWebhooks < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
add_column :webhooks, :secret_key, :string
|
||||
end
|
||||
end
|
||||
|
|
@ -2950,7 +2950,8 @@ CREATE TABLE public.webhooks (
|
|||
created_at timestamp(6) without time zone NOT NULL,
|
||||
updated_at timestamp(6) without time zone NOT NULL,
|
||||
last_error text,
|
||||
text text
|
||||
text text,
|
||||
secret_key character varying
|
||||
);
|
||||
|
||||
|
||||
|
|
@ -7700,6 +7701,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
|||
('20210716124649'),
|
||||
('20210720112050'),
|
||||
('20210811103123'),
|
||||
('20210906132120');
|
||||
('20210906132120'),
|
||||
('20211103115450');
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue