1
0
Fork 0

FIX: make invite topic redirects work and allow them to be used in conditional route_tos

Dieser Commit ist enthalten in:
Angus McLeod 2020-05-01 18:16:58 +10:00
Ursprung e257d60c86
Commit 379e839b71
5 geänderte Dateien mit 26 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -72,6 +72,8 @@ export default Component.extend({
return type ? I18n.t(`admin.wizard.selector.label.${snakeCase(type)}`) : null; return type ? I18n.t(`admin.wizard.selector.label.${snakeCase(type)}`) : null;
}, },
comboBoxAllowAny: alias('showWizardField'),
@discourseComputed('activeType') @discourseComputed('activeType')
comboBoxContent(activeType) { comboBoxContent(activeType) {
const controller = getOwner(this).lookup('controller:admin-wizards-wizard-show'); const controller = getOwner(this).lookup('controller:admin-wizards-wizard-show');

Datei anzeigen

@ -35,6 +35,7 @@
onChange=(action "changeValue") onChange=(action "changeValue")
options=(hash options=(hash
none=placeholderKey none=placeholderKey
allowAny=comboBoxAllowAny
)}} )}}
{{/if}} {{/if}}

Datei anzeigen

@ -1,7 +1,7 @@
module InvitesControllerCustomWizard module InvitesControllerCustomWizard
def path(url) def path(url)
if ::Wizard.user_requires_completion?(@user) 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 != '/' if wizard_id && url != '/'
CustomWizard::Wizard.set_submission_redirect(@user, wizard_id, url) CustomWizard::Wizard.set_submission_redirect(@user, wizard_id, url)

Datei anzeigen

@ -187,7 +187,8 @@ class CustomWizard::Builder
if updater.errors.empty? if updater.errors.empty?
if final_step 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 elsif route_to
updater.result[:redirect_on_next] = route_to updater.result[:redirect_on_next] = route_to
end end

Datei anzeigen

@ -15,7 +15,11 @@ class CustomWizard::Mapper
greater_or_equal: '>=', greater_or_equal: '>=',
less_or_equal: '<=', less_or_equal: '<=',
regex: '=~', regex: '=~',
boolean: '==' boolean: {
present: "present?",
true: "==",
false: "=="
}
} }
def initialize(params) def initialize(params)
@ -90,9 +94,8 @@ class CustomWizard::Mapper
operator = map_operator(connector) operator = map_operator(connector)
key = map_field(pair['key'], pair['key_type']) key = map_field(pair['key'], pair['key_type'])
value = cast_value(map_field(pair['value'], pair['value_type']), key, connector) value = cast_value(map_field(pair['value'], pair['value_type']), key, connector)
begin begin
cast_result(key.public_send(operator, value), connector) validation_result(key, value, operator)
rescue NoMethodError rescue NoMethodError
# #
end end
@ -102,8 +105,6 @@ class CustomWizard::Mapper
def cast_value(value, key, connector) def cast_value(value, key, connector)
if connector == 'regex' if connector == 'regex'
Regexp.new(value) Regexp.new(value)
elsif connector == 'boolean'
ActiveRecord::Type::Boolean.new.cast(value)
else else
if key.is_a?(String) if key.is_a?(String)
value.to_s value.to_s
@ -115,8 +116,20 @@ class CustomWizard::Mapper
end end
end end
def cast_result(result, connector) def validation_result(key, value, operator)
if connector == 'regex' 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 result == 0 ? true : false
else else
result result