From 47722d13a3e3482d8084c7c77b00cdda0a596a72 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Sun, 19 Apr 2020 16:42:44 +1000 Subject: [PATCH] after_signup on approval fixes --- lib/custom_wizard/wizard.rb | 18 +++++++++--------- plugin.rb | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/custom_wizard/wizard.rb b/lib/custom_wizard/wizard.rb index 2fd521ab..80d8726e 100644 --- a/lib/custom_wizard/wizard.rb +++ b/lib/custom_wizard/wizard.rb @@ -45,9 +45,9 @@ class CustomWizard::Wizard @needs_categories = false @needs_groups = false @theme_id = attrs['theme_id'] - - if attrs['theme'] - theme = Theme.find_by(name: attrs['theme']) + + if attrs['theme'].present? + theme = ::Theme.find_by(name: attrs['theme']) @theme_id = theme.id if theme end @@ -210,14 +210,14 @@ class CustomWizard::Wizard records .sort_by { |record| record.value['permitted'].present? ? 0 : 1 } .each do |record| - wizard = CustomWizard::Wizard.new(JSON.parse(record.value), user) - + wizard = self.new(JSON.parse(record.value), user) + if wizard.permitted? result = wizard break end end - + result else false @@ -344,7 +344,7 @@ class CustomWizard::Wizard def self.create(wizard_id, user = nil) if wizard = self.find(wizard_id) - CustomWizard::Wizard.new(wizard.to_h, user) + self.new(wizard.to_h, user) else false end @@ -355,8 +355,8 @@ class CustomWizard::Wizard end def self.set_wizard_redirect(wizard_id, user) - wizard = CustomWizard::Wizard.create(wizard_id, user) - + wizard = self.create(wizard_id, user) + if wizard.permitted? user.custom_fields['redirect_to_wizard'] = wizard_id user.save_custom_fields(true) diff --git a/plugin.rb b/plugin.rb index a8d81b14..f34eae64 100644 --- a/plugin.rb +++ b/plugin.rb @@ -118,8 +118,8 @@ after_initialize do end on(:user_approved) do |user| - if wizard_id = CustomWizard::Wizard.after_signup(user) - CustomWizard::Wizard.set_wizard_redirect(wizard_id, user) + if wizard = CustomWizard::Wizard.after_signup(user) + CustomWizard::Wizard.set_wizard_redirect(wizard.id, user) end end