Sha256: 39310d1014d5b16f4c7319f49e8aeec10a68f9ffb17c0f5a948c9c81b69c1e95

Contents?: true

Size: 1.61 KB

Versions: 14

Compression:

Stored size: 1.61 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::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

14 entries across 14 versions & 1 rubygems

Version Path
locomotivecms-3.1.0.rc1 app/controllers/locomotive/concerns/within_site_controller.rb
locomotivecms-3.0.1 app/controllers/locomotive/concerns/within_site_controller.rb
locomotivecms-3.0.0 app/controllers/locomotive/concerns/within_site_controller.rb
locomotivecms-3.0.0.rc7 app/controllers/locomotive/concerns/within_site_controller.rb
locomotivecms-3.0.0.rc6 app/controllers/locomotive/concerns/within_site_controller.rb
locomotivecms-3.0.0.rc5 app/controllers/locomotive/concerns/within_site_controller.rb
locomotivecms-3.0.0.rc4 app/controllers/locomotive/concerns/within_site_controller.rb
locomotivecms-3.0.0.rc3 app/controllers/locomotive/concerns/within_site_controller.rb
locomotivecms-3.0.0.rc2 app/controllers/locomotive/concerns/within_site_controller.rb
locomotivecms-3.0.0.rc1 app/controllers/locomotive/concerns/within_site_controller.rb
locomotivecms-3.0.0.pre.beta.1 app/controllers/locomotive/concerns/within_site_controller.rb
locomotivecms-3.0.0.pre.alpha.3 app/controllers/locomotive/concerns/within_site_controller.rb
locomotivecms-3.0.0.pre.alpha.2 app/controllers/locomotive/concerns/within_site_controller.rb
locomotivecms-3.0.0.pre.alpha app/controllers/locomotive/concerns/within_site_controller.rb