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

Refactor redirect logic and update not_permitted text

Dieser Commit ist enthalten in:
Angus McLeod 2018-07-06 10:58:53 +10:00
Ursprung c098a24cb3
Commit b71ec64a9f
6 geänderte Dateien mit 39 neuen und 33 gelöschten Zeilen

Datei anzeigen

@ -2,7 +2,7 @@
{{wizard-no-access text=(i18n 'wizard.completed') wizardId=wizardId}}
{{else}}
{{#if notPermitted}}
{{wizard-no-access text=(i18n 'wizard.completed' level=minTrust) wizardId=wizardId}}
{{wizard-no-access text=(i18n 'wizard.not_permitted' level=minTrust) wizardId=wizardId}}
{{/if}}
{{#if noWizard}}
{{wizard-no-access text=(i18n 'wizard.none') wizardId=wizardId}}

Datei anzeigen

@ -41,8 +41,8 @@ class CustomWizard::WizardController < ::ApplicationController
wizard_id = params[:wizard_id]
user = current_user
wizard_data = PluginStore.get('custom_wizard', wizard_id.underscore)
wizard = CustomWizard::Wizard.new(user, wizard_data)
wizard_template = PluginStore.get('custom_wizard', wizard_id.underscore)
wizard = CustomWizard::Wizard.new(user, wizard_template)
if wizard.required && !wizard.completed? && wizard.permitted?
return render json: { error: I18n.t('wizard.no_skip') }

Datei anzeigen

@ -3,11 +3,13 @@ module Jobs
def execute(args)
if CustomWizard::Wizard.find(args[:wizard_id])
user_ids = []
User.human_users.each do |u|
u.custom_fields['redirect_to_wizard'] = args[:wizard_id]
u.save_custom_fields(true)
user_ids.push(u.id)
User.human_users.each do |user|
if CustomWizard::Wizard.set_wizard_redirect(user, args[:wizard_id])
user_ids.push(user.id)
end
end
MessageBus.publish "/redirect_to_wizard", args[:wizard_id], user_ids: user_ids
end
end

Datei anzeigen

@ -168,10 +168,25 @@ class CustomWizard::Wizard
end
def self.find(wizard_id)
PluginStoreRow.find_by(plugin_name: 'custom_wizard', key: wizard_id)
PluginStore.get('custom_wizard', wizard_id)
end
def self.set_redirect(user, wizard_id, url)
def self.create(user, wizard_id)
CustomWizard::Wizard.new(user, self.find(wizard_id).to_h)
end
def self.set_submission_redirect(user, wizard_id, url)
PluginStore.set("#{wizard_id.underscore}_submissions", user.id, [{ redirect_to: url }])
end
def self.set_wizard_redirect(user, wizard_id)
wizard = CustomWizard::Wizard.create(user, wizard_id)
if wizard.permitted?
user.custom_fields['redirect_to_wizard'] = wizard_id
user.save_custom_fields(true)
else
false
end
end
end

Datei anzeigen

@ -7,27 +7,17 @@ require_dependency 'wizard/step'
wizard_result = self.new(user).requires_completion?
return wizard_result if wizard_result
custom_redirect = nil
custom_redirect = false
if user && wizard_id = CustomWizard::Wizard.after_signup
custom_redirect = wizard_id
wizard = CustomWizard::Wizard.create(user, wizard_id)
wizard = CustomWizard::Wizard.new(user, id: wizard_id)
data = PluginStore.get('custom_wizard', wizard_id)
if data['required']
user.custom_fields['redirect_to_wizard'] = wizard_id
user.save_custom_fields(true)
end
if CustomWizard::Wizard.new(user, id: wizard_id).completed?
custom_redirect = nil
if !wizard.completed? && wizard.permitted?
custom_redirect = true
CustomWizard::Wizard.set_wizard_redirect(user, wizard_id)
end
end
$redis.set('custom_wizard_redirect', custom_redirect)
!!custom_redirect
end
end

Datei anzeigen

@ -75,7 +75,7 @@ after_initialize do
::UsersController.class_eval do
def wizard_path
if custom_wizard_redirect = $redis.get('custom_wizard_redirect')
if custom_wizard_redirect = current_user.custom_fields['redirect_to_wizard']
"#{Discourse.base_url}/w/#{custom_wizard_redirect.dasherize}"
else
"#{Discourse.base_url}/wizard"
@ -86,10 +86,10 @@ after_initialize do
module InvitesControllerCustomWizard
def path(url)
if Wizard.user_requires_completion?(@user)
wizard_id = $redis.get('custom_wizard_redirect')
wizard_id = @user.custom_fields['custom_wizard_redirect']
if wizard_id && url != '/'
CustomWizard::Wizard.set_redirect(@user, wizard_id, url)
CustomWizard::Wizard.set_submission_redirect(@user, wizard_id, url)
url = "/w/#{wizard_id.dasherize}"
end
end
@ -111,16 +111,16 @@ after_initialize do
before_action :redirect_to_wizard_if_required, if: :current_user
def redirect_to_wizard_if_required
@wizard_id ||= current_user.custom_fields['redirect_to_wizard']
wizard_id = current_user.custom_fields['redirect_to_wizard']
@excluded_routes ||= SiteSetting.wizard_redirect_exclude_paths.split('|') + ['/w/']
url = request.referer || request.original_url
if request.format === 'text/html' && !@excluded_routes.any? { |str| /#{str}/ =~ url } && @wizard_id
if request.format === 'text/html' && !@excluded_routes.any? { |str| /#{str}/ =~ url } && wizard_id
if request.referer !~ /\/w\// && request.referer !~ /\/invites\//
CustomWizard::Wizard.set_redirect(current_user, @wizard_id, request.referer)
CustomWizard::Wizard.set_submission_redirect(current_user, wizard_id, request.referer)
end
redirect_to "/w/#{@wizard_id.dasherize}"
redirect_to "/w/#{wizard_id.dasherize}"
end
end
end
@ -148,8 +148,7 @@ after_initialize do
DiscourseEvent.on(:user_approved) do |user|
if wizard_id = CustomWizard::Wizard.after_signup
user.custom_fields['redirect_to_wizard'] = wizard_id
user.save_custom_fields(true)
CustomWizard::Wizard.set_wizard_redirect(user, wizard_id)
end
end