Sha256: cc6863043d45e91b01da82e0e1f17dc2ab0cc84a0c2c220f22023d38604733fc

Contents?: true

Size: 1.66 KB

Versions: 28

Compression:

Stored size: 1.66 KB

Contents

module Locomotive
  module Concerns

    # When called, the within_site method enhances the controller by:
    #
    #   - checking if the user is requesting an existing Locomotive site
    #   - checking if the user is a member of this site (can be disabled)
    #   - setting the current timezone defined by the site
    #
    # Thus, this module requires the follow concerns:
    #   - SiteDispatcher
    #   - Membership
    #   - Timezone
    #
    module WithinSiteController

      extend ActiveSupport::Concern

      included do

        include Locomotive::Concerns::SiteDispatcherController
        include Locomotive::Concerns::TimezoneController
        include Locomotive::Concerns::MembershipController
        include Locomotive::Concerns::LocaleHelpersController

        helper  Locomotive::Shared::SitesHelper,
                Locomotive::Shared::AccountsHelper,
                Locomotive::Shared::PagesHelper,
                Locomotive::Shared::SiteMetafieldsHelper,
                Locomotive::ContentTypesHelper

      end

      module ClassMethods

        def within_site_only_if_existing(guest = false)
          within_site(false, guest)
        end

        def within_site_but_as_guest
          within_site(true, true)
        end

        def within_site(required = true, guest = false)
          class_eval do
            before_action :require_site if required

            unless guest
              before_action :validate_site_membership, if: :current_site?
            end

            around_action :set_timezone, if: :current_site?

            before_action :set_current_content_locale, if: :current_site?
          end
        end

      end
    end

  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
locomotivecms-4.2.0.alpha2 app/controllers/locomotive/concerns/within_site_controller.rb
locomotivecms-4.2.0.alpha1 app/controllers/locomotive/concerns/within_site_controller.rb
locomotivecms-4.1.1 app/controllers/locomotive/concerns/within_site_controller.rb
locomotivecms-4.1.0 app/controllers/locomotive/concerns/within_site_controller.rb
locomotivecms-4.1.0.rc1 app/controllers/locomotive/concerns/within_site_controller.rb
locomotivecms-4.0.3 app/controllers/locomotive/concerns/within_site_controller.rb
locomotivecms-4.0.2 app/controllers/locomotive/concerns/within_site_controller.rb
locomotivecms-4.0.1 app/controllers/locomotive/concerns/within_site_controller.rb
locomotivecms-4.0.0 app/controllers/locomotive/concerns/within_site_controller.rb
locomotivecms-4.0.0.rc0 app/controllers/locomotive/concerns/within_site_controller.rb
locomotivecms-4.0.0.alpha3 app/controllers/locomotive/concerns/within_site_controller.rb
locomotivecms-3.4.1 app/controllers/locomotive/concerns/within_site_controller.rb
locomotivecms-4.0.0.alpha2 app/controllers/locomotive/concerns/within_site_controller.rb
locomotivecms-4.0.0.alpha1 app/controllers/locomotive/concerns/within_site_controller.rb
locomotivecms-3.4.0 app/controllers/locomotive/concerns/within_site_controller.rb
locomotivecms-3.3.0 app/controllers/locomotive/concerns/within_site_controller.rb
locomotivecms-3.3.0.rc3 app/controllers/locomotive/concerns/within_site_controller.rb
locomotivecms-3.3.0.rc2 app/controllers/locomotive/concerns/within_site_controller.rb
locomotivecms-3.1.2 app/controllers/locomotive/concerns/within_site_controller.rb
locomotivecms-3.2.1 app/controllers/locomotive/concerns/within_site_controller.rb