Class: Decidim::Elections::CurrentUserVoteFlow

Inherits:
VoteFlow
  • Object
show all
Defined in:
decidim-elections/app/services/decidim/elections/current_user_vote_flow.rb

Overview

Service that encapsulates the vote flow used for elections for registered users.

Instance Method Summary collapse

Methods inherited from VoteFlow

#valid_received_data?, #voter_from_token, #voter_id, #voter_id_token, #voter_token

Constructor Details

#initialize(election, current_user, &can_vote_block) ⇒ CurrentUserVoteFlow

Returns a new instance of CurrentUserVoteFlow.


7
8
9
10
11
12
# File 'decidim-elections/app/services/decidim/elections/current_user_vote_flow.rb', line 7

def initialize(election, current_user, &can_vote_block)
  super(election)

  @current_user = current_user
  @can_vote_block = can_vote_block
end

Instance Method Details

#ballot_style_idObject


51
# File 'decidim-elections/app/services/decidim/elections/current_user_vote_flow.rb', line 51

def ballot_style_id; end

#has_voter?Boolean

Returns:

  • (Boolean)

18
19
20
# File 'decidim-elections/app/services/decidim/elections/current_user_vote_flow.rb', line 18

def has_voter?
  current_user.present?
end

#login_path(online_vote_path) ⇒ Object


45
# File 'decidim-elections/app/services/decidim/elections/current_user_vote_flow.rb', line 45

def (online_vote_path); end

#questions_for(election) ⇒ Object


47
48
49
# File 'decidim-elections/app/services/decidim/elections/current_user_vote_flow.rb', line 47

def questions_for(election)
  election.questions
end

#userObject


25
26
27
# File 'decidim-elections/app/services/decidim/elections/current_user_vote_flow.rb', line 25

def user
  current_user
end

#vote_checkObject


38
39
40
41
42
43
# File 'decidim-elections/app/services/decidim/elections/current_user_vote_flow.rb', line 38

def vote_check(*)
  VoteCheckResult.new(
    allowed: current_user && (received_voter_token || can_vote_block.call),
    error_message: I18n.t("votes.messages.not_allowed", scope: "decidim.elections")
  )
end

#voter_dataObject


29
30
31
32
33
34
35
36
# File 'decidim-elections/app/services/decidim/elections/current_user_vote_flow.rb', line 29

def voter_data
  return nil unless current_user

  {
    id: current_user.id,
    created: current_user.created_at.to_i
  }
end

#voter_login(params) ⇒ Object


14
15
16
# File 'decidim-elections/app/services/decidim/elections/current_user_vote_flow.rb', line 14

def (params)
  # There is no previous login page for this vote flow
end