diff --git a/assets/javascripts/discourse/components/wizard-mapper-selector.js.es6 b/assets/javascripts/discourse/components/wizard-mapper-selector.js.es6 index e2899c2f..b92ab4de 100644 --- a/assets/javascripts/discourse/components/wizard-mapper-selector.js.es6 +++ b/assets/javascripts/discourse/components/wizard-mapper-selector.js.es6 @@ -72,6 +72,8 @@ export default Component.extend({ return type ? I18n.t(`admin.wizard.selector.label.${snakeCase(type)}`) : null; }, + comboBoxAllowAny: alias('showWizardField'), + @discourseComputed('activeType') comboBoxContent(activeType) { const controller = getOwner(this).lookup('controller:admin-wizards-wizard-show'); diff --git a/assets/javascripts/discourse/templates/components/wizard-mapper-selector.hbs b/assets/javascripts/discourse/templates/components/wizard-mapper-selector.hbs index 8f442dfc..c86d2a7d 100644 --- a/assets/javascripts/discourse/templates/components/wizard-mapper-selector.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-mapper-selector.hbs @@ -35,6 +35,7 @@ onChange=(action "changeValue") options=(hash none=placeholderKey + allowAny=comboBoxAllowAny )}} {{/if}} diff --git a/extensions/invites_controller.rb b/extensions/invites_controller.rb index fdba7723..caa3a976 100644 --- a/extensions/invites_controller.rb +++ b/extensions/invites_controller.rb @@ -1,7 +1,7 @@ module InvitesControllerCustomWizard def path(url) if ::Wizard.user_requires_completion?(@user) - wizard_id = @user.custom_fields['custom_wizard_redirect'] + wizard_id = @user.custom_fields['redirect_to_wizard'] if wizard_id && url != '/' CustomWizard::Wizard.set_submission_redirect(@user, wizard_id, url) diff --git a/lib/custom_wizard/builder.rb b/lib/custom_wizard/builder.rb index aaa00470..c04f11b1 100644 --- a/lib/custom_wizard/builder.rb +++ b/lib/custom_wizard/builder.rb @@ -187,7 +187,8 @@ class CustomWizard::Builder if updater.errors.empty? if final_step - updater.result[:redirect_on_complete] = route_to || data['redirect_on_complete'] + redirect_url = route_to || data['redirect_on_complete'] || data["redirect_to"] + updater.result[:redirect_on_complete] = redirect_url elsif route_to updater.result[:redirect_on_next] = route_to end diff --git a/lib/custom_wizard/mapper.rb b/lib/custom_wizard/mapper.rb index cb1663d9..3931bd11 100644 --- a/lib/custom_wizard/mapper.rb +++ b/lib/custom_wizard/mapper.rb @@ -15,7 +15,11 @@ class CustomWizard::Mapper greater_or_equal: '>=', less_or_equal: '<=', regex: '=~', - boolean: '==' + boolean: { + present: "present?", + true: "==", + false: "==" + } } def initialize(params) @@ -90,9 +94,8 @@ class CustomWizard::Mapper operator = map_operator(connector) key = map_field(pair['key'], pair['key_type']) value = cast_value(map_field(pair['value'], pair['value_type']), key, connector) - begin - cast_result(key.public_send(operator, value), connector) + validation_result(key, value, operator) rescue NoMethodError # end @@ -102,8 +105,6 @@ class CustomWizard::Mapper def cast_value(value, key, connector) if connector == 'regex' Regexp.new(value) - elsif connector == 'boolean' - ActiveRecord::Type::Boolean.new.cast(value) else if key.is_a?(String) value.to_s @@ -115,8 +116,20 @@ class CustomWizard::Mapper end end - def cast_result(result, connector) - if connector == 'regex' + def validation_result(key, value, operator) + result = nil + + if operator.is_a?(Hash) && (operator = operator[value.to_sym]).present? + if value == "present" + result = key.public_send(operator) + elsif ["true", "false"].include?(value) + result = key.public_send(operator, ActiveRecord::Type::Boolean.new.cast(value)) + end + else + result = key.public_send(operator, value) + end + + if operator == '=~' result == 0 ? true : false else result