Sha256: a94c144cdf195554dd1d5fc3c5e38ee92152608db0a9c19fc8aa81dceb20ceee

Contents?: true

Size: 1.02 KB

Versions: 13

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module Decidim
  module Initiatives
    # This class infers the current initiative we are 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 initiative 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

13 entries across 13 versions & 1 rubygems

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