Add CustomWizard class protections and pro feature restrictions
Dieser Commit ist enthalten in:
Ursprung
eff1d2c7d2
Commit
eadc40bdae
6 geänderte Dateien mit 43 neuen und 16 gelöschten Zeilen
|
@ -17,6 +17,7 @@ en:
|
||||||
name_too_short: "'%{name}' is too short for a custom field name (min length is #{min_length})"
|
name_too_short: "'%{name}' is too short for a custom field name (min length is #{min_length})"
|
||||||
name_already_taken: "'%{name}' is already taken as a custom field name"
|
name_already_taken: "'%{name}' is already taken as a custom field name"
|
||||||
save_default: "Failed to save custom field '%{name}'"
|
save_default: "Failed to save custom field '%{name}'"
|
||||||
|
pro_required: "PRO Actions require a PRO Subscription"
|
||||||
|
|
||||||
field:
|
field:
|
||||||
too_short: "%{label} must be at least %{min} characters"
|
too_short: "%{label} must be at least %{min} characters"
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Jobs
|
class CustomWizard::UpdateProSubscription < ::Jobs::Scheduled
|
||||||
class UpdateProSubscription < ::Jobs::Scheduled
|
every 10.minutes
|
||||||
every 1.days
|
|
||||||
|
|
||||||
def execute(args)
|
def execute(args)
|
||||||
CustomWizard::ProSubscription.update
|
CustomWizard::ProSubscription.update
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
|
@ -14,9 +14,15 @@ class CustomWizard::Action
|
||||||
@submission = opts[:submission]
|
@submission = opts[:submission]
|
||||||
@log = []
|
@log = []
|
||||||
@result = CustomWizard::ActionResult.new
|
@result = CustomWizard::ActionResult.new
|
||||||
|
@pro = CustomWizard::Pro.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def perform
|
def perform
|
||||||
|
if pro_actions.include?(action['type']) && !@pro.subscribed?
|
||||||
|
log_error(I18n.t("wizard.custom_field.error.pro_required"))
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
self.send(action['type'].to_sym)
|
self.send(action['type'].to_sym)
|
||||||
end
|
end
|
||||||
|
@ -752,4 +758,8 @@ class CustomWizard::Action
|
||||||
|
|
||||||
CustomWizard::Log.create(log)
|
CustomWizard::Log.create(log)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def pro_actions
|
||||||
|
%w[send_message watch_categories send_to_api create_group create_category]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,13 +22,6 @@ class CustomWizard::Builder
|
||||||
@sorted_handlers.sort_by! { |h| -h[:priority] }
|
@sorted_handlers.sort_by! { |h| -h[:priority] }
|
||||||
end
|
end
|
||||||
|
|
||||||
def mapper
|
|
||||||
CustomWizard::Mapper.new(
|
|
||||||
user: @wizard.user,
|
|
||||||
data: @wizard.current_submission&.fields_and_meta
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
def build(build_opts = {}, params = {})
|
def build(build_opts = {}, params = {})
|
||||||
return nil if !SiteSetting.custom_wizard_enabled || !@wizard
|
return nil if !SiteSetting.custom_wizard_enabled || !@wizard
|
||||||
return @wizard if !@wizard.can_access? && !build_opts[:force]
|
return @wizard if !@wizard.can_access? && !build_opts[:force]
|
||||||
|
@ -80,6 +73,15 @@ class CustomWizard::Builder
|
||||||
@wizard
|
@wizard
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def mapper
|
||||||
|
CustomWizard::Mapper.new(
|
||||||
|
user: @wizard.user,
|
||||||
|
data: @wizard.current_submission&.fields_and_meta
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
def append_field(step, step_template, field_template, build_opts)
|
def append_field(step, step_template, field_template, build_opts)
|
||||||
params = {
|
params = {
|
||||||
id: field_template['id'],
|
id: field_template['id'],
|
||||||
|
@ -224,7 +226,10 @@ class CustomWizard::Builder
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_condition(template)
|
def check_condition(template)
|
||||||
return false unless @pro.subscribed?
|
unless @pro.subscribed?
|
||||||
|
CustomWizard::Log.create(I18n.t("wizard.custom_field.error.pro_required"))
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
if template['condition'].present?
|
if template['condition'].present?
|
||||||
result = CustomWizard::Mapper.new(
|
result = CustomWizard::Mapper.new(
|
||||||
|
|
|
@ -38,14 +38,15 @@ class CustomWizard::ProSubscription
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.update
|
def self.update
|
||||||
@subscribed = nil
|
|
||||||
auth = CustomWizard::ProAuthentication.new
|
auth = CustomWizard::ProAuthentication.new
|
||||||
subscription = self.new
|
subscription = self.new
|
||||||
|
|
||||||
if auth.active?
|
if auth.active?
|
||||||
response = Excon.get(
|
response = Excon.get(
|
||||||
"https://#{SUBSCRIPTION_SERVER}/subscription-server/user-subscriptions/#{SUBSCRIPTION_TYPE}/#{CLIENT_NAME}",
|
"https://#{SUBSCRIPTION_SERVER}/subscription-server/user-subscriptions/#{SUBSCRIPTION_TYPE}/#{CLIENT_NAME}",
|
||||||
headers: { "User-Api-Key" => auth.api_key }
|
headers: {
|
||||||
|
"User-Api-Key" => auth.api_key
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
if response.status == 200
|
if response.status == 200
|
||||||
|
|
12
plugin.rb
12
plugin.rb
|
@ -126,6 +126,18 @@ after_initialize do
|
||||||
|
|
||||||
Liquid::Template.register_filter(::CustomWizard::LiquidFilter::FirstNonEmpty)
|
Liquid::Template.register_filter(::CustomWizard::LiquidFilter::FirstNonEmpty)
|
||||||
|
|
||||||
|
class CustomWizard::UnpermittedOverride < StandardError; end
|
||||||
|
|
||||||
|
CustomWizard.constants.each do |class_name|
|
||||||
|
klass = CustomWizard.const_get(class_name)
|
||||||
|
next if !klass.is_a?(Class) || klass.superclass.name.to_s.split("::").first == 'CustomWizard'
|
||||||
|
|
||||||
|
klass.define_singleton_method(:prepend) { |klass| raise CustomWizard::UnpermittedOverride.new }
|
||||||
|
klass.define_singleton_method(:include) { |klass| raise CustomWizard::UnpermittedOverride.new }
|
||||||
|
klass.define_singleton_method(:define_method) { |name, &block| raise CustomWizard::UnpermittedOverride.new }
|
||||||
|
klass.define_singleton_method(:define_singleton_method) { |name, &block| raise CustomWizard::UnpermittedOverride.new }
|
||||||
|
end
|
||||||
|
|
||||||
add_class_method(:wizard, :user_requires_completion?) do |user|
|
add_class_method(:wizard, :user_requires_completion?) do |user|
|
||||||
wizard_result = self.new(user).requires_completion?
|
wizard_result = self.new(user).requires_completion?
|
||||||
return wizard_result if wizard_result
|
return wizard_result if wizard_result
|
||||||
|
|
Laden …
In neuem Issue referenzieren