Added check in poll card that allows setting the value of
results_enabled flag.

Access to stats/results now is controlled with abilities.

Polls related to proposals will be accessible to the proposal author
like they were administrators.
This commit is contained in:
Juan Salvador Pérez García
2018-07-13 10:39:49 +02:00
parent 0daaf9e7db
commit f439fc7371
16 changed files with 93 additions and 10 deletions

View File

@@ -7,6 +7,7 @@ gem 'acts_as_votable', '~> 0.11.1'
gem 'ahoy_matey', '~> 1.6.0'
gem 'ancestry', '~> 3.0.1'
gem 'autoprefixer-rails', '~> 8.2.0'
gem 'best_in_place', '~> 3.0.1'
gem 'browser', '~> 2.5.2'
gem 'cancancan', '~> 2.1.2'
gem 'ckeditor', '~> 4.2.3'

View File

@@ -68,6 +68,9 @@ GEM
babel-source (>= 4.0, < 6)
execjs (~> 2.0)
bcrypt (3.1.11)
best_in_place (3.0.3)
actionpack (>= 3.2)
railties (>= 3.2)
browser (2.5.2)
builder (3.2.3)
bullet (5.7.1)
@@ -504,6 +507,7 @@ DEPENDENCIES
ahoy_matey (~> 1.6.0)
ancestry (~> 3.0.1)
autoprefixer-rails (~> 8.2.0)
best_in_place (~> 3.0.1)
browser (~> 2.5.2)
bullet (~> 5.7.0)
byebug (~> 10.0.0)

View File

@@ -17,6 +17,7 @@
//= require jquery-ui/widgets/autocomplete
//= require jquery-ui/widgets/sortable
//= require jquery-fileupload/basic
//= require best_in_place
//= require foundation
//= require turbolinks
//= require ckeditor/loader
@@ -81,6 +82,7 @@
//= require globalize
//= require clipboard
//= require clipboard_button
//= require best_in_place_initialize
var initialize_modules = function() {
App.Comments.initialize();
@@ -127,6 +129,7 @@ var initialize_modules = function() {
App.Managers.initialize();
App.Globalize.initialize();
App.ClipboardButton.initialize();
App.BestInPlace.initialize();
};
$(function(){

View File

@@ -0,0 +1,3 @@
App.BestInPlace =
initialize: ->
$('.best_in_place').best_in_place();

0
app/assets/javascripts/rem.min.js vendored Executable file → Normal file
View File

0
app/assets/javascripts/respond.min.js vendored Executable file → Normal file
View File

View File

@@ -34,10 +34,14 @@ class Dashboard::PollsController < Dashboard::BaseController
def update
authorize! :manage_polls, proposal
if poll.update(poll_params)
redirect_to proposal_dashboard_poll_path(proposal, poll), notice: t("flash.actions.update.poll")
else
render :edit
respond_to do |format|
if poll.update(poll_params)
format.html { redirect_to proposal_dashboard_poll_path(proposal, poll), notice: t("flash.actions.update.poll") }
format.json { respond_with_bip(poll) }
else
format.html { render :edit }
format.json { respond_with_bip(poll) }
end
end
end

View File

@@ -69,7 +69,7 @@ module Abilities
can [:create, :destroy, :manage], ::Poll::BoothAssignment
can [:create, :destroy], ::Poll::OfficerAssignment
can [:read, :create, :update], Poll::Question
can :destroy, Poll::Question # , comments_count: 0, votes_up: 0
can :destroy, Poll::Question
can :manage, SiteCustomization::Page
can :manage, SiteCustomization::Image

View File

@@ -26,6 +26,10 @@ module Abilities
proposal.author.id == user.id
end
can :results, Poll do |poll|
poll.related&.author&.id == user.id
end
can [:retire_form, :retire], Proposal, author_id: user.id
can :read, Legislation::Proposal

View File

@@ -26,6 +26,20 @@
</a>
<% end %>
</div>
<div class="card-section">
<p>
<%= best_in_place poll,
:results_enabled,
as: :checkbox,
url: proposal_dashboard_poll_url(proposal, poll),
collection: {
false: raw('<input type="checkbox">'),
true: raw('<input type="checkbox" checked>')
} %>
<strong><%= t('.show_results') %></strong>
</p>
<p class="help-text"><%= t('.show_results_help') %></p>
</div>
</div>
</div>

View File

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

View File

@@ -573,7 +573,9 @@ en:
responses:
one: "%{count} response"
other: "%{count} responses"
view_responses: Ver respuestas
view_responses: View responses
show_results: Show results
show_results_help: If you check this box the results will be public and all users will be able to see them
form:
add_question: Add question
question_fields:

View File

@@ -574,6 +574,8 @@ es:
one: "%{count} respuesta"
other: "%{count} respuestas"
view_responses: Ver respuestas
show_results: Mostrar resultados
show_results_help: Si marcas esta casilla los resultados serán públicos y todos los usuarios podrán verlos
form:
add_question: Añadir pregunta
question_fields:

View File

@@ -6,6 +6,7 @@ describe Abilities::Administrator do
let(:user) { administrator.user }
let(:administrator) { create(:administrator) }
let(:poll) { create(:poll, :current, stats_enabled: false, results_enabled: false) }
let(:other_user) { create(:user) }
let(:hidden_user) { create(:user, :hidden) }
@@ -91,6 +92,9 @@ describe Abilities::Administrator do
it { should_not be_able_to(:destroy, budget_investment_document) }
it { should be_able_to(:manage, ProposalDashboardAction) }
it { should be_able_to(:stats, poll) }
it { should be_able_to(:results, poll) }
it { is_expected.to be_able_to :manage, AdministratorTask }
it { is_expected.to be_able_to :manage, administrator_task }
end

View File

@@ -167,8 +167,12 @@ describe Abilities::Common do
end
describe 'proposal polls' do
let(:poll) { create(:poll, related: own_proposal) }
it { should be_able_to(:manage_polls, own_proposal) }
it { should_not be_able_to(:manage_polls, proposal) }
it { should_not be_able_to(:stats, poll) }
it { should be_able_to(:results, poll) }
end
describe 'publishing proposals' do

View File

@@ -35,4 +35,42 @@ describe Abilities::Everyone do
it { should be_able_to(:read_results, finished_budget) }
it { should_not be_able_to(:read_results, reviewing_ballot_budget) }
it { should_not be_able_to(:manage, ProposalDashboardAction) }
context 'when accessing poll results' do
let(:results_enabled) { true }
let(:poll) { create(:poll, :expired, results_enabled: results_enabled) }
it { should be_able_to(:results, poll) }
context 'and results disabled' do
let(:results_enabled) { false }
it { should_not be_able_to(:results, poll) }
end
context 'and not expired' do
let(:poll) { create(:poll, :current, results_enabled: true) }
it { should_not be_able_to(:results, poll) }
end
end
context 'when accessing poll stats' do
let(:stats_enabled) { true }
let(:poll) { create(:poll, :expired, stats_enabled: stats_enabled) }
it { should be_able_to(:stats, poll) }
context 'and stats disabled' do
let(:stats_enabled) { false }
it { should_not be_able_to(:stats, poll) }
end
context 'and not expired' do
let(:poll) { create(:poll, :current, stats_enabled: true) }
it { should_not be_able_to(:stats, poll) }
end
end
end