From e584123d343b2785c7cd4734cc4d9dba70d93b52 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Thu, 12 Dec 2019 10:53:13 +1100 Subject: [PATCH] FIX: extension module prepending --- controllers/application_controller.rb | 10 +++++--- serializers/site_serializer.rb | 11 +++++---- serializers/wizard_field_serializer.rb | 10 +++++--- serializers/wizard_serializer.rb | 34 ++++++++++++++------------ serializers/wizard_step_serializer.rb | 10 +++++--- 5 files changed, 42 insertions(+), 33 deletions(-) diff --git a/controllers/application_controller.rb b/controllers/application_controller.rb index 5e6358d2..a9ae33ab 100644 --- a/controllers/application_controller.rb +++ b/controllers/application_controller.rb @@ -1,8 +1,10 @@ -module ApplicationControllerCWExtension +module CustomWizardApplicationControllerExtension extend ActiveSupport::Concern - included do - before_action :redirect_to_wizard_if_required, if: :current_user + 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 @@ -23,5 +25,5 @@ module ApplicationControllerCWExtension end class ApplicationController - prepend ApplicationControllerCWExtension if SiteSetting.custom_wizard_enabled + prepend CustomWizardApplicationControllerExtension if SiteSetting.custom_wizard_enabled end \ No newline at end of file diff --git a/serializers/site_serializer.rb b/serializers/site_serializer.rb index faff37c9..64e37173 100644 --- a/serializers/site_serializer.rb +++ b/serializers/site_serializer.rb @@ -1,11 +1,12 @@ ## TODO limit this to the first admin -module SiteSerializerCWX +module CustomWizardSiteSerializerExtension extend ActiveSupport::Concern - included do - attributes :complete_custom_wizard + 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? @@ -23,5 +24,5 @@ module SiteSerializerCWX end class SiteSerializer - prepend SiteSerializerCWX if SiteSetting.custom_wizard_enabled + prepend CustomWizardSiteSerializerExtension if SiteSetting.custom_wizard_enabled end \ No newline at end of file diff --git a/serializers/wizard_field_serializer.rb b/serializers/wizard_field_serializer.rb index c1ef779f..873f8735 100644 --- a/serializers/wizard_field_serializer.rb +++ b/serializers/wizard_field_serializer.rb @@ -1,8 +1,10 @@ -module CustomWizardWizardFieldSerializerExtension +module CustomWizardFieldSerializerExtension extend ActiveSupport::Concern - included do - attributes :dropdown_none, :image, :file_types, :limit, :property + def self.prepended(klass) + klass.class_eval do + attributes :dropdown_none, :image, :file_types, :limit, :property + end end def label @@ -45,5 +47,5 @@ module CustomWizardWizardFieldSerializerExtension end class WizardFieldSerializer - prepend CustomWizardWizardFieldSerializerExtension if SiteSetting.custom_wizard_enabled + prepend CustomWizardFieldSerializerExtension if SiteSetting.custom_wizard_enabled end \ No newline at end of file diff --git a/serializers/wizard_serializer.rb b/serializers/wizard_serializer.rb index 9cd97f26..c39ecdb0 100644 --- a/serializers/wizard_serializer.rb +++ b/serializers/wizard_serializer.rb @@ -1,19 +1,21 @@ -module CustomWizardWizardSerializerExtension +module CustomWizardSerializerExtension extend ActiveSupport::Concern - included do - attributes :id, - :name, - :background, - :completed, - :required, - :min_trust, - :permitted, - :user, - :categories, - :uncategorized_category_id + def self.prepended(klass) + klass.class_eval do + attributes :id, + :name, + :background, + :completed, + :required, + :min_trust, + :permitted, + :user, + :categories, + :uncategorized_category_id + end end - + def id object.id end @@ -89,7 +91,7 @@ module CustomWizardWizardSerializerExtension site = ::Site.new(scope) ::ActiveModel::ArraySerializer.new(site.categories, each_serializer: BasicCategorySerializer) rescue => e - puts "HERE IS THE ERROR: #{e.inspect}" + [] end end @@ -98,6 +100,6 @@ module CustomWizardWizardSerializerExtension end end -class WizardSerializer - prepend CustomWizardWizardSerializerExtension if SiteSetting.custom_wizard_enabled +class WizardSerializer + prepend CustomWizardSerializerExtension if SiteSetting.custom_wizard_enabled end \ No newline at end of file diff --git a/serializers/wizard_step_serializer.rb b/serializers/wizard_step_serializer.rb index e3774069..e4e120bb 100644 --- a/serializers/wizard_step_serializer.rb +++ b/serializers/wizard_step_serializer.rb @@ -1,8 +1,10 @@ -module CustomWizardWizardStepSerializerExtension +module CustomWizardStepSerializerExtension extend ActiveSupport::Concern - included do - attributes :permitted, :permitted_message + def self.prepended(klass) + klass.class_eval do + attributes :permitted, :permitted_message + end end def title @@ -25,5 +27,5 @@ module CustomWizardWizardStepSerializerExtension end class WizardStepSerializer - prepend CustomWizardWizardStepSerializerExtension if SiteSetting.custom_wizard_enabled + prepend CustomWizardStepSerializerExtension if SiteSetting.custom_wizard_enabled end \ No newline at end of file