Sha256: 919fda91486c419fc77488f7db65ff51e8bdedde369e598226c22318af3da36a

Contents?: true

Size: 1.32 KB

Versions: 60

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

module Decidim
  module Conferences
    # This class infers the current conference we're scoped to by
    # looking at the request parameters and the organization in the request
    # environment, and injects it into the environment.
    class CurrentConference
      # Public: Matches the request against an conference and injects it
      #         into the environment.
      #
      # request - The request that holds the conference 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_conference(env, request.params) ? true : false
      end

      private

      def current_conference(env, params)
        env["decidim.current_participatory_space"] ||=
          detect_current_conference(params)
      end

      def detect_current_conference(params)
        organization_conferences.where(slug: params["conference_slug"]).or(
          organization_conferences.where(id: params["conference_slug"])
        ).first!
      end

      def organization_conferences
        @organization_conferences ||= OrganizationConferences.new(@organization).query
      end
    end
  end
end

Version data entries

60 entries across 60 versions & 1 rubygems

Version Path
decidim-conferences-0.27.9 app/constraints/decidim/conferences/current_conference.rb
decidim-conferences-0.27.8 app/constraints/decidim/conferences/current_conference.rb
decidim-conferences-0.27.7 app/constraints/decidim/conferences/current_conference.rb
decidim-conferences-0.27.6 app/constraints/decidim/conferences/current_conference.rb
decidim-conferences-0.26.10 app/constraints/decidim/conferences/current_conference.rb
decidim-conferences-0.26.9 app/constraints/decidim/conferences/current_conference.rb
decidim-conferences-0.27.5 app/constraints/decidim/conferences/current_conference.rb
decidim-conferences-0.26.8 app/constraints/decidim/conferences/current_conference.rb
decidim-conferences-0.27.4 app/constraints/decidim/conferences/current_conference.rb
decidim-conferences-0.27.3 app/constraints/decidim/conferences/current_conference.rb
decidim-conferences-0.26.7 app/constraints/decidim/conferences/current_conference.rb
decidim-conferences-0.26.5 app/constraints/decidim/conferences/current_conference.rb
decidim-conferences-0.27.2 app/constraints/decidim/conferences/current_conference.rb
decidim-conferences-0.27.1 app/constraints/decidim/conferences/current_conference.rb
decidim-conferences-0.26.4 app/constraints/decidim/conferences/current_conference.rb
decidim-conferences-0.27.0 app/constraints/decidim/conferences/current_conference.rb
decidim-conferences-0.26.3 app/constraints/decidim/conferences/current_conference.rb
decidim-conferences-0.27.0.rc2 app/constraints/decidim/conferences/current_conference.rb
decidim-conferences-0.27.0.rc1 app/constraints/decidim/conferences/current_conference.rb
decidim-conferences-0.26.2 app/constraints/decidim/conferences/current_conference.rb