Class: Decidim::Votings::CensusVoteFlow

Inherits:
Elections::VoteFlow show all
Defined in:
decidim-elections/app/services/decidim/votings/census_vote_flow.rb

Overview

Service that encapsulates the vote flow used for Votings, using a census instead of users.

Instance Method Summary collapse

Methods inherited from Elections::VoteFlow

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

Constructor Details

This class inherits a constructor from Decidim::Elections::VoteFlow

Instance Method Details

#ballot_style_idObject



55
56
57
# File 'decidim-elections/app/services/decidim/votings/census_vote_flow.rb', line 55

def ballot_style_id
  ballot_style&.slug
end

#has_voter?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'decidim-elections/app/services/decidim/votings/census_vote_flow.rb', line 15

def has_voter?
  datum.present?
end

#login_path(online_vote_path) ⇒ Object



63
64
65
# File 'decidim-elections/app/services/decidim/votings/census_vote_flow.rb', line 63

def (online_vote_path)
  EngineRouter.main_proxy(election.component.participatory_space).(election_id: election.id, vote_path: online_vote_path) if online_vote_path
end

#questions_for(election) ⇒ Object



47
48
49
50
51
52
53
# File 'decidim-elections/app/services/decidim/votings/census_vote_flow.rb', line 47

def questions_for(election)
  if ballot_style.present?
    ballot_style.questions.where(election:)
  else
    election.questions
  end
end

#userObject



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

def user
  nil
end

#vote_check(online_vote_path: nil) ⇒ Object



39
40
41
42
43
44
45
# File 'decidim-elections/app/services/decidim/votings/census_vote_flow.rb', line 39

def vote_check(online_vote_path: nil)
  VoteCheckResult.new(
    allowed: has_voter? && !voted_in_person?,
    error_message: I18n.t("vote_flow.#{voted_in_person? ? "already_voted_in_person" : "datum_not_found"}", scope: "decidim.votings.census"),
    exit_path: (online_vote_path)
  )
end

#voted_in_person?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'decidim-elections/app/services/decidim/votings/census_vote_flow.rb', line 59

def voted_in_person?
  Decidim::Votings::Votes::InPersonVoteForVoter.for(election, voter_id)
end

#voter_dataObject



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

def voter_data
  return nil unless datum

  {
    id: datum.id,
    created: datum.created_at.to_i,
    name: datum.full_name
  }
end

#voter_in_person(params) ⇒ Object



11
12
13
# File 'decidim-elections/app/services/decidim/votings/census_vote_flow.rb', line 11

def voter_in_person(params)
  @in_person_params = params
end

#voter_login(params) ⇒ Object



7
8
9
# File 'decidim-elections/app/services/decidim/votings/census_vote_flow.rb', line 7

def (params)
  @login_params = params
end

#voter_nameObject



19
20
21
# File 'decidim-elections/app/services/decidim/votings/census_vote_flow.rb', line 19

def voter_name
  datum&.full_name
end