Sha256: f0a18aed5d44b1d8059cb8239dc6216ceab75bbac9dc596fabf1bd9230a68be8

Contents?: true

Size: 1.12 KB

Versions: 7

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

require "active_support/concern"

module Decidim
  module Elections
    # Common logic for the vote flow
    module HasVoteFlow
      extend ActiveSupport::Concern

      included do
        helper_method :voter_id, :voter_token, :voter_name, :preview_mode?, :ballot_style_id
        delegate :voter_id, :ballot_style_id, :voter_token, :voter_name, :email, to: :vote_flow
      end

      def vote_flow
        @vote_flow ||= election.participatory_space.try(:vote_flow_for, election) || default_vote_flow
      end

      def default_vote_flow
        Decidim::Elections::CurrentUserVoteFlow.new(election, current_user) do
          allowed_to?(:user_vote, :election, election:)
        end
      end

      def preview_mode?
        return @preview_mode if defined?(@preview_mode)

        @preview_mode = !election.published? || !election.started?
      end

      def can_preview?
        return @can_preview if defined?(@can_preview)

        @preview_mode = allowed_to?(:preview, :election, election:)
      end

      def ballot_questions
        vote_flow.questions_for(election)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
decidim-elections-0.28.4 app/controllers/concerns/decidim/elections/has_vote_flow.rb
decidim-elections-0.28.3 app/controllers/concerns/decidim/elections/has_vote_flow.rb
decidim-elections-0.28.2 app/controllers/concerns/decidim/elections/has_vote_flow.rb
decidim-elections-0.28.1 app/controllers/concerns/decidim/elections/has_vote_flow.rb
decidim-elections-0.28.0 app/controllers/concerns/decidim/elections/has_vote_flow.rb
decidim-elections-0.28.0.rc5 app/controllers/concerns/decidim/elections/has_vote_flow.rb
decidim-elections-0.28.0.rc4 app/controllers/concerns/decidim/elections/has_vote_flow.rb