2019-10-03 08:54:15 +02:00
|
|
|
require_dependency 'wizard'
|
|
|
|
require_dependency 'wizard/field'
|
|
|
|
require_dependency 'wizard/step'
|
|
|
|
|
2017-11-01 05:21:14 +01:00
|
|
|
::Wizard.class_eval do
|
|
|
|
def self.user_requires_completion?(user)
|
|
|
|
wizard_result = self.new(user).requires_completion?
|
|
|
|
return wizard_result if wizard_result
|
|
|
|
|
2018-07-06 02:58:53 +02:00
|
|
|
custom_redirect = false
|
2017-11-01 05:21:14 +01:00
|
|
|
|
2018-09-25 13:04:08 +02:00
|
|
|
if user && user.first_seen_at.blank? && wizard_id = CustomWizard::Wizard.after_signup
|
2018-07-06 02:58:53 +02:00
|
|
|
wizard = CustomWizard::Wizard.create(user, wizard_id)
|
2018-05-24 07:32:51 +02:00
|
|
|
|
2018-07-06 02:58:53 +02:00
|
|
|
if !wizard.completed? && wizard.permitted?
|
|
|
|
custom_redirect = true
|
|
|
|
CustomWizard::Wizard.set_wizard_redirect(user, wizard_id)
|
2017-11-01 05:21:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
!!custom_redirect
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-15 05:58:22 +02:00
|
|
|
::Wizard::Field.class_eval do
|
2019-07-26 11:12:58 +02:00
|
|
|
attr_reader :label, :description, :image, :key, :min_length, :file_types, :limit, :property
|
2017-11-09 03:50:48 +01:00
|
|
|
attr_accessor :dropdown_none
|
2017-10-15 05:58:22 +02:00
|
|
|
|
|
|
|
def initialize(attrs)
|
2018-05-13 07:46:02 +02:00
|
|
|
@attrs = attrs || {}
|
2017-10-15 05:58:22 +02:00
|
|
|
@id = attrs[:id]
|
|
|
|
@type = attrs[:type]
|
|
|
|
@required = !!attrs[:required]
|
|
|
|
@description = attrs[:description]
|
2018-03-05 02:52:15 +01:00
|
|
|
@image = attrs[:image]
|
2017-10-15 05:58:22 +02:00
|
|
|
@key = attrs[:key]
|
|
|
|
@min_length = attrs[:min_length]
|
|
|
|
@value = attrs[:value]
|
|
|
|
@choices = []
|
2017-11-09 03:50:48 +01:00
|
|
|
@dropdown_none = attrs[:dropdown_none]
|
2019-07-19 05:47:17 +02:00
|
|
|
@file_types = attrs[:file_types]
|
2019-07-26 10:59:21 +02:00
|
|
|
@limit = attrs[:limit]
|
2019-07-26 11:12:58 +02:00
|
|
|
@property = attrs[:property]
|
2017-10-15 05:58:22 +02:00
|
|
|
end
|
2018-05-13 07:46:02 +02:00
|
|
|
|
|
|
|
def label
|
2018-05-13 07:47:55 +02:00
|
|
|
@label ||= PrettyText.cook(@attrs[:label])
|
2018-05-13 07:46:02 +02:00
|
|
|
end
|
2017-10-15 05:58:22 +02:00
|
|
|
end
|
|
|
|
|
2018-05-13 07:39:28 +02:00
|
|
|
::Wizard::Choice.class_eval do
|
|
|
|
def initialize(id, opts)
|
|
|
|
@id = id
|
|
|
|
@opts = opts
|
|
|
|
@data = opts[:data]
|
|
|
|
@extra_label = opts[:extra_label]
|
|
|
|
@icon = opts[:icon]
|
|
|
|
end
|
|
|
|
|
|
|
|
def label
|
2018-05-13 07:47:55 +02:00
|
|
|
@label ||= PrettyText.cook(@opts[:label])
|
2018-05-13 07:39:28 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-15 05:58:22 +02:00
|
|
|
class ::Wizard::Step
|
2019-07-27 09:01:29 +02:00
|
|
|
attr_accessor :title, :description, :key, :permitted, :permitted_message
|
2017-10-15 05:58:22 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
::WizardSerializer.class_eval do
|
2019-07-26 10:59:21 +02:00
|
|
|
attributes :id,
|
|
|
|
:name,
|
|
|
|
:background,
|
|
|
|
:completed,
|
|
|
|
:required,
|
|
|
|
:min_trust,
|
|
|
|
:permitted,
|
|
|
|
:user,
|
|
|
|
:categories,
|
|
|
|
:uncategorized_category_id
|
2017-10-15 05:58:22 +02:00
|
|
|
|
|
|
|
def id
|
|
|
|
object.id
|
|
|
|
end
|
|
|
|
|
2017-10-17 09:18:53 +02:00
|
|
|
def include_id?
|
|
|
|
object.respond_to?(:id)
|
|
|
|
end
|
|
|
|
|
2019-06-19 07:39:39 +02:00
|
|
|
def name
|
|
|
|
object.name
|
|
|
|
end
|
|
|
|
|
2017-10-15 05:58:22 +02:00
|
|
|
def background
|
|
|
|
object.background
|
|
|
|
end
|
|
|
|
|
2017-10-17 09:18:53 +02:00
|
|
|
def include_background?
|
|
|
|
object.respond_to?(:background)
|
|
|
|
end
|
|
|
|
|
2017-10-15 05:58:22 +02:00
|
|
|
def completed
|
|
|
|
object.completed?
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_completed?
|
2017-12-25 13:34:33 +01:00
|
|
|
object.completed? &&
|
|
|
|
(!object.respond_to?(:multiple_submissions) || !object.multiple_submissions) &&
|
|
|
|
!scope.is_admin?
|
2017-10-15 05:58:22 +02:00
|
|
|
end
|
|
|
|
|
2017-11-29 10:48:49 +01:00
|
|
|
def min_trust
|
|
|
|
object.min_trust
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_min_trust?
|
|
|
|
object.respond_to?(:min_trust)
|
|
|
|
end
|
|
|
|
|
|
|
|
def permitted
|
|
|
|
object.permitted?
|
|
|
|
end
|
|
|
|
|
2018-01-11 02:59:18 +01:00
|
|
|
def include_permitted?
|
|
|
|
object.respond_to?(:permitted?)
|
2017-11-29 10:48:49 +01:00
|
|
|
end
|
|
|
|
|
2017-10-15 05:58:22 +02:00
|
|
|
def include_start?
|
|
|
|
object.start && include_steps?
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_steps?
|
|
|
|
!include_completed?
|
|
|
|
end
|
2017-11-01 05:21:14 +01:00
|
|
|
|
|
|
|
def required
|
|
|
|
object.required
|
|
|
|
end
|
2017-11-02 03:26:49 +01:00
|
|
|
|
|
|
|
def include_required?
|
|
|
|
object.respond_to?(:required)
|
|
|
|
end
|
2019-06-19 07:23:10 +02:00
|
|
|
|
|
|
|
def user
|
|
|
|
object.user
|
|
|
|
end
|
2019-07-26 10:59:21 +02:00
|
|
|
|
|
|
|
def categories
|
|
|
|
begin
|
|
|
|
site = ::Site.new(scope)
|
|
|
|
::ActiveModel::ArraySerializer.new(site.categories, each_serializer: BasicCategorySerializer)
|
|
|
|
rescue => e
|
|
|
|
puts "HERE IS THE ERROR: #{e.inspect}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def uncategorized_category_id
|
|
|
|
SiteSetting.uncategorized_category_id
|
|
|
|
end
|
2017-10-15 05:58:22 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
::WizardStepSerializer.class_eval do
|
2019-07-27 09:01:29 +02:00
|
|
|
attributes :permitted, :permitted_message
|
2019-07-02 06:49:14 +02:00
|
|
|
|
2017-10-15 05:58:22 +02:00
|
|
|
def title
|
2019-06-19 06:32:03 +02:00
|
|
|
return PrettyText.cook(object.title) if object.title
|
|
|
|
PrettyText.cook(I18n.t("#{object.key || i18n_key}.title", default: ''))
|
2017-10-15 05:58:22 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def description
|
|
|
|
return object.description if object.description
|
2018-04-15 04:49:12 +02:00
|
|
|
PrettyText.cook(I18n.t("#{object.key || i18n_key}.description", default: '', base_url: Discourse.base_url))
|
2017-10-15 05:58:22 +02:00
|
|
|
end
|
2019-07-02 06:49:14 +02:00
|
|
|
|
|
|
|
def permitted
|
|
|
|
object.permitted
|
|
|
|
end
|
2019-07-27 09:01:29 +02:00
|
|
|
|
|
|
|
def permitted_message
|
|
|
|
object.permitted_message
|
|
|
|
end
|
2017-10-15 05:58:22 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
::WizardFieldSerializer.class_eval do
|
2019-07-26 11:12:58 +02:00
|
|
|
attributes :dropdown_none, :image, :file_types, :limit, :property
|
2017-11-09 03:50:48 +01:00
|
|
|
|
2017-10-15 05:58:22 +02:00
|
|
|
def label
|
2018-05-20 03:57:48 +02:00
|
|
|
return object.label if object.label.present?
|
2017-10-15 05:58:22 +02:00
|
|
|
I18n.t("#{object.key || i18n_key}.label", default: '')
|
|
|
|
end
|
|
|
|
|
|
|
|
def description
|
2018-05-20 03:57:48 +02:00
|
|
|
return object.description if object.description.present?
|
2018-01-30 14:19:32 +01:00
|
|
|
I18n.t("#{object.key || i18n_key}.description", default: '', base_url: Discourse.base_url)
|
2017-10-15 05:58:22 +02:00
|
|
|
end
|
|
|
|
|
2018-03-05 02:52:15 +01:00
|
|
|
def image
|
|
|
|
object.image
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_image?
|
|
|
|
object.image.present?
|
|
|
|
end
|
|
|
|
|
2017-10-15 05:58:22 +02:00
|
|
|
def placeholder
|
|
|
|
I18n.t("#{object.key || i18n_key}.placeholder", default: '')
|
|
|
|
end
|
2017-11-09 03:50:48 +01:00
|
|
|
|
|
|
|
def dropdown_none
|
|
|
|
object.dropdown_none
|
|
|
|
end
|
2019-07-19 05:47:17 +02:00
|
|
|
|
|
|
|
def file_types
|
|
|
|
object.file_types
|
|
|
|
end
|
2019-07-26 10:59:21 +02:00
|
|
|
|
|
|
|
def limit
|
|
|
|
object.limit
|
|
|
|
end
|
2019-07-26 11:12:58 +02:00
|
|
|
|
|
|
|
def property
|
|
|
|
object.property
|
|
|
|
end
|
2017-10-15 05:58:22 +02:00
|
|
|
end
|