2021-03-11 07:30:15 +01:00
|
|
|
# frozen_string_literal: true
|
2024-10-16 13:52:03 +02:00
|
|
|
require_dependency "wizard/step"
|
|
|
|
require_dependency "wizard/field"
|
|
|
|
require_dependency "wizard/step_updater"
|
|
|
|
require_dependency "wizard/builder"
|
2017-10-15 05:58:22 +02:00
|
|
|
|
2017-09-23 04:34:07 +02:00
|
|
|
class CustomWizard::Wizard
|
2019-12-12 05:43:11 +01:00
|
|
|
include ActiveModel::SerializerSupport
|
2017-09-23 04:34:07 +02:00
|
|
|
|
2017-11-01 05:21:14 +01:00
|
|
|
attr_accessor :id,
|
|
|
|
:name,
|
|
|
|
:background,
|
2020-04-13 14:17:22 +02:00
|
|
|
:theme_id,
|
2017-11-01 05:21:14 +01:00
|
|
|
:save_submissions,
|
|
|
|
:multiple_submissions,
|
|
|
|
:after_time,
|
2018-05-09 07:06:43 +02:00
|
|
|
:after_time_scheduled,
|
2024-10-17 16:15:25 +02:00
|
|
|
:after_time_group_names,
|
2017-11-01 05:21:14 +01:00
|
|
|
:after_signup,
|
2017-11-22 10:34:21 +01:00
|
|
|
:required,
|
2019-11-04 18:49:30 +01:00
|
|
|
:prompt_completion,
|
2019-12-12 05:43:11 +01:00
|
|
|
:restart_on_revisit,
|
2021-09-22 10:22:05 +02:00
|
|
|
:resume_on_revisit,
|
2020-03-30 08:16:03 +02:00
|
|
|
:permitted,
|
2020-04-13 14:17:22 +02:00
|
|
|
:steps,
|
2020-10-31 08:05:50 +01:00
|
|
|
:step_ids,
|
2021-06-23 08:13:58 +02:00
|
|
|
:field_ids,
|
2021-04-20 19:58:19 +02:00
|
|
|
:first_step,
|
|
|
|
:start,
|
2020-04-13 14:17:22 +02:00
|
|
|
:actions,
|
2021-06-23 08:13:58 +02:00
|
|
|
:action_ids,
|
2021-06-17 09:50:22 +02:00
|
|
|
:user,
|
2023-01-18 19:53:36 +01:00
|
|
|
:guest_id,
|
2021-07-21 05:31:03 +02:00
|
|
|
:template
|
2017-10-15 05:58:22 +02:00
|
|
|
|
2024-10-16 13:52:03 +02:00
|
|
|
attr_reader :all_step_ids
|
2024-10-16 14:18:23 +02:00
|
|
|
attr_writer :submissions
|
2021-06-23 08:13:58 +02:00
|
|
|
|
2023-01-18 19:53:36 +01:00
|
|
|
GUEST_ID_PREFIX ||= "guest"
|
2023-02-07 12:46:17 +01:00
|
|
|
GUEST_GROUP_ID = -1
|
2023-01-18 19:53:36 +01:00
|
|
|
|
|
|
|
def initialize(attrs = {}, user = nil, guest_id = nil)
|
|
|
|
if user
|
|
|
|
@user = user
|
|
|
|
elsif guest_id
|
|
|
|
@guest_id = guest_id
|
|
|
|
end
|
|
|
|
|
2020-11-03 01:24:20 +01:00
|
|
|
attrs = attrs.with_indifferent_access
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2024-10-16 13:52:03 +02:00
|
|
|
@id = attrs["id"]
|
|
|
|
@name = attrs["name"]
|
|
|
|
@background = attrs["background"]
|
|
|
|
@save_submissions = cast_bool(attrs["save_submissions"])
|
|
|
|
@multiple_submissions = cast_bool(attrs["multiple_submissions"])
|
|
|
|
@prompt_completion = cast_bool(attrs["prompt_completion"])
|
|
|
|
@restart_on_revisit = cast_bool(attrs["restart_on_revisit"])
|
|
|
|
@resume_on_revisit = cast_bool(attrs["resume_on_revisit"])
|
|
|
|
@after_signup = cast_bool(attrs["after_signup"])
|
|
|
|
@after_time = cast_bool(attrs["after_time"])
|
|
|
|
@after_time_scheduled = attrs["after_time_scheduled"]
|
2024-10-17 16:15:25 +02:00
|
|
|
@after_time_group_names = attrs["after_time_groups"]
|
2024-10-16 13:52:03 +02:00
|
|
|
@required = cast_bool(attrs["required"])
|
|
|
|
@permitted = attrs["permitted"] || nil
|
|
|
|
@theme_id = attrs["theme_id"]
|
|
|
|
|
|
|
|
if attrs["theme"].present?
|
|
|
|
theme = ::Theme.find_by(name: attrs["theme"])
|
2020-04-13 14:17:22 +02:00
|
|
|
@theme_id = theme.id if theme
|
2017-11-01 05:21:14 +01:00
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-04-13 14:17:22 +02:00
|
|
|
@first_step = nil
|
|
|
|
@steps = []
|
2021-06-23 08:13:58 +02:00
|
|
|
|
2024-10-16 13:52:03 +02:00
|
|
|
if attrs["steps"].present?
|
|
|
|
@step_ids = @all_step_ids = attrs["steps"].map { |s| s["id"] }
|
2021-06-23 08:13:58 +02:00
|
|
|
|
|
|
|
@field_ids = []
|
2024-10-16 13:52:03 +02:00
|
|
|
attrs["steps"].each do |step|
|
|
|
|
step["fields"].each { |field| @field_ids << field["id"] } if step["fields"].present?
|
2021-06-23 08:13:58 +02:00
|
|
|
end
|
2020-11-03 01:24:20 +01:00
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2024-10-16 13:52:03 +02:00
|
|
|
@actions = attrs["actions"] || []
|
|
|
|
@action_ids = @actions.map { |a| a["id"] }
|
2021-07-21 05:31:03 +02:00
|
|
|
@template = attrs
|
2017-10-15 05:58:22 +02:00
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2023-01-18 19:53:36 +01:00
|
|
|
def actor_id
|
|
|
|
user ? user.id : guest_id
|
|
|
|
end
|
|
|
|
|
2020-11-03 01:24:20 +01:00
|
|
|
def cast_bool(val)
|
|
|
|
val.nil? ? false : ActiveRecord::Type::Boolean.new.cast(val)
|
|
|
|
end
|
2017-10-15 05:58:22 +02:00
|
|
|
|
2021-04-20 19:58:19 +02:00
|
|
|
def create_step(step_id)
|
|
|
|
::CustomWizard::Step.new(step_id)
|
2017-10-15 05:58:22 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def append_step(step)
|
|
|
|
step = create_step(step) if step.is_a?(String)
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2017-10-15 05:58:22 +02:00
|
|
|
yield step if block_given?
|
|
|
|
|
2020-10-31 08:05:50 +01:00
|
|
|
steps << step
|
2021-04-20 19:58:19 +02:00
|
|
|
step.wizard = self
|
|
|
|
step.index = (steps.size == 1 ? 0 : steps.size) if step.index.nil?
|
|
|
|
end
|
|
|
|
|
2021-06-23 08:13:58 +02:00
|
|
|
def update!
|
|
|
|
update_step_order
|
|
|
|
update_step_ids
|
|
|
|
update_field_ids
|
|
|
|
update_action_ids
|
|
|
|
|
|
|
|
@submissions = nil
|
|
|
|
@current_submission = nil
|
|
|
|
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_step_order
|
2021-04-20 19:58:19 +02:00
|
|
|
steps.sort_by!(&:index)
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2021-04-20 19:58:19 +02:00
|
|
|
steps.each_with_index do |step, index|
|
|
|
|
if index === 0
|
|
|
|
@first_step = step
|
|
|
|
@start = step.id
|
|
|
|
else
|
|
|
|
last_step = steps[index - 1]
|
|
|
|
last_step.next = step
|
|
|
|
step.previous = last_step
|
|
|
|
end
|
|
|
|
|
|
|
|
step.index = index
|
|
|
|
|
2024-10-16 13:52:03 +02:00
|
|
|
step.conditional_final_step = true if index === (steps.length - 1)
|
2021-04-20 19:58:19 +02:00
|
|
|
|
2024-10-16 13:52:03 +02:00
|
|
|
step.last_step = true if index === (all_step_ids.length - 1)
|
2021-04-20 19:58:19 +02:00
|
|
|
|
2023-06-21 10:53:42 +02:00
|
|
|
if !@restart_on_revisit && step.previous && step.previous.id === last_completed_step_id
|
2021-04-20 19:58:19 +02:00
|
|
|
@start = step.id
|
|
|
|
end
|
2017-10-15 05:58:22 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-20 19:58:19 +02:00
|
|
|
def last_completed_step_id
|
2023-01-18 19:53:36 +01:00
|
|
|
return nil unless actor_id && unfinished?
|
|
|
|
|
2024-10-16 13:52:03 +02:00
|
|
|
last_completed_step =
|
|
|
|
CustomWizard::UserHistory
|
|
|
|
.where(
|
|
|
|
actor_id: actor_id,
|
|
|
|
action: CustomWizard::UserHistory.actions[:step],
|
|
|
|
context: id,
|
|
|
|
subject: all_step_ids,
|
|
|
|
)
|
|
|
|
.order("created_at")
|
|
|
|
.last
|
2023-01-18 19:53:36 +01:00
|
|
|
|
|
|
|
last_completed_step&.subject
|
2017-10-15 05:58:22 +02:00
|
|
|
end
|
|
|
|
|
2021-04-20 19:58:19 +02:00
|
|
|
def find_step(step_id)
|
|
|
|
steps.select { |step| step.id === step_id }.first
|
|
|
|
end
|
|
|
|
|
2020-11-26 04:05:50 +01:00
|
|
|
def create_updater(step_id, submission)
|
2017-11-01 05:21:14 +01:00
|
|
|
step = @steps.find { |s| s.id == step_id }
|
|
|
|
wizard = self
|
2023-01-18 19:53:36 +01:00
|
|
|
CustomWizard::StepUpdater.new(wizard, step, submission)
|
2017-11-01 05:21:14 +01:00
|
|
|
end
|
2017-10-15 05:58:22 +02:00
|
|
|
|
2017-11-01 05:21:14 +01:00
|
|
|
def unfinished?
|
2023-01-18 19:53:36 +01:00
|
|
|
return nil unless actor_id
|
2023-03-22 11:20:30 +01:00
|
|
|
return false if last_submission&.submitted?
|
2019-06-19 07:23:10 +02:00
|
|
|
|
2024-10-16 13:52:03 +02:00
|
|
|
most_recent =
|
|
|
|
CustomWizard::UserHistory
|
|
|
|
.where(actor_id: actor_id, action: CustomWizard::UserHistory.actions[:step], context: id)
|
|
|
|
.distinct
|
|
|
|
.order("updated_at DESC")
|
|
|
|
.first
|
2017-11-01 05:21:14 +01:00
|
|
|
|
2019-01-22 00:57:03 +01:00
|
|
|
if most_recent && most_recent.subject == "reset"
|
2019-01-14 03:53:53 +01:00
|
|
|
false
|
|
|
|
elsif most_recent
|
2020-11-03 01:24:20 +01:00
|
|
|
most_recent.subject != steps.last.id
|
2017-11-01 05:21:14 +01:00
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def completed?
|
2023-01-18 19:53:36 +01:00
|
|
|
return nil unless actor_id
|
2023-03-22 11:20:30 +01:00
|
|
|
return true if last_submission&.submitted?
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2024-10-16 13:52:03 +02:00
|
|
|
history =
|
|
|
|
CustomWizard::UserHistory.where(
|
|
|
|
actor_id: actor_id,
|
|
|
|
action: CustomWizard::UserHistory.actions[:step],
|
|
|
|
context: id,
|
|
|
|
)
|
2017-11-01 05:21:14 +01:00
|
|
|
|
2024-10-10 10:19:43 +02:00
|
|
|
if after_time && multiple_submissions
|
2020-10-31 08:05:50 +01:00
|
|
|
history = history.where("updated_at > ?", after_time_scheduled)
|
2017-11-01 05:21:14 +01:00
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2017-11-01 05:21:14 +01:00
|
|
|
completed = history.distinct.order(:subject).pluck(:subject)
|
2020-10-31 08:05:50 +01:00
|
|
|
(step_ids - completed).empty?
|
2017-10-15 05:58:22 +02:00
|
|
|
end
|
|
|
|
|
2024-09-24 13:39:25 +02:00
|
|
|
def permitted?(always_allow_admin: true)
|
2023-01-18 19:53:36 +01:00
|
|
|
return nil unless actor_id
|
2024-09-24 13:39:25 +02:00
|
|
|
return true if user && ((always_allow_admin && user.admin?) || permitted.blank?)
|
2023-02-07 12:46:17 +01:00
|
|
|
return false if !user && permitted.blank?
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2024-10-16 13:52:03 +02:00
|
|
|
mapper =
|
|
|
|
CustomWizard::Mapper.new(
|
|
|
|
inputs: permitted,
|
|
|
|
user: user,
|
|
|
|
opts: {
|
|
|
|
with_type: true,
|
|
|
|
multiple: true,
|
|
|
|
},
|
|
|
|
).perform
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-04-06 10:36:38 +02:00
|
|
|
return true if mapper.blank?
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-04-06 10:36:38 +02:00
|
|
|
mapper.all? do |m|
|
2023-02-07 12:46:17 +01:00
|
|
|
if !user
|
2024-10-16 13:52:03 +02:00
|
|
|
m[:type] === "assignment" && [*m[:result]].include?(GUEST_GROUP_ID)
|
2020-04-06 10:36:38 +02:00
|
|
|
else
|
2024-10-16 13:52:03 +02:00
|
|
|
if m[:type] === "assignment"
|
2023-03-10 13:43:37 +01:00
|
|
|
[*m[:result]].include?(GUEST_GROUP_ID) ||
|
2024-10-16 13:52:03 +02:00
|
|
|
[*m[:result]].include?(Group::AUTO_GROUPS[:everyone]) ||
|
|
|
|
GroupUser.exists?(group_id: m[:result], user_id: user.id)
|
|
|
|
elsif m[:type] === "validation"
|
2023-02-07 12:46:17 +01:00
|
|
|
m[:result]
|
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
2020-04-06 10:36:38 +02:00
|
|
|
end
|
|
|
|
end
|
2017-11-29 10:48:49 +01:00
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2024-10-10 10:19:43 +02:00
|
|
|
def can_submit?
|
|
|
|
multiple_submissions || !completed?
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_access?(always_allow_admin: true)
|
|
|
|
permitted?(always_allow_admin: always_allow_admin) && can_submit?
|
2020-04-13 14:17:22 +02:00
|
|
|
end
|
2017-11-29 10:48:49 +01:00
|
|
|
|
2024-10-17 16:15:25 +02:00
|
|
|
def should_redirect?
|
|
|
|
can_access?(always_allow_admin: false) && after_time_target?
|
|
|
|
end
|
|
|
|
|
2019-01-14 03:53:53 +01:00
|
|
|
def reset
|
2023-01-18 19:53:36 +01:00
|
|
|
return nil unless actor_id
|
|
|
|
|
|
|
|
CustomWizard::UserHistory.create(
|
|
|
|
action: CustomWizard::UserHistory.actions[:step],
|
|
|
|
actor_id: actor_id,
|
2020-10-31 08:05:50 +01:00
|
|
|
context: id,
|
2024-10-16 13:52:03 +02:00
|
|
|
subject: "reset",
|
2019-01-14 03:53:53 +01:00
|
|
|
)
|
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2021-06-23 08:13:58 +02:00
|
|
|
def update_step_ids
|
|
|
|
@step_ids = steps.map(&:id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_field_ids
|
|
|
|
@field_ids = steps.map { |step| step.fields.map { |field| field.id } }.flatten
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_action_ids
|
|
|
|
@action_ids = []
|
|
|
|
|
|
|
|
@actions.each do |action|
|
2024-10-16 13:52:03 +02:00
|
|
|
if action["run_after"].blank? || action["run_after"] === "wizard_completion" ||
|
|
|
|
step_ids.include?(action["run_after"])
|
|
|
|
@action_ids << action["id"]
|
2021-06-23 08:13:58 +02:00
|
|
|
end
|
|
|
|
end
|
2021-06-17 09:50:22 +02:00
|
|
|
end
|
|
|
|
|
2020-04-13 14:17:22 +02:00
|
|
|
def submissions
|
2023-01-18 19:53:36 +01:00
|
|
|
@submissions ||= CustomWizard::Submission.list(self).submissions
|
2020-10-31 08:05:50 +01:00
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2023-03-22 11:20:30 +01:00
|
|
|
def last_submission
|
|
|
|
@last_submission ||= submissions&.last
|
|
|
|
end
|
|
|
|
|
2020-11-03 01:24:20 +01:00
|
|
|
def current_submission
|
2024-10-16 13:52:03 +02:00
|
|
|
@current_submission ||=
|
|
|
|
begin
|
|
|
|
if submissions.present?
|
|
|
|
unsubmitted = submissions.select { |submission| !submission.submitted_at }
|
|
|
|
unsubmitted.present? ? unsubmitted.first : CustomWizard::Submission.new(self)
|
|
|
|
else
|
|
|
|
CustomWizard::Submission.new(self)
|
|
|
|
end
|
2021-06-17 09:50:22 +02:00
|
|
|
end
|
2021-05-05 09:43:03 +02:00
|
|
|
end
|
2021-04-20 19:58:19 +02:00
|
|
|
|
2022-01-31 10:18:04 +01:00
|
|
|
def cleanup_on_complete!
|
|
|
|
remove_user_redirect
|
2021-04-20 19:58:19 +02:00
|
|
|
|
2021-06-17 09:50:22 +02:00
|
|
|
if current_submission.present?
|
|
|
|
current_submission.submitted_at = Time.now.iso8601
|
|
|
|
current_submission.save
|
2021-04-20 19:58:19 +02:00
|
|
|
end
|
2021-06-23 08:13:58 +02:00
|
|
|
|
|
|
|
update!
|
2020-11-03 01:24:20 +01:00
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2022-01-31 10:18:04 +01:00
|
|
|
def cleanup_on_skip!
|
|
|
|
remove_user_redirect
|
|
|
|
|
2024-10-16 13:52:03 +02:00
|
|
|
current_submission.remove if current_submission.present?
|
2022-01-31 10:18:04 +01:00
|
|
|
|
|
|
|
reset
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove_user_redirect
|
2024-10-10 10:19:43 +02:00
|
|
|
return if user.blank?
|
2023-01-18 19:53:36 +01:00
|
|
|
|
2022-01-31 10:18:04 +01:00
|
|
|
if id == user.redirect_to_wizard
|
2024-10-16 13:52:03 +02:00
|
|
|
user.custom_fields.delete("redirect_to_wizard")
|
2022-01-31 10:18:04 +01:00
|
|
|
user.save_custom_fields(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-10-17 16:15:25 +02:00
|
|
|
def after_time_groups
|
|
|
|
@after_time_groups ||= Group.where(name: after_time_group_names)
|
|
|
|
end
|
|
|
|
|
|
|
|
def after_time_target?
|
|
|
|
return true if after_time_group_names.blank? || !after_time_groups.exists?
|
|
|
|
return true if after_time_groups.joins(:users).where(users: { username: user.username }).exists?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2023-01-18 19:53:36 +01:00
|
|
|
def self.create(wizard_id, user = nil, guest_id = nil)
|
2020-10-31 08:05:50 +01:00
|
|
|
if template = CustomWizard::Template.find(wizard_id)
|
2023-01-18 19:53:36 +01:00
|
|
|
new(template.to_h, user, guest_id)
|
2020-10-31 08:05:50 +01:00
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
2020-04-13 14:17:22 +02:00
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2021-09-07 14:06:13 +02:00
|
|
|
def self.list(user, template_opts = {}, not_completed = false)
|
2020-11-03 01:24:20 +01:00
|
|
|
return [] unless user
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2024-10-16 13:52:03 +02:00
|
|
|
CustomWizard::Template
|
|
|
|
.list(**template_opts)
|
|
|
|
.reduce([]) do |result, template|
|
|
|
|
wizard = new(template, user)
|
|
|
|
result.push(wizard) if wizard.permitted? && (!not_completed || !wizard.completed?)
|
|
|
|
result
|
|
|
|
end
|
2020-03-30 08:16:03 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.after_signup(user)
|
2024-10-16 13:52:03 +02:00
|
|
|
wizards =
|
|
|
|
list(
|
|
|
|
user,
|
|
|
|
{ setting: "after_signup", order: "(value::json ->> 'permitted') IS NOT NULL DESC" },
|
|
|
|
)
|
2020-11-03 01:24:20 +01:00
|
|
|
wizards.any? ? wizards.first : false
|
2017-10-15 05:58:22 +02:00
|
|
|
end
|
|
|
|
|
2017-11-22 10:34:21 +01:00
|
|
|
def self.prompt_completion(user)
|
2024-10-16 13:52:03 +02:00
|
|
|
wizards =
|
|
|
|
list(
|
|
|
|
user,
|
|
|
|
{ setting: "prompt_completion", order: "(value::json ->> 'permitted') IS NOT NULL DESC" },
|
|
|
|
true,
|
|
|
|
)
|
2020-11-03 01:24:20 +01:00
|
|
|
if wizards.any?
|
2024-10-16 13:52:03 +02:00
|
|
|
wizards.map { |w| { id: w.id, name: w.name } }
|
2017-11-22 10:34:21 +01:00
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-10-17 16:15:25 +02:00
|
|
|
def self.set_after_time_redirect(wizard_id, user)
|
|
|
|
wizard = self.create(wizard_id, user)
|
|
|
|
set_user_redirect(wizard_id, user) if wizard.after_time_target?
|
|
|
|
end
|
|
|
|
|
2021-06-17 09:50:22 +02:00
|
|
|
def self.set_user_redirect(wizard_id, user)
|
2020-04-19 08:42:44 +02:00
|
|
|
wizard = self.create(wizard_id, user)
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2024-10-10 10:19:43 +02:00
|
|
|
if wizard.can_access?(always_allow_admin: false)
|
2024-10-16 13:52:03 +02:00
|
|
|
user.custom_fields["redirect_to_wizard"] = wizard_id
|
2018-07-06 02:58:53 +02:00
|
|
|
user.save_custom_fields(true)
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
2021-06-17 09:50:22 +02:00
|
|
|
|
|
|
|
def self.set_wizard_redirect(user, wizard_id, url)
|
|
|
|
wizard = self.create(wizard_id, user)
|
|
|
|
|
|
|
|
if wizard.permitted?
|
2021-06-23 08:13:58 +02:00
|
|
|
submission = wizard.current_submission
|
2021-06-17 09:50:22 +02:00
|
|
|
submission.redirect_to = url
|
|
|
|
submission.save
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
2023-01-18 19:53:36 +01:00
|
|
|
|
|
|
|
def self.generate_guest_id
|
|
|
|
"#{self::GUEST_ID_PREFIX}_#{SecureRandom.hex(12)}"
|
|
|
|
end
|
2017-09-23 04:34:07 +02:00
|
|
|
end
|