Sha256: 06fa84d1be0bdb9ed260623ac48cf91efb9a9c4d1ca219c1167396b4297d093d

Contents?: true

Size: 1.43 KB

Versions: 11

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

module Decidim
  module ParticipatoryProcesses
    # This class infers the current participatory process we're 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_id"])
        ).first!
      end

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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
decidim-participatory_processes-0.9.0 app/constraints/decidim/participatory_processes/current_participatory_process.rb
decidim-participatory_processes-0.8.4 app/constraints/decidim/participatory_processes/current_participatory_process.rb
decidim-participatory_processes-0.8.3 app/constraints/decidim/participatory_processes/current_participatory_process.rb
decidim-participatory_processes-0.8.2 app/constraints/decidim/participatory_processes/current_participatory_process.rb
decidim-participatory_processes-0.8.1 app/constraints/decidim/participatory_processes/current_participatory_process.rb
decidim-participatory_processes-0.8.0 app/constraints/decidim/participatory_processes/current_participatory_process.rb
decidim-participatory_processes-0.7.4 app/constraints/decidim/participatory_processes/current_participatory_process.rb
decidim-participatory_processes-0.7.3 app/constraints/decidim/participatory_processes/current_participatory_process.rb
decidim-participatory_processes-0.7.2 app/constraints/decidim/participatory_processes/current_participatory_process.rb
decidim-participatory_processes-0.7.1 app/constraints/decidim/participatory_processes/current_participatory_process.rb
decidim-participatory_processes-0.7.0 app/constraints/decidim/participatory_processes/current_participatory_process.rb