mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-24 08:43:13 +08:00
Add configuration variable for webhooks, disable by default [SCI-6031]
This commit is contained in:
parent
295d27f0d7
commit
d67f7691a1
5 changed files with 14 additions and 2 deletions
|
@ -74,7 +74,8 @@ class Activity < ApplicationRecord
|
|||
breadcrumbs: {}
|
||||
)
|
||||
|
||||
after_create ->(activity) { Activities::DispatchWebhooksJob.perform_later(activity) }
|
||||
after_create ->(activity) { Activities::DispatchWebhooksJob.perform_later(activity) },
|
||||
if: -> { Rails.application.config.x.webhooks_enabled }
|
||||
|
||||
def self.activity_types_list
|
||||
activity_list = type_ofs.map do |key, value|
|
||||
|
|
|
@ -6,12 +6,19 @@ class Webhook < ApplicationRecord
|
|||
belongs_to :activity_filter
|
||||
validates :http_method, presence: true
|
||||
validates :url, presence: true
|
||||
validate :enabled?
|
||||
validate :valid_url
|
||||
|
||||
scope :active, -> { where(active: true) }
|
||||
|
||||
private
|
||||
|
||||
def enabled?
|
||||
unless Rails.application.config.x.webhooks_enabled
|
||||
errors.add(:configuration, I18n.t('activerecord.errors.models.webhook.attributes.configuration.disabled'))
|
||||
end
|
||||
end
|
||||
|
||||
def valid_url
|
||||
unless /\A#{URI::DEFAULT_PARSER.make_regexp(%w(http https))}\z/.match?(url)
|
||||
errors.add(:url, I18n.t('activerecord.errors.models.webhook.attributes.url.not_valid'))
|
||||
|
|
|
@ -14,7 +14,7 @@ module Organization
|
|||
end
|
||||
|
||||
can :create_acitivity_filters do
|
||||
true
|
||||
Rails.application.config.x.webhooks_enabled
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -40,6 +40,8 @@ module Scinote
|
|||
# Max uploaded file size in MB
|
||||
config.x.file_max_size_mb = (ENV['FILE_MAX_SIZE_MB'] || 50).to_i
|
||||
|
||||
config.x.webhooks_enabled = ENV['ENABLE_WEBHOOKS'] == 'true'
|
||||
|
||||
# Logging
|
||||
config.log_formatter = proc do |severity, datetime, progname, msg|
|
||||
"[#{datetime}] #{severity}: #{msg}\n"
|
||||
|
|
|
@ -148,6 +148,8 @@ en:
|
|||
per_column_limit: "Too many items in the column"
|
||||
webhook:
|
||||
attributes:
|
||||
configuration:
|
||||
disabled: 'Webhooks are disabled'
|
||||
url:
|
||||
not_valid: 'Not valid URL'
|
||||
|
||||
|
|
Loading…
Reference in a new issue