0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-25 18:50:27 +01:00

Add pro restriction

Dieser Commit ist enthalten in:
angusmcleod 2021-08-10 17:00:42 +08:00
Ursprung a7904a28af
Commit f49f516403
11 geänderte Dateien mit 84 neuen und 30 gelöschten Zeilen

Datei anzeigen

@ -39,6 +39,7 @@ export default DiscourseRoute.extend({
currentStep: wizard.steps[0], currentStep: wizard.steps[0],
currentAction: wizard.actions[0], currentAction: wizard.actions[0],
creating: model.create, creating: model.create,
proSubscribed: parentModel.pro_subscribed
}; };
controller.setProperties(props); controller.setProperties(props);

Datei anzeigen

@ -166,7 +166,8 @@
wizard=wizard wizard=wizard
currentField=currentField currentField=currentField
wizardFields=wizardFields wizardFields=wizardFields
fieldTypes=fieldTypes}} fieldTypes=fieldTypes
proSubscribed=proSubscribed}}
{{/if}} {{/if}}
{{wizard-links {{wizard-links

Datei anzeigen

@ -213,17 +213,20 @@
{{#if field.showAdvanced}} {{#if field.showAdvanced}}
<div class="advanced-settings"> <div class="advanced-settings">
<div class="setting full field-mapper-setting"> {{#if proSubscribed}}
<div class="setting-label"> <div class="setting full field-mapper-setting pro">
<label>{{i18n "admin.wizard.condition"}}</label> <div class="setting-label">
</div> <label>{{i18n "admin.wizard.condition"}}</label>
<span class="pro-label">{{i18n "admin.wizard.pro.label"}}</span>
</div>
<div class="setting-value"> <div class="setting-value">
{{wizard-mapper {{wizard-mapper
inputs=field.condition inputs=field.condition
options=fieldConditionOptions}} options=fieldConditionOptions}}
</div>
</div> </div>
</div> {{/if}}
<div class="setting full field-mapper-setting"> <div class="setting full field-mapper-setting">
<div class="setting-label"> <div class="setting-label">

Datei anzeigen

@ -38,26 +38,29 @@
{{#if step.showAdvanced}} {{#if step.showAdvanced}}
<div class="advanced-settings"> <div class="advanced-settings">
<div class="setting full field-mapper-setting"> {{#if proSubscribed}}
<div class="setting-label"> <div class="setting full field-mapper-setting pro">
<label>{{i18n "admin.wizard.condition"}}</label> <div class="setting-label">
<label>{{i18n "admin.wizard.condition"}}</label>
<span class="pro-label">{{i18n "admin.wizard.pro.label"}}</span>
</div>
<div class="setting-value">
{{wizard-mapper
inputs=step.condition
options=stepConditionOptions}}
</div>
</div> </div>
<div class="setting-value"> <div class="setting full">
{{wizard-mapper <div class="setting-label"></div>
inputs=step.condition <div class="setting-value force-final">
options=stepConditionOptions}} <h4>{{i18n "admin.wizard.step.force_final.label"}}</h4>
{{input type="checkbox" checked=step.force_final}}
<span>{{i18n "admin.wizard.step.force_final.description"}}</span>
</div>
</div> </div>
</div> {{/if}}
<div class="setting full">
<div class="setting-label"></div>
<div class="setting-value force-final">
<h4>{{i18n "admin.wizard.step.force_final.label"}}</h4>
{{input type="checkbox" checked=step.force_final}}
<span>{{i18n "admin.wizard.step.force_final.description"}}</span>
</div>
</div>
<div class="setting full field-mapper-setting"> <div class="setting full field-mapper-setting">
<div class="setting-label"> <div class="setting-label">
@ -129,5 +132,6 @@
currentFieldId=currentField.id currentFieldId=currentField.id
fieldTypes=fieldTypes fieldTypes=fieldTypes
removeField="removeField" removeField="removeField"
wizardFields=wizardFields}} wizardFields=wizardFields
proSubscribed=proSubscribed}}
{{/each}} {{/each}}

Datei anzeigen

@ -372,6 +372,22 @@
.setting-gutter { .setting-gutter {
margin-top: 5px; margin-top: 5px;
} }
&.pro {
.setting-label {
display: flex;
flex-direction: column;
label {
margin: 0;
}
}
.pro-label {
color: $tertiary;
font-size: .75em;
}
}
} }
.advanced-settings { .advanced-settings {

Datei anzeigen

@ -436,6 +436,7 @@ en:
pro: pro:
nav_label: PRO nav_label: PRO
label: PRO
title: Custom Wizard PRO title: Custom Wizard PRO
authorize: Authorize authorize: Authorize
authorized: Authorized authorized: Authorized

Datei anzeigen

@ -49,6 +49,7 @@ en:
required: "%{property} is required" required: "%{property} is required"
conflict: "Wizard with id '%{wizard_id}' already exists" conflict: "Wizard with id '%{wizard_id}' already exists"
after_time: "After time setting is invalid" after_time: "After time setting is invalid"
pro: "%{property} is PRO only"
site_settings: site_settings:
custom_wizard_enabled: "Enable custom wizards." custom_wizard_enabled: "Enable custom wizards."

Datei anzeigen

@ -10,7 +10,8 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController
), ),
field_types: CustomWizard::Field.types, field_types: CustomWizard::Field.types,
realtime_validations: CustomWizard::RealtimeValidation.types, realtime_validations: CustomWizard::RealtimeValidation.types,
custom_fields: custom_field_list custom_fields: custom_field_list,
pro_subscribed: CustomWizard::Pro.subscribed?
) )
end end

Datei anzeigen

@ -6,6 +6,7 @@ class CustomWizard::Builder
@template = CustomWizard::Template.create(wizard_id) @template = CustomWizard::Template.create(wizard_id)
return nil if @template.nil? return nil if @template.nil?
@wizard = CustomWizard::Wizard.new(template.data, user) @wizard = CustomWizard::Wizard.new(template.data, user)
@pro = CustomWizard::Pro.new
end end
def self.sorted_handlers def self.sorted_handlers
@ -222,6 +223,8 @@ class CustomWizard::Builder
end end
def check_condition(template) def check_condition(template)
return false unless @pro.subscribed?
if template['condition'].present? if template['condition'].present?
result = CustomWizard::Mapper.new( result = CustomWizard::Mapper.new(
inputs: template['condition'], inputs: template['condition'],

Datei anzeigen

@ -18,4 +18,8 @@ class CustomWizard::Pro
def subscribed? def subscribed?
@subscription.active? @subscription.active?
end end
def self.subscribed?
self.new.subscribed?
end
end end

Datei anzeigen

@ -6,6 +6,7 @@ class CustomWizard::TemplateValidator
def initialize(data, opts = {}) def initialize(data, opts = {})
@data = data @data = data
@opts = opts @opts = opts
@pro = CustomWizard::Pro.new
end end
def perform def perform
@ -14,12 +15,15 @@ class CustomWizard::TemplateValidator
check_id(data, :wizard) check_id(data, :wizard)
check_required(data, :wizard) check_required(data, :wizard)
validate_after_time validate_after_time
validate_pro(data, :wizard)
data[:steps].each do |step| data[:steps].each do |step|
check_required(step, :step) check_required(step, :step)
validate_pro(step, :step)
if data[:fields].present? if data[:fields].present?
data[:fields].each do |field| data[:fields].each do |field|
validate_pro(field, :field)
check_required(field, :field) check_required(field, :field)
end end
end end
@ -47,6 +51,13 @@ class CustomWizard::TemplateValidator
} }
end end
def self.pro
{
step: ['condition'],
field: ['conition']
}
end
private private
def check_required(object, type) def check_required(object, type)
@ -57,6 +68,14 @@ class CustomWizard::TemplateValidator
end end
end end
def validate_pro(object, type)
CustomWizard::TemplateValidator.required[type].each do |property|
if object[property].present? && !@pro.subscribed?
errors.add :base, I18n.t("wizard.validation.pro", property: property)
end
end
end
def check_id(object, type) def check_id(object, type)
if type === :wizard && @opts[:create] && CustomWizard::Template.exists?(object[:id]) if type === :wizard && @opts[:create] && CustomWizard::Template.exists?(object[:id])
errors.add :base, I18n.t("wizard.validation.conflict", wizard_id: object[:id]) errors.add :base, I18n.t("wizard.validation.conflict", wizard_id: object[:id])