Sha256: 75a7918672d67ca7a4aaee52416212cec428adc44fba210b874fdf3333a4f398

Contents?: true

Size: 1.44 KB

Versions: 13

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

module Decidim
  module ParticipatoryProcesses
    # This class infers the current participatory process we are scoped to by
    # looking at the request parameters and the organization in the request
    # environment, and injects it into the environment.
    class CurrentParticipatoryProcess
      # Public: Matches the request against a participatory process and injects it
      #         into the environment.
      #
      # request - The request that holds the participatory process 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_participatory_process(env, request.params) ? true : false
      end

      private

      def current_participatory_process(env, params)
        env["decidim.current_participatory_space"] ||=
          detect_current_participatory_process(params)
      end

      def detect_current_participatory_process(params)
        organization_processes.where(slug: params["participatory_process_slug"]).or(
          organization_processes.where(id: params["participatory_process_slug"])
        ).first!
      end

      def organization_processes
        @organization_processes ||= OrganizationParticipatoryProcesses.new(@organization).query
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
decidim-participatory_processes-0.29.1 app/constraints/decidim/participatory_processes/current_participatory_process.rb
decidim-participatory_processes-0.28.4 app/constraints/decidim/participatory_processes/current_participatory_process.rb
decidim-participatory_processes-0.29.0 app/constraints/decidim/participatory_processes/current_participatory_process.rb
decidim-participatory_processes-0.28.3 app/constraints/decidim/participatory_processes/current_participatory_process.rb
decidim-participatory_processes-0.29.0.rc4 app/constraints/decidim/participatory_processes/current_participatory_process.rb
decidim-participatory_processes-0.29.0.rc3 app/constraints/decidim/participatory_processes/current_participatory_process.rb
decidim-participatory_processes-0.29.0.rc2 app/constraints/decidim/participatory_processes/current_participatory_process.rb
decidim-participatory_processes-0.29.0.rc1 app/constraints/decidim/participatory_processes/current_participatory_process.rb
decidim-participatory_processes-0.28.2 app/constraints/decidim/participatory_processes/current_participatory_process.rb
decidim-participatory_processes-0.28.1 app/constraints/decidim/participatory_processes/current_participatory_process.rb
decidim-participatory_processes-0.28.0 app/constraints/decidim/participatory_processes/current_participatory_process.rb
decidim-participatory_processes-0.28.0.rc5 app/constraints/decidim/participatory_processes/current_participatory_process.rb
decidim-participatory_processes-0.28.0.rc4 app/constraints/decidim/participatory_processes/current_participatory_process.rb