Hide poll results and stats to admins

This commit is contained in:
decabeza
2019-01-23 17:43:05 +01:00
parent ad355d4df6
commit 62088bc635
2 changed files with 18 additions and 13 deletions

View File

@@ -1,10 +1,8 @@
<% if current_user && current_user.administrator? ||
(@poll.expired? && (@poll.results_enabled? || @poll.stats_enabled?)) %>
<div class="row margin-top"> <div class="row margin-top">
<div class="small-12 column"> <div class="small-12 column">
<ul class="menu simple clear"> <ul class="menu simple clear">
<% if current_user && current_user.administrator? || @poll.results_enabled? %>
<% if controller_name == "polls" && action_name == "results" %> <% if controller_name == "polls" && action_name == "results" %>
<% if @poll.results_enabled? %>
<li class="is-active"> <li class="is-active">
<h2><%= t("polls.show.results_menu") %></h2> <h2><%= t("polls.show.results_menu") %></h2>
</li> </li>
@@ -13,8 +11,8 @@
<% end %> <% end %>
<% end %> <% end %>
<% if current_user && current_user.administrator? || @poll.stats_enabled? %>
<% if controller_name == "polls" && action_name == "stats" %> <% if controller_name == "polls" && action_name == "stats" %>
<% if @poll.stats_enabled? %>
<li class="is-active"> <li class="is-active">
<h2><%= t("polls.show.stats_menu") %></h2> <h2><%= t("polls.show.stats_menu") %></h2>
</li> </li>

View File

@@ -474,21 +474,28 @@ feature 'Polls' do
expect(page).to have_content("You do not have permission to carry out the action 'stats' on poll.") expect(page).to have_content("You do not have permission to carry out the action 'stats' on poll.")
end end
scenario "Show poll results and stats if user is administrator" do scenario "Do not show poll results or stats if are disabled" do
poll = create(:poll, :current, results_enabled: false, stats_enabled: false) poll = create(:poll, :expired, results_enabled: false, stats_enabled: false)
user = create(:administrator).user question1 = create(:poll_question, poll: poll)
create(:poll_question_answer, question: question1, title: "Han Solo")
create(:poll_question_answer, question: question1, title: "Chewbacca")
question2 = create(:poll_question, poll: poll)
create(:poll_question_answer, question: question2, title: "Leia")
create(:poll_question_answer, question: question2, title: "Luke")
user = create(:user)
admin = create(:administrator).user
login_as user login_as user
visit poll_path(poll) visit poll_path(poll)
expect(page).to have_content("Poll results") expect(page).not_to have_content("Poll results")
expect(page).to have_content("Participation statistics") expect(page).not_to have_content("Participation statistics")
visit results_poll_path(poll) login_as admin
expect(page).to have_content("Questions") visit poll_path(poll)
visit stats_poll_path(poll) expect(page).not_to have_content("Poll results")
expect(page).to have_content("Participation data") expect(page).not_to have_content("Participation statistics")
end end
end end
end end