Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-22 09:20:29 +01:00
Add pro restriction
Dieser Commit ist enthalten in:
Ursprung
a7904a28af
Commit
f49f516403
11 geänderte Dateien mit 84 neuen und 30 gelöschten Zeilen
|
@ -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);
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -213,9 +213,11 @@
|
||||||
{{#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 full field-mapper-setting pro">
|
||||||
<div class="setting-label">
|
<div class="setting-label">
|
||||||
<label>{{i18n "admin.wizard.condition"}}</label>
|
<label>{{i18n "admin.wizard.condition"}}</label>
|
||||||
|
<span class="pro-label">{{i18n "admin.wizard.pro.label"}}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="setting-value">
|
<div class="setting-value">
|
||||||
|
@ -224,6 +226,7 @@
|
||||||
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">
|
||||||
|
|
|
@ -38,9 +38,11 @@
|
||||||
{{#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 full field-mapper-setting pro">
|
||||||
<div class="setting-label">
|
<div class="setting-label">
|
||||||
<label>{{i18n "admin.wizard.condition"}}</label>
|
<label>{{i18n "admin.wizard.condition"}}</label>
|
||||||
|
<span class="pro-label">{{i18n "admin.wizard.pro.label"}}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="setting-value">
|
<div class="setting-value">
|
||||||
|
@ -58,6 +60,7 @@
|
||||||
<span>{{i18n "admin.wizard.step.force_final.description"}}</span>
|
<span>{{i18n "admin.wizard.step.force_final.description"}}</span>
|
||||||
</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">
|
||||||
|
@ -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}}
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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."
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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'],
|
||||||
|
|
|
@ -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
|
|
@ -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])
|
||||||
|
|
Laden …
In neuem Issue referenzieren