Sha256: 96d80353fb5b9c8ea96c2d43e9e53623fdbe54caa4c64269d97c7f1a68b72128

Contents?: true

Size: 1.37 KB

Versions: 52

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

module Decidim
  module Consultations
    # This module, when injected into a controller, ensures there's a
    # consultation available and deducts it from the context.
    module NeedsConsultation
      def self.enhance_controller(instance_or_module)
        instance_or_module.class_eval do
          helper_method :current_consultation
        end
      end

      def self.extended(base)
        base.extend Decidim::NeedsOrganization, InstanceMethods

        enhance_controller(base)
      end

      def self.included(base)
        base.include Decidim::NeedsOrganization, InstanceMethods

        enhance_controller(base)
      end

      module InstanceMethods
        # Public: Finds the current Consultation given this controller's
        # context.
        #
        # Returns the current Consultation.
        def current_consultation
          @current_consultation ||= detect_consultation
        end

        alias current_participatory_space current_consultation

        private

        def detect_consultation
          request.env["current_consultation"] ||
            organization_consultations.find_by(slug: params[:consultation_slug] || params[:slug])
        end

        def organization_consultations
          @organization_consultations ||= OrganizationConsultations.new(current_organization).query
        end
      end
    end
  end
end

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
decidim-consultations-0.23.3 app/controllers/concerns/decidim/consultations/needs_consultation.rb
decidim-consultations-0.23.2 app/controllers/concerns/decidim/consultations/needs_consultation.rb
decidim-consultations-0.23.1 app/controllers/concerns/decidim/consultations/needs_consultation.rb
decidim-consultations-0.23.1.rc1 app/controllers/concerns/decidim/consultations/needs_consultation.rb
decidim-consultations-0.23.0 app/controllers/concerns/decidim/consultations/needs_consultation.rb
decidim-consultations-0.22.0 app/controllers/concerns/decidim/consultations/needs_consultation.rb
decidim-consultations-0.21.0 app/controllers/concerns/decidim/consultations/needs_consultation.rb
decidim-consultations-0.20.1 app/controllers/concerns/decidim/consultations/needs_consultation.rb
decidim-consultations-0.20.0 app/controllers/concerns/decidim/consultations/needs_consultation.rb
decidim-consultations-0.19.1 app/controllers/concerns/decidim/consultations/needs_consultation.rb
decidim-consultations-0.18.1 app/controllers/concerns/decidim/consultations/needs_consultation.rb
decidim-consultations-0.19.0 app/controllers/concerns/decidim/consultations/needs_consultation.rb
decidim-consultations-0.17.2 app/controllers/concerns/decidim/consultations/needs_consultation.rb
decidim-consultations-0.18.0 app/controllers/concerns/decidim/consultations/needs_consultation.rb
decidim-consultations-0.17.1 app/controllers/concerns/decidim/consultations/needs_consultation.rb
decidim-consultations-0.16.1 app/controllers/concerns/decidim/consultations/needs_consultation.rb
decidim-consultations-0.17.0 app/controllers/concerns/decidim/consultations/needs_consultation.rb
decidim-consultations-0.16.0 app/controllers/concerns/decidim/consultations/needs_consultation.rb
decidim-consultations-0.15.2 app/controllers/concerns/decidim/consultations/needs_consultation.rb
decidim-consultations-0.15.1 app/controllers/concerns/decidim/consultations/needs_consultation.rb