Sha256: a044074fdc50f5545d32bed57530394949e6d025cb3c666c00b22a0d4a3cd7eb

Contents?: true

Size: 1.18 KB

Versions: 31

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

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

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

        enhance_controller(base)
      end

      module InstanceMethods
        # Public: Finds the current Voting given this controller's
        # context.
        #
        # Returns the current Voting.
        def current_participatory_space
          @current_participatory_space ||= detect_voting
        end

        alias current_voting current_participatory_space

        private

        def detect_voting
          request.env["current_participatory_space"] ||
            organization_votings.find_by(slug: params[:voting_slug] || params[:slug])
        end

        def organization_votings
          @organization_votings ||= OrganizationVotings.new(current_organization).query
        end
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
decidim-elections-0.27.9 app/controllers/concerns/decidim/votings/needs_voting.rb
decidim-elections-0.27.8 app/controllers/concerns/decidim/votings/needs_voting.rb
decidim-elections-0.27.7 app/controllers/concerns/decidim/votings/needs_voting.rb
decidim-elections-0.27.6 app/controllers/concerns/decidim/votings/needs_voting.rb
decidim-elections-0.26.10 app/controllers/concerns/decidim/votings/needs_voting.rb
decidim-elections-0.26.9 app/controllers/concerns/decidim/votings/needs_voting.rb
decidim-elections-0.27.5 app/controllers/concerns/decidim/votings/needs_voting.rb
decidim-elections-0.26.8 app/controllers/concerns/decidim/votings/needs_voting.rb
decidim-elections-0.27.4 app/controllers/concerns/decidim/votings/needs_voting.rb
decidim-elections-0.27.3 app/controllers/concerns/decidim/votings/needs_voting.rb
decidim-elections-0.26.7 app/controllers/concerns/decidim/votings/needs_voting.rb
decidim-elections-0.26.5 app/controllers/concerns/decidim/votings/needs_voting.rb
decidim-elections-0.27.2 app/controllers/concerns/decidim/votings/needs_voting.rb
decidim-elections-0.27.1 app/controllers/concerns/decidim/votings/needs_voting.rb
decidim-elections-0.26.4 app/controllers/concerns/decidim/votings/needs_voting.rb
decidim-elections-0.27.0 app/controllers/concerns/decidim/votings/needs_voting.rb
decidim-elections-0.26.3 app/controllers/concerns/decidim/votings/needs_voting.rb
decidim-elections-0.27.0.rc2 app/controllers/concerns/decidim/votings/needs_voting.rb
decidim-elections-0.27.0.rc1 app/controllers/concerns/decidim/votings/needs_voting.rb
decidim-elections-0.26.2 app/controllers/concerns/decidim/votings/needs_voting.rb