Sha256: 842bea130b4cc7bca9f905852c9f8a06a6e8b5dbf1f20ee31e417730afcbedc8

Contents?: true

Size: 1.41 KB

Versions: 9

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

module Decidim
  module Assemblies
    # This module, when injected into a controller, ensures there's a
    # Assembly available and deducts it from the context.
    module NeedsAssembly
      def self.enhance_controller(instance_or_module)
        instance_or_module.class_eval do
          helper_method :current_assembly
        end
      end

      def self.extended(base)
        base.extend Decidim::NeedsOrganization, InstanceMethods

        enhance_controller(base)
      end

      def self.included(base)
        base.include Decidim::NeedsOrganization, InstanceMethods

        enhance_controller(base)
      end

      module InstanceMethods
        # Public: Finds the current Assembly given this controller's
        # context.
        #
        # Returns the current Assembly.
        def current_assembly
          @current_assembly ||= detect_assembly
        end

        alias current_participatory_space current_assembly

        private

        def ability_context
          super.merge(current_assembly: current_assembly)
        end

        def detect_assembly
          request.env["current_assembly"] ||
            organization_assemblies.find_by!(slug: params[:assembly_slug] || params[:slug])
        end

        def organization_assemblies
          @organization_assemblies ||= OrganizationAssemblies.new(current_organization).query
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
decidim-assemblies-0.8.3 app/controllers/concerns/decidim/assemblies/needs_assembly.rb
decidim-assemblies-0.8.2 app/controllers/concerns/decidim/assemblies/needs_assembly.rb
decidim-assemblies-0.8.1 app/controllers/concerns/decidim/assemblies/needs_assembly.rb
decidim-assemblies-0.8.0 app/controllers/concerns/decidim/assemblies/needs_assembly.rb
decidim-assemblies-0.7.4 app/controllers/concerns/decidim/assemblies/needs_assembly.rb
decidim-assemblies-0.7.3 app/controllers/concerns/decidim/assemblies/needs_assembly.rb
decidim-assemblies-0.7.2 app/controllers/concerns/decidim/assemblies/needs_assembly.rb
decidim-assemblies-0.7.1 app/controllers/concerns/decidim/assemblies/needs_assembly.rb
decidim-assemblies-0.7.0 app/controllers/concerns/decidim/assemblies/needs_assembly.rb