Sha256: 3f646f51857db0a3914783bb12b28311ddc62f451c0b7f5168414b07947d3105

Contents?: true

Size: 1.02 KB

Versions: 62

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module Decidim
  module Initiatives
    # This class infers the current initiative we're scoped to by
    # looking at the request parameters and the organization in the request
    # environment, and injects it into the environment.
    class CurrentInitiative
      include InitiativeSlug

      # Public: Matches the request against an initative and injects it
      #         into the environment.
      #
      # request - The request that holds the initiative 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_initiative(env, request.params) ? true : false
      end

      private

      def current_initiative(env, params)
        env["decidim.current_participatory_space"] ||= Initiative.find_by(id: id_from_slug(params[:initiative_slug]))
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
decidim-initiatives-0.27.1 app/constraints/decidim/initiatives/current_initiative.rb
decidim-initiatives-0.26.4 app/constraints/decidim/initiatives/current_initiative.rb
decidim-initiatives-0.27.0 app/constraints/decidim/initiatives/current_initiative.rb
decidim-initiatives-0.26.3 app/constraints/decidim/initiatives/current_initiative.rb
decidim-initiatives-0.27.0.rc2 app/constraints/decidim/initiatives/current_initiative.rb
decidim-initiatives-0.27.0.rc1 app/constraints/decidim/initiatives/current_initiative.rb
decidim-initiatives-0.26.2 app/constraints/decidim/initiatives/current_initiative.rb
decidim-initiatives-0.26.1 app/constraints/decidim/initiatives/current_initiative.rb
decidim-initiatives-0.26.0 app/constraints/decidim/initiatives/current_initiative.rb
decidim-initiatives-0.26.0.rc2 app/constraints/decidim/initiatives/current_initiative.rb
decidim-initiatives-0.26.0.rc1 app/constraints/decidim/initiatives/current_initiative.rb
decidim-initiatives-0.25.2 app/constraints/decidim/initiatives/current_initiative.rb
decidim-initiatives-0.25.1 app/constraints/decidim/initiatives/current_initiative.rb
decidim-initiatives-0.25.0 app/constraints/decidim/initiatives/current_initiative.rb
decidim-initiatives-0.25.0.rc4 app/constraints/decidim/initiatives/current_initiative.rb
decidim-initiatives-0.25.0.rc3 app/constraints/decidim/initiatives/current_initiative.rb
decidim-initiatives-0.25.0.rc2 app/constraints/decidim/initiatives/current_initiative.rb
decidim-initiatives-0.25.0.rc1 app/constraints/decidim/initiatives/current_initiative.rb
decidim-initiatives-0.24.3 app/constraints/decidim/initiatives/current_initiative.rb
decidim-initiatives-0.23.6 app/constraints/decidim/initiatives/current_initiative.rb