Require at least 2 candidates to open a vote

This commit is contained in:
ricola 2025-04-06 17:04:31 -06:00
parent 440013890e
commit dc01cb61ad
2 changed files with 9 additions and 2 deletions

View file

@ -57,7 +57,12 @@
<h3><%= _("Actions for organizers") %></h2>
<form action="/votes/<%= @vote.secure_id %>/open" method="post">
<% if @vote.candidates.length < 2 %>
<button type="submit" disabled><%= _("Open vote to participants") %></button>
<p><%= _("Add at least 2 candidates before opening the vote to participants.") %></p>
<% else %>
<button type="submit"><%= _("Open vote to participants") %></button>
<% end %>
</form>
<form action="/votes/<%= @vote.secure_id %>/delete" method="post">
<button type="submit"><%= _("Delete vote") %></button>

View file

@ -200,8 +200,10 @@ post '/votes/:id/open' do
find_vote
require_organizer
require_draft_vote
@vote.state = 'open'
@vote.save
if not @vote.candidates.length < 2
@vote.state = 'open'
@vote.save
end
redirect '/votes/' + @vote.secure_id
end