Don't allow to modify questions for started polls

Adding, modifiying, and/or deleting questions for an already started
poll is far away from being democratic and can lead to unwanted side
effects like missing votes in the results or stats.

So, from now on, only modifiying questions will be possible only if
the poll has not started yet.
This commit is contained in:
Julian Herrero
2022-09-15 16:36:50 +02:00
committed by Javi Martín
parent d499a6944e
commit 8a26954bc5
18 changed files with 277 additions and 47 deletions

View File

@@ -12,10 +12,10 @@
<%= f.hidden_field :poll_id, value: question.poll.id %>
<% else %>
<div class="small-12 medium-6 large-4 column">
<% select_options = Poll.all.map { |p| [p.name, p.id] } %>
<%= f.select :poll_id,
options_for_select(select_options),
prompt: t("admin.questions.index.select_poll") %>
prompt: t("admin.questions.index.select_poll"),
hint: t("admin.questions.form.poll_help") %>
</div>
<% end %>
</div>

View File

@@ -2,9 +2,18 @@ class Admin::Poll::Questions::FormComponent < ApplicationComponent
include TranslatableFormHelper
include GlobalizeHelper
attr_reader :question, :url
delegate :can?, to: :helpers
def initialize(question, url:)
@question = question
@url = url
end
private
def select_options
Poll.all.select { |poll| can?(:create, Poll::Question.new(poll: poll)) }.map do |poll|
[poll.name, poll.id]
end
end
end

View File

@@ -0,0 +1,3 @@
<%= render Admin::TableActionsComponent.new(question, actions: actions) do |table_actions| %>
<%= table_actions.action(:answers, text: t("admin.polls.show.edit_answers")) %>
<% end %>

View File

@@ -0,0 +1,14 @@
class Admin::Poll::Questions::TableActionsComponent < ApplicationComponent
attr_reader :question
delegate :can?, to: :helpers
def initialize(question)
@question = question
end
private
def actions
[:edit, :destroy].select { |action| can?(action, question) }
end
end