Sha256: f91c37f5db55ef6c4f080dcec46dbc23249cce37ed5f189d4484be8cb6246882

Contents?: true

Size: 1.1 KB

Versions: 18

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module Decidim
  module Assemblies
    # This class infers the current assembly we're scoped to by
    # looking at the request parameters and the organization in the request
    # environment, and injects it into the environment.
    class CurrentAssembly
      # Public: Matches the request against an assembly and injects it
      #         into the environment.
      #
      # request - The request that holds the assembly relevant
      #           information.
      #
      # Returns a true if the request matched, false otherwise
      def matches?(request)
        env = request.env

        @organization = env["decidim.current_organization"]
        return false unless @organization

        current_assembly(env, request.params) ? true : false
      end

      private

      def current_assembly(env, params)
        env["decidim.current_participatory_space"] ||=
          detect_current_assembly(params)
      end

      def detect_current_assembly(params)
        OrganizationAssemblies.new(@organization).query.find_by_id(params["assembly_id"])
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
decidim-assemblies-0.6.8 app/constraints/decidim/assemblies/current_assembly.rb
decidim-0.6.8 decidim-assemblies/app/constraints/decidim/assemblies/current_assembly.rb
decidim-assemblies-0.6.7 app/constraints/decidim/assemblies/current_assembly.rb
decidim-0.6.7 decidim-assemblies/app/constraints/decidim/assemblies/current_assembly.rb
decidim-assemblies-0.6.6 app/constraints/decidim/assemblies/current_assembly.rb
decidim-0.6.6 decidim-assemblies/app/constraints/decidim/assemblies/current_assembly.rb
decidim-assemblies-0.6.5 app/constraints/decidim/assemblies/current_assembly.rb
decidim-0.6.5 decidim-assemblies/app/constraints/decidim/assemblies/current_assembly.rb
decidim-assemblies-0.6.4 app/constraints/decidim/assemblies/current_assembly.rb
decidim-0.6.4 decidim-assemblies/app/constraints/decidim/assemblies/current_assembly.rb
decidim-assemblies-0.6.3 app/constraints/decidim/assemblies/current_assembly.rb
decidim-0.6.3 decidim-assemblies/app/constraints/decidim/assemblies/current_assembly.rb
decidim-assemblies-0.6.2 app/constraints/decidim/assemblies/current_assembly.rb
decidim-0.6.2 decidim-assemblies/app/constraints/decidim/assemblies/current_assembly.rb
decidim-assemblies-0.6.1 app/constraints/decidim/assemblies/current_assembly.rb
decidim-0.6.1 decidim-assemblies/app/constraints/decidim/assemblies/current_assembly.rb
decidim-assemblies-0.6.0 app/constraints/decidim/assemblies/current_assembly.rb
decidim-0.6.0 decidim-assemblies/app/constraints/decidim/assemblies/current_assembly.rb