Sha256: fd4f1bc8bb19d569028a87f9aeca9e1338ef2140af0f9d657c8f16e0a811d57f

Contents?: true

Size: 830 Bytes

Versions: 4

Compression:

Stored size: 830 Bytes

Contents

# frozen_string_literal: true

require "active_support/concern"

module Decidim
  # Shared behaviour for controllers that need an organization present in order
  # to work. The organization is injected via the CurrentOrganization
  # middleware.
  module NeedsOrganization
    extend ActiveSupport::Concern

    included do
      before_action :verify_organization
      helper_method :current_organization

      # The current organization for the request.
      #
      # Returns an Organization.
      def current_organization
        @current_organization ||= request.env["decidim.current_organization"]
      end

      private

      # Raises a 404 if no organization is present.
      def verify_organization
        raise ActionController::RoutingError, "Not Found" unless current_organization
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
decidim-core-0.3.2 app/controllers/concerns/decidim/needs_organization.rb
decidim-core-0.3.1 app/controllers/concerns/decidim/needs_organization.rb
decidim-core-0.3.0 app/controllers/concerns/decidim/needs_organization.rb
decidim-core-0.2.0 app/controllers/concerns/decidim/needs_organization.rb