Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-09 11:52:54 +01:00
Update structure
Dieser Commit ist enthalten in:
Ursprung
500c305701
Commit
02c6096395
6 geänderte Dateien mit 60 neuen und 87 gelöschten Zeilen
|
@ -1,29 +0,0 @@
|
|||
module CustomWizardApplicationControllerExtension
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def self.prepended(klass)
|
||||
klass.class_eval do
|
||||
before_action :redirect_to_wizard_if_required, if: :current_user
|
||||
end
|
||||
end
|
||||
|
||||
def redirect_to_wizard_if_required
|
||||
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
|
||||
|
||||
if CustomWizard::Wizard.exists?(wizard_id)
|
||||
redirect_to "/w/#{wizard_id.dasherize}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class ApplicationController
|
||||
prepend CustomWizardApplicationControllerExtension if SiteSetting.custom_wizard_enabled
|
||||
end
|
|
@ -1,20 +0,0 @@
|
|||
module CustomWizardExtraLocalesController
|
||||
def show
|
||||
if request.referer && URI(request.referer).path.include?('/w/')
|
||||
bundle = params[:bundle]
|
||||
|
||||
if params[:v]&.size == 32
|
||||
hash = ExtraLocalesController.bundle_js_hash(bundle)
|
||||
immutable_for(1.year) if hash == params[:v]
|
||||
end
|
||||
|
||||
render plain: ExtraLocalesController.bundle_js(bundle), content_type: "application/javascript"
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class ExtraLocalesController
|
||||
prepend CustomWizardExtraLocalesController if SiteSetting.custom_wizard_enabled
|
||||
end
|
16
extensions/extra_locales_controller.rb
Normale Datei
16
extensions/extra_locales_controller.rb
Normale Datei
|
@ -0,0 +1,16 @@
|
|||
module ExtraLocalesControllerCustomWizard
|
||||
def show
|
||||
if request.referer && URI(request.referer).path.include?('/w/')
|
||||
bundle = params[:bundle]
|
||||
|
||||
if params[:v]&.size == 32
|
||||
hash = ::ExtraLocalesController.bundle_js_hash(bundle)
|
||||
immutable_for(1.year) if hash == params[:v]
|
||||
end
|
||||
|
||||
render plain: ::ExtraLocalesController.bundle_js(bundle), content_type: "application/javascript"
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
module InvitesControllerCustomWizard
|
||||
def path(url)
|
||||
if Wizard.user_requires_completion?(@user)
|
||||
if ::Wizard.user_requires_completion?(@user)
|
||||
wizard_id = @user.custom_fields['custom_wizard_redirect']
|
||||
|
||||
if wizard_id && url != '/'
|
||||
|
@ -16,7 +16,3 @@ module InvitesControllerCustomWizard
|
|||
@user = user
|
||||
end
|
||||
end
|
||||
|
||||
class InvitesController
|
||||
prepend InvitesControllerCustomWizard if SiteSetting.custom_wizard_enabled
|
||||
end
|
47
plugin.rb
47
plugin.rb
|
@ -52,9 +52,6 @@ after_initialize do
|
|||
../controllers/custom_wizard/wizard.rb
|
||||
../controllers/custom_wizard/steps.rb
|
||||
../controllers/custom_wizard/transfer.rb
|
||||
../controllers/application_controller.rb
|
||||
../controllers/extra_locales_controller.rb
|
||||
../controllers/invites_controller.rb
|
||||
../jobs/clear_after_time_wizard.rb
|
||||
../jobs/refresh_api_access_token.rb
|
||||
../jobs/set_after_time_wizard.rb
|
||||
|
@ -83,7 +80,8 @@ after_initialize do
|
|||
../serializers/custom_wizard/wizard_step_serializer.rb
|
||||
../serializers/custom_wizard/wizard_serializer.rb
|
||||
../serializers/custom_wizard/log_serializer.rb
|
||||
../serializers/site_serializer.rb
|
||||
../extensions/extra_locales_controller.rb
|
||||
../extensions/invites_controller.rb
|
||||
].each do |path|
|
||||
load File.expand_path(path, __FILE__)
|
||||
end
|
||||
|
@ -125,5 +123,46 @@ after_initialize do
|
|||
end
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
reloadable_patch do |plugin|
|
||||
if enabled?
|
||||
::ExtraLocalesController.prepend ExtraLocalesControllerCustomWizard
|
||||
::InvitesController.prepend InvitesControllerCustomWizard
|
||||
end
|
||||
end
|
||||
|
||||
DiscourseEvent.trigger(:custom_wizard_ready)
|
||||
end
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
## TODO limit this to the first admin
|
||||
|
||||
module CustomWizardSiteSerializerExtension
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def self.prepended(klass)
|
||||
klass.class_eval do
|
||||
attributes :complete_custom_wizard
|
||||
end
|
||||
end
|
||||
|
||||
def include_wizard_required?
|
||||
scope.is_admin? && Wizard.new(scope.user).requires_completion?
|
||||
end
|
||||
|
||||
def complete_custom_wizard
|
||||
if scope.user && requires_completion = CustomWizard::Wizard.prompt_completion(scope.user)
|
||||
requires_completion.map {|w| { name: w[:name], url: "/w/#{w[:id]}"} }
|
||||
end
|
||||
end
|
||||
|
||||
def include_complete_custom_wizard?
|
||||
complete_custom_wizard.present?
|
||||
end
|
||||
end
|
||||
|
||||
class ::SiteSerializer
|
||||
prepend CustomWizardSiteSerializerExtension if SiteSetting.custom_wizard_enabled
|
||||
end
|
Laden …
In neuem Issue referenzieren