2017-09-23 04:34:07 +02:00
|
|
|
# name: discourse-custom-wizard
|
2017-10-05 02:36:46 +02:00
|
|
|
# about: Create custom wizards
|
2020-04-14 14:12:43 +02:00
|
|
|
# version: 0.2
|
2017-09-23 04:34:07 +02:00
|
|
|
# authors: Angus McLeod
|
2018-01-12 08:23:57 +01:00
|
|
|
# url: https://github.com/angusmcleod/discourse-custom-wizard
|
2017-09-23 04:34:07 +02:00
|
|
|
|
2020-04-01 07:03:26 +02:00
|
|
|
register_asset 'stylesheets/common/wizard-admin.scss'
|
|
|
|
register_asset 'stylesheets/common/wizard-mapper.scss'
|
2017-11-01 05:21:14 +01:00
|
|
|
register_asset 'lib/jquery.timepicker.min.js'
|
|
|
|
register_asset 'lib/jquery.timepicker.scss'
|
2017-09-23 04:34:07 +02:00
|
|
|
|
2019-12-05 07:48:32 +01:00
|
|
|
enabled_site_setting :custom_wizard_enabled
|
|
|
|
|
2017-09-25 16:47:40 +02:00
|
|
|
config = Rails.application.config
|
2019-12-05 09:05:21 +01:00
|
|
|
plugin_asset_path = "#{Rails.root}/plugins/discourse-custom-wizard/assets"
|
|
|
|
config.assets.paths << "#{plugin_asset_path}/javascripts"
|
|
|
|
config.assets.paths << "#{plugin_asset_path}/stylesheets/wizard"
|
2017-09-25 16:47:40 +02:00
|
|
|
|
2017-11-01 12:47:27 +01:00
|
|
|
if Rails.env.production?
|
2017-12-03 08:57:54 +01:00
|
|
|
config.assets.precompile += %w{
|
2019-10-09 01:09:30 +02:00
|
|
|
wizard-custom-guest.js
|
2020-10-02 07:03:26 +02:00
|
|
|
wizard-custom-globals.js
|
2017-12-03 08:57:54 +01:00
|
|
|
wizard-custom.js
|
2019-01-18 01:34:52 +01:00
|
|
|
wizard-custom-start.js
|
2020-10-02 10:07:16 +02:00
|
|
|
wizard-plugin.js.erb
|
2019-01-29 01:42:23 +01:00
|
|
|
wizard-raw-templates.js.erb
|
2017-12-03 08:57:54 +01:00
|
|
|
}
|
2017-11-01 12:47:27 +01:00
|
|
|
end
|
|
|
|
|
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"
|
|
|
|
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
|
2020-04-13 14:17:22 +02:00
|
|
|
../controllers/custom_wizard/admin/admin.rb
|
|
|
|
../controllers/custom_wizard/admin/wizard.rb
|
|
|
|
../controllers/custom_wizard/admin/submissions.rb
|
|
|
|
../controllers/custom_wizard/admin/api.rb
|
2020-04-15 02:46:44 +02:00
|
|
|
../controllers/custom_wizard/admin/logs.rb
|
2020-03-30 08:16:03 +02:00
|
|
|
../controllers/custom_wizard/wizard.rb
|
|
|
|
../controllers/custom_wizard/steps.rb
|
|
|
|
../controllers/custom_wizard/transfer.rb
|
|
|
|
../jobs/clear_after_time_wizard.rb
|
|
|
|
../jobs/refresh_api_access_token.rb
|
|
|
|
../jobs/set_after_time_wizard.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
|
|
|
|
../lib/custom_wizard/field.rb
|
|
|
|
../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
|
2020-10-31 08:05:50 +01:00
|
|
|
../lib/custom_wizard/template.rb
|
2020-04-13 14:17:22 +02:00
|
|
|
../lib/custom_wizard/validator.rb
|
2020-03-30 08:16:03 +02:00
|
|
|
../lib/custom_wizard/wizard.rb
|
|
|
|
../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
|
|
|
|
../serializers/custom_wizard/api/authorization_serializer.rb
|
|
|
|
../serializers/custom_wizard/api/basic_endpoint_serializer.rb
|
|
|
|
../serializers/custom_wizard/api/endpoint_serializer.rb
|
|
|
|
../serializers/custom_wizard/api/log_serializer.rb
|
|
|
|
../serializers/custom_wizard/api_serializer.rb
|
|
|
|
../serializers/custom_wizard/basic_api_serializer.rb
|
2020-04-13 14:17:22 +02:00
|
|
|
../serializers/custom_wizard/basic_wizard_serializer.rb
|
2020-03-30 08:16:03 +02:00
|
|
|
../serializers/custom_wizard/wizard_field_serializer.rb
|
|
|
|
../serializers/custom_wizard/wizard_step_serializer.rb
|
|
|
|
../serializers/custom_wizard/wizard_serializer.rb
|
2020-04-15 02:46:44 +02:00
|
|
|
../serializers/custom_wizard/log_serializer.rb
|
2020-04-19 08:06:18 +02:00
|
|
|
../extensions/extra_locales_controller.rb
|
|
|
|
../extensions/invites_controller.rb
|
2020-09-16 15:35:07 +02:00
|
|
|
../extensions/users_controller.rb
|
2020-04-29 04:36:44 +02:00
|
|
|
../extensions/wizard_field.rb
|
|
|
|
../extensions/wizard_step.rb
|
2019-12-05 07:48:32 +01:00
|
|
|
].each do |path|
|
|
|
|
load File.expand_path(path, __FILE__)
|
|
|
|
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)
|
2017-10-15 05:58:22 +02:00
|
|
|
|
2020-03-30 08:16:03 +02:00
|
|
|
if !wizard.completed?
|
2019-12-05 09:05:21 +01:00
|
|
|
custom_redirect = true
|
2020-04-13 14:17:22 +02:00
|
|
|
CustomWizard::Wizard.set_wizard_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
|
|
|
|
|
2019-12-05 09:05:21 +01:00
|
|
|
add_to_class(:users_controller, :wizard_path) do
|
|
|
|
if custom_wizard_redirect = current_user.custom_fields['redirect_to_wizard']
|
|
|
|
"#{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
|
|
|
|
object.custom_fields['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)
|
|
|
|
CustomWizard::Wizard.set_wizard_redirect(wizard.id, user)
|
2018-06-05 04:25:44 +02:00
|
|
|
end
|
|
|
|
end
|
2020-04-19 08:06:18 +02:00
|
|
|
|
|
|
|
add_to_class(:application_controller, :redirect_to_wizard_if_required) do
|
|
|
|
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.referer !~ /\/w\// && request.referer !~ /\/invites\//
|
|
|
|
CustomWizard::Wizard.set_submission_redirect(current_user, wizard_id, request.referer)
|
|
|
|
end
|
2018-06-05 04:25:44 +02:00
|
|
|
|
2020-04-19 08:06:18 +02:00
|
|
|
if CustomWizard::Wizard.exists?(wizard_id)
|
|
|
|
redirect_to "/w/#{wizard_id.dasherize}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
add_to_serializer(:site, :include_wizard_required?) do
|
|
|
|
scope.is_admin? && Wizard.new(scope.user).requires_completion?
|
|
|
|
end
|
|
|
|
|
|
|
|
add_to_serializer(:site, :complete_custom_wizard) do
|
|
|
|
if scope.user && requires_completion = CustomWizard::Wizard.prompt_completion(scope.user)
|
|
|
|
requires_completion.map {|w| { name: w[:name], url: "/w/#{w[:id]}"} }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
add_to_serializer(:site, :include_complete_custom_wizard?) do
|
|
|
|
complete_custom_wizard.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
add_model_callback(:application_controller, :before_action) do
|
|
|
|
redirect_to_wizard_if_required if current_user
|
|
|
|
end
|
|
|
|
|
2020-04-30 02:54:30 +02:00
|
|
|
::ExtraLocalesController.prepend ExtraLocalesControllerCustomWizard
|
|
|
|
::InvitesController.prepend InvitesControllerCustomWizard
|
2020-09-16 15:35:07 +02:00
|
|
|
::UsersController.prepend CustomWizardUsersController
|
2020-04-30 02:54:30 +02:00
|
|
|
::Wizard::Field.prepend CustomWizardFieldExtension
|
|
|
|
::Wizard::Step.prepend CustomWizardStepExtension
|
2020-04-19 08:06:18 +02:00
|
|
|
|
2020-10-31 08:05:50 +01:00
|
|
|
full_path = "#{Rails.root}/plugins/discourse-custom-wizard/assets/stylesheets/wizard/wizard_custom.scss"
|
|
|
|
DiscoursePluginRegistry.register_asset(full_path, {}, "wizard_custom")
|
|
|
|
Stylesheet::Importer.register_import("wizard_custom") do
|
|
|
|
import_files(DiscoursePluginRegistry.stylesheets["wizard_custom"])
|
|
|
|
end
|
2020-08-19 06:41:20 +02:00
|
|
|
|
2018-01-16 08:13:50 +01:00
|
|
|
DiscourseEvent.trigger(:custom_wizard_ready)
|
2017-09-23 04:34:07 +02:00
|
|
|
end
|