Sha256: 88f2da32d20a1b1d7cf744f01d6034930ce01697676e1c8c52af9a04c77f1616

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

require "active_support/concern"

module Decidim
  # This module, when injected into a controller, ensures there's a
  # Participatory Process available and deducts it from the context.
  module NeedsParticipatoryProcess
    extend ActiveSupport::Concern

    include NeedsOrganization

    included do
      after_action :verify_participatory_process
      helper_method :current_participatory_process

      # Public: Finds the current Participatory Process given this controller's
      # context.
      #
      # Returns the current ParticipatoryProcess.
      def current_participatory_process
        @current_participatory_process ||= detect_participatory_process
      end

      private

      def verify_participatory_process
        raise ActionController::RoutingError, "Participatory process not found." unless current_participatory_process
      end

      def detect_participatory_process
        request.env["current_participatory_process"] ||
          current_organization.participatory_processes.find_by(id: params[:participatory_process_id] || params[:id])
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
decidim-core-0.3.2 app/controllers/concerns/decidim/needs_participatory_process.rb
decidim-core-0.3.1 app/controllers/concerns/decidim/needs_participatory_process.rb
decidim-core-0.3.0 app/controllers/concerns/decidim/needs_participatory_process.rb