2021-03-11 07:30:15 +01:00
|
|
|
# frozen_string_literal: true
|
2017-09-23 04:34:07 +02:00
|
|
|
# name: discourse-custom-wizard
|
2022-08-18 23:04:42 +02:00
|
|
|
# about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more.
|
2024-10-16 11:14:03 +02:00
|
|
|
# version: 2.8.11
|
2023-06-22 06:23:41 +02:00
|
|
|
# authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever, Juan Marcos Gutierrez Ramos
|
2020-11-09 05:14:45 +01:00
|
|
|
# url: https://github.com/paviliondev/discourse-custom-wizard
|
2022-08-12 16:48:30 +02:00
|
|
|
# contact_emails: development@pavilion.tech
|
2022-03-25 12:18:54 +01:00
|
|
|
# subscription_url: https://coop.pavilion.tech
|
2024-01-26 16:19:54 +01:00
|
|
|
# meta_topic_id: 73345
|
2017-09-23 04:34:07 +02:00
|
|
|
|
2024-06-20 13:06:02 +02:00
|
|
|
gem 'liquid', '5.5.0', require: true
|
2024-10-16 11:10:50 +02:00
|
|
|
gem "discourse_subscription_client", "0.1.6", require_name: "discourse_subscription_client"
|
2023-10-06 09:52:42 +02:00
|
|
|
gem 'discourse_plugin_statistics', '0.1.0.pre7', require: true
|
2023-05-06 02:43:16 +02:00
|
|
|
register_asset 'stylesheets/common/admin.scss'
|
|
|
|
register_asset 'stylesheets/common/wizard.scss'
|
2023-11-17 10:08:56 +01:00
|
|
|
register_svg_icon 'pavilion-logo'
|
2024-04-15 08:58:03 +02:00
|
|
|
register_svg_icon "hat-wizard"
|
2017-09-23 04:34:07 +02:00
|
|
|
|
2019-12-05 07:48:32 +01:00
|
|
|
enabled_site_setting :custom_wizard_enabled
|
|
|
|
|
2019-02-20 07:27:17 +01:00
|
|
|
if respond_to?(:register_svg_icon)
|
2020-03-30 01:53:28 +02:00
|
|
|
register_svg_icon "far-calendar"
|
2019-02-20 07:27:17 +01:00
|
|
|
register_svg_icon "chevron-right"
|
|
|
|
register_svg_icon "chevron-left"
|
2020-11-10 01:56:11 +01:00
|
|
|
register_svg_icon "save"
|
2021-08-31 01:23:33 +02:00
|
|
|
register_svg_icon "sliders-h"
|
|
|
|
register_svg_icon "calendar"
|
|
|
|
register_svg_icon "check"
|
|
|
|
register_svg_icon "times"
|
|
|
|
register_svg_icon "clock"
|
|
|
|
register_svg_icon "link"
|
|
|
|
register_svg_icon "comment-alt"
|
2021-08-09 23:44:44 +02:00
|
|
|
register_svg_icon "far-life-ring"
|
2021-07-20 09:32:18 +02:00
|
|
|
register_svg_icon "arrow-right"
|
2021-10-05 14:54:06 +02:00
|
|
|
register_svg_icon "bolt"
|
2019-02-20 07:27:17 +01:00
|
|
|
end
|
2019-01-14 03:03:42 +01:00
|
|
|
|
2017-09-23 04:34:07 +02:00
|
|
|
after_initialize do
|
2020-03-30 08:16:03 +02:00
|
|
|
%w[
|
|
|
|
../lib/custom_wizard/engine.rb
|
|
|
|
../config/routes.rb
|
2022-03-12 14:49:41 +01:00
|
|
|
../app/controllers/custom_wizard/admin/admin.rb
|
2023-09-24 09:25:42 +02:00
|
|
|
../app/controllers/custom_wizard/admin/subscription.rb
|
2022-03-12 14:49:41 +01:00
|
|
|
../app/controllers/custom_wizard/admin/wizard.rb
|
|
|
|
../app/controllers/custom_wizard/admin/submissions.rb
|
|
|
|
../app/controllers/custom_wizard/admin/api.rb
|
|
|
|
../app/controllers/custom_wizard/admin/logs.rb
|
|
|
|
../app/controllers/custom_wizard/admin/manager.rb
|
|
|
|
../app/controllers/custom_wizard/admin/custom_fields.rb
|
2023-01-18 19:53:36 +01:00
|
|
|
../app/controllers/custom_wizard/wizard_client.rb
|
2022-03-12 14:49:41 +01:00
|
|
|
../app/controllers/custom_wizard/wizard.rb
|
|
|
|
../app/controllers/custom_wizard/steps.rb
|
|
|
|
../app/controllers/custom_wizard/realtime_validations.rb
|
|
|
|
../app/jobs/regular/refresh_api_access_token.rb
|
|
|
|
../app/jobs/regular/set_after_time_wizard.rb
|
2020-11-26 04:05:50 +01:00
|
|
|
../lib/custom_wizard/validators/template.rb
|
|
|
|
../lib/custom_wizard/validators/update.rb
|
2020-05-04 11:02:49 +02:00
|
|
|
../lib/custom_wizard/action_result.rb
|
2020-04-15 02:46:44 +02:00
|
|
|
../lib/custom_wizard/action.rb
|
2020-03-30 08:16:03 +02:00
|
|
|
../lib/custom_wizard/builder.rb
|
2020-12-04 08:05:56 +01:00
|
|
|
../lib/custom_wizard/cache.rb
|
2020-10-20 07:40:23 +02:00
|
|
|
../lib/custom_wizard/custom_field.rb
|
2020-03-30 08:16:03 +02:00
|
|
|
../lib/custom_wizard/field.rb
|
2021-01-27 06:08:26 +01:00
|
|
|
../lib/custom_wizard/realtime_validation.rb
|
2021-02-16 01:43:00 +01:00
|
|
|
../lib/custom_wizard/realtime_validations/result.rb
|
|
|
|
../lib/custom_wizard/realtime_validations/similar_topics.rb
|
2020-03-30 08:16:03 +02:00
|
|
|
../lib/custom_wizard/mapper.rb
|
2020-04-15 02:46:44 +02:00
|
|
|
../lib/custom_wizard/log.rb
|
2020-03-30 08:16:03 +02:00
|
|
|
../lib/custom_wizard/step_updater.rb
|
2021-04-20 19:58:19 +02:00
|
|
|
../lib/custom_wizard/step.rb
|
2021-06-17 09:50:22 +02:00
|
|
|
../lib/custom_wizard/submission.rb
|
2022-03-25 12:18:54 +01:00
|
|
|
../lib/custom_wizard/subscription.rb
|
2020-10-31 08:05:50 +01:00
|
|
|
../lib/custom_wizard/template.rb
|
2020-03-30 08:16:03 +02:00
|
|
|
../lib/custom_wizard/wizard.rb
|
2023-01-18 19:53:36 +01:00
|
|
|
../lib/custom_wizard/user_history.rb
|
2020-03-30 08:16:03 +02:00
|
|
|
../lib/custom_wizard/api/api.rb
|
|
|
|
../lib/custom_wizard/api/authorization.rb
|
|
|
|
../lib/custom_wizard/api/endpoint.rb
|
|
|
|
../lib/custom_wizard/api/log_entry.rb
|
2021-04-09 07:34:42 +02:00
|
|
|
../lib/custom_wizard/liquid_extensions/first_non_empty.rb
|
2021-05-12 02:44:09 +02:00
|
|
|
../lib/custom_wizard/exceptions/exceptions.rb
|
2023-10-04 07:09:52 +02:00
|
|
|
../lib/discourse_plugin_statistics/plugin.rb
|
2022-03-12 14:49:41 +01:00
|
|
|
../app/serializers/custom_wizard/api/authorization_serializer.rb
|
|
|
|
../app/serializers/custom_wizard/api/basic_endpoint_serializer.rb
|
|
|
|
../app/serializers/custom_wizard/api/endpoint_serializer.rb
|
|
|
|
../app/serializers/custom_wizard/api/log_serializer.rb
|
|
|
|
../app/serializers/custom_wizard/api_serializer.rb
|
|
|
|
../app/serializers/custom_wizard/basic_api_serializer.rb
|
|
|
|
../app/serializers/custom_wizard/basic_wizard_serializer.rb
|
|
|
|
../app/serializers/custom_wizard/custom_field_serializer.rb
|
|
|
|
../app/serializers/custom_wizard/wizard_field_serializer.rb
|
|
|
|
../app/serializers/custom_wizard/wizard_step_serializer.rb
|
|
|
|
../app/serializers/custom_wizard/wizard_serializer.rb
|
|
|
|
../app/serializers/custom_wizard/log_serializer.rb
|
|
|
|
../app/serializers/custom_wizard/submission_serializer.rb
|
|
|
|
../app/serializers/custom_wizard/realtime_validation/similar_topics_serializer.rb
|
2022-03-12 14:00:07 +01:00
|
|
|
../lib/custom_wizard/extensions/extra_locales_controller.rb
|
|
|
|
../lib/custom_wizard/extensions/invites_controller.rb
|
|
|
|
../lib/custom_wizard/extensions/users_controller.rb
|
2022-03-12 15:08:56 +01:00
|
|
|
../lib/custom_wizard/extensions/guardian.rb
|
2022-03-12 14:00:07 +01:00
|
|
|
../lib/custom_wizard/extensions/custom_field/preloader.rb
|
|
|
|
../lib/custom_wizard/extensions/custom_field/serializer.rb
|
|
|
|
../lib/custom_wizard/extensions/custom_field/extension.rb
|
|
|
|
../lib/custom_wizard/extensions/discourse_tagging.rb
|
2019-12-05 07:48:32 +01:00
|
|
|
].each do |path|
|
|
|
|
load File.expand_path(path, __FILE__)
|
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2022-01-31 10:41:14 +01:00
|
|
|
Liquid::Template.error_mode = :strict
|
|
|
|
|
2021-11-17 15:45:48 +01:00
|
|
|
# preloaded category custom fields
|
|
|
|
%w[
|
|
|
|
create_topic_wizard
|
2021-12-07 09:31:39 +01:00
|
|
|
].each do |custom_field|
|
2021-11-17 15:45:48 +01:00
|
|
|
Site.preloaded_category_custom_fields << custom_field
|
|
|
|
end
|
|
|
|
|
2021-04-09 07:34:42 +02:00
|
|
|
Liquid::Template.register_filter(::CustomWizard::LiquidFilter::FirstNonEmpty)
|
|
|
|
|
2021-10-30 12:37:16 +02:00
|
|
|
add_to_class(:topic, :wizard_submission_id) do
|
2023-05-06 02:43:16 +02:00
|
|
|
custom_fields['wizard_submission_id']
|
2021-10-19 05:35:55 +02:00
|
|
|
end
|
|
|
|
|
2019-12-05 09:05:21 +01:00
|
|
|
add_class_method(:wizard, :user_requires_completion?) do |user|
|
|
|
|
wizard_result = self.new(user).requires_completion?
|
|
|
|
return wizard_result if wizard_result
|
2019-12-05 07:48:32 +01:00
|
|
|
|
2019-12-05 09:05:21 +01:00
|
|
|
custom_redirect = false
|
2019-12-05 07:48:32 +01:00
|
|
|
|
2019-12-05 09:05:21 +01:00
|
|
|
if user &&
|
|
|
|
user.first_seen_at.blank? &&
|
2020-03-30 08:16:03 +02:00
|
|
|
wizard = CustomWizard::Wizard.after_signup(user)
|
2023-05-06 02:43:16 +02:00
|
|
|
|
2020-03-30 08:16:03 +02:00
|
|
|
if !wizard.completed?
|
2019-12-05 09:05:21 +01:00
|
|
|
custom_redirect = true
|
2021-06-17 09:50:22 +02:00
|
|
|
CustomWizard::Wizard.set_user_redirect(wizard.id, user)
|
2019-12-05 07:48:32 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-05 09:05:21 +01:00
|
|
|
!!custom_redirect
|
2019-12-05 07:48:32 +01:00
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2022-01-31 10:18:04 +01:00
|
|
|
add_to_class(:user, :redirect_to_wizard) do
|
2023-05-06 02:43:16 +02:00
|
|
|
if custom_fields['redirect_to_wizard'].present?
|
|
|
|
custom_fields['redirect_to_wizard']
|
2022-01-31 10:18:04 +01:00
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-05 09:05:21 +01:00
|
|
|
add_to_class(:users_controller, :wizard_path) do
|
2022-01-31 10:18:04 +01:00
|
|
|
if custom_wizard_redirect = current_user.redirect_to_wizard
|
2019-12-05 09:05:21 +01:00
|
|
|
"#{Discourse.base_url}/w/#{custom_wizard_redirect.dasherize}"
|
|
|
|
else
|
|
|
|
"#{Discourse.base_url}/wizard"
|
2017-11-01 05:21:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-05 09:05:21 +01:00
|
|
|
add_to_serializer(:current_user, :redirect_to_wizard) do
|
2022-01-31 10:18:04 +01:00
|
|
|
object.redirect_to_wizard
|
2017-11-03 14:43:57 +01:00
|
|
|
end
|
2018-01-16 08:13:50 +01:00
|
|
|
|
2020-03-30 01:53:28 +02:00
|
|
|
on(:user_approved) do |user|
|
2020-04-19 08:42:44 +02:00
|
|
|
if wizard = CustomWizard::Wizard.after_signup(user)
|
2021-06-17 09:50:22 +02:00
|
|
|
CustomWizard::Wizard.set_user_redirect(wizard.id, user)
|
2018-06-05 04:25:44 +02:00
|
|
|
end
|
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-04-19 08:06:18 +02:00
|
|
|
add_to_class(:application_controller, :redirect_to_wizard_if_required) do
|
2023-05-06 02:43:16 +02:00
|
|
|
@excluded_routes ||= SiteSetting.wizard_redirect_exclude_paths.split('|') + ['/w/']
|
2020-04-19 08:06:18 +02:00
|
|
|
url = request.referer || request.original_url
|
2022-01-31 10:18:04 +01:00
|
|
|
excluded_route = @excluded_routes.any? { |str| /#{str}/ =~ url }
|
2023-05-06 02:43:16 +02:00
|
|
|
not_api = request.format === 'text/html'
|
2022-01-31 10:18:04 +01:00
|
|
|
|
|
|
|
if not_api && !excluded_route
|
|
|
|
wizard_id = current_user.redirect_to_wizard
|
|
|
|
|
|
|
|
if CustomWizard::Template.can_redirect_users?(wizard_id)
|
|
|
|
if url !~ /\/w\// && url !~ /\/invites\//
|
|
|
|
CustomWizard::Wizard.set_wizard_redirect(current_user, wizard_id, url)
|
|
|
|
end
|
2020-04-19 08:06:18 +02:00
|
|
|
|
2024-09-24 13:39:25 +02:00
|
|
|
wizard = CustomWizard::Wizard.create(wizard_id, current_user)
|
2024-10-10 10:19:43 +02:00
|
|
|
redirect_to "/w/#{wizard_id.dasherize}" if wizard.can_access?(always_allow_admin: false)
|
2020-04-19 08:06:18 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2024-06-20 09:38:37 +02:00
|
|
|
add_to_class(:site_serializer, :include_wizard_required?) do
|
2020-04-19 08:06:18 +02:00
|
|
|
scope.is_admin? && Wizard.new(scope.user).requires_completion?
|
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2024-06-20 09:38:37 +02:00
|
|
|
add_to_class(:site_serializer, :complete_custom_wizard) do
|
2020-04-19 08:06:18 +02:00
|
|
|
if scope.user && requires_completion = CustomWizard::Wizard.prompt_completion(scope.user)
|
2021-03-11 07:30:15 +01:00
|
|
|
requires_completion.map { |w| { name: w[:name], url: "/w/#{w[:id]}" } }
|
2020-04-19 08:06:18 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-06-20 09:38:37 +02:00
|
|
|
add_to_class(:site_serializer, :include_complete_custom_wizard?) do
|
2020-04-19 08:06:18 +02:00
|
|
|
complete_custom_wizard.present?
|
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-04-19 08:06:18 +02:00
|
|
|
add_model_callback(:application_controller, :before_action) do
|
|
|
|
redirect_to_wizard_if_required if current_user
|
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-11-23 00:11:45 +01:00
|
|
|
::ExtraLocalesController.prepend ExtraLocalesControllerCustomWizard
|
2020-04-30 02:54:30 +02:00
|
|
|
::InvitesController.prepend InvitesControllerCustomWizard
|
2020-09-16 15:35:07 +02:00
|
|
|
::UsersController.prepend CustomWizardUsersController
|
2021-10-19 05:35:55 +02:00
|
|
|
::Guardian.prepend CustomWizardGuardian
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-10-31 08:05:50 +01:00
|
|
|
full_path = "#{Rails.root}/plugins/discourse-custom-wizard/assets/stylesheets/wizard/wizard_custom.scss"
|
2021-03-13 08:57:18 +01:00
|
|
|
if Stylesheet::Importer.respond_to?(:plugin_assets)
|
2023-05-06 02:43:16 +02:00
|
|
|
Stylesheet::Importer.plugin_assets['wizard_custom'] = Set[full_path]
|
2021-03-13 08:57:18 +01:00
|
|
|
else
|
|
|
|
# legacy method, Discourse 2.7.0.beta5 and below
|
|
|
|
DiscoursePluginRegistry.register_asset(full_path, {}, "wizard_custom")
|
|
|
|
Stylesheet::Importer.register_import("wizard_custom") do
|
|
|
|
import_files(DiscoursePluginRegistry.stylesheets["wizard_custom"])
|
|
|
|
end
|
2020-10-31 08:05:50 +01:00
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-11-08 04:24:20 +01:00
|
|
|
CustomWizard::CustomField::CLASSES.keys.each do |klass|
|
2021-06-08 13:39:49 +02:00
|
|
|
class_constant = klass.to_s.classify.constantize
|
|
|
|
|
2020-11-08 04:24:20 +01:00
|
|
|
add_model_callback(klass, :after_initialize) do
|
2020-12-01 08:20:02 +01:00
|
|
|
if CustomWizard::CustomField.enabled?
|
|
|
|
CustomWizard::CustomField.list_by(:klass, klass.to_s).each do |field|
|
2021-06-08 13:39:49 +02:00
|
|
|
class_constant.register_custom_field_type(field[:name], field[:type].to_sym)
|
2020-12-01 08:20:02 +01:00
|
|
|
end
|
2020-10-23 02:53:39 +02:00
|
|
|
end
|
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2021-06-08 13:39:49 +02:00
|
|
|
class_constant.singleton_class.prepend CustomWizardCustomFieldPreloader
|
|
|
|
class_constant.singleton_class.prepend CustomWizardCustomFieldExtension
|
2020-11-08 04:24:20 +01:00
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-11-08 04:24:20 +01:00
|
|
|
CustomWizard::CustomField.serializers.each do |serializer_klass|
|
2020-11-09 07:50:17 +01:00
|
|
|
"#{serializer_klass}_serializer".classify.constantize.prepend CustomWizardCustomFieldSerializer
|
2020-10-23 02:53:39 +02:00
|
|
|
end
|
|
|
|
|
2022-02-07 06:40:52 +01:00
|
|
|
reloadable_patch do |plugin|
|
|
|
|
::DiscourseTagging.singleton_class.prepend CustomWizardDiscourseTagging
|
|
|
|
end
|
|
|
|
|
2018-01-16 08:13:50 +01:00
|
|
|
DiscourseEvent.trigger(:custom_wizard_ready)
|
2023-09-20 02:46:42 +02:00
|
|
|
|
|
|
|
on(:before_create_topic) do |topic_params, user|
|
|
|
|
category = topic_params.category
|
2023-10-03 05:38:01 +02:00
|
|
|
wizard_submission_id = topic_params.custom_fields&.[]('wizard_submission_id')
|
2023-10-03 04:05:28 +02:00
|
|
|
if category&.custom_fields&.[]('create_topic_wizard').present? && wizard_submission_id.blank?
|
2023-09-20 02:46:42 +02:00
|
|
|
raise Discourse::InvalidParameters.new(
|
2023-10-03 00:18:00 +02:00
|
|
|
I18n.t('wizard.error_messages.wizard_replacing_composer')
|
|
|
|
)
|
2023-09-20 02:46:42 +02:00
|
|
|
end
|
|
|
|
end
|
2017-09-23 04:34:07 +02:00
|
|
|
end
|