Fixes #218
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:
1
Gemfile
1
Gemfile
@@ -7,6 +7,7 @@ gem 'acts_as_votable', '~> 0.11.1'
|
|||||||
gem 'ahoy_matey', '~> 1.6.0'
|
gem 'ahoy_matey', '~> 1.6.0'
|
||||||
gem 'ancestry', '~> 3.0.1'
|
gem 'ancestry', '~> 3.0.1'
|
||||||
gem 'autoprefixer-rails', '~> 8.2.0'
|
gem 'autoprefixer-rails', '~> 8.2.0'
|
||||||
|
gem 'best_in_place', '~> 3.0.1'
|
||||||
gem 'browser', '~> 2.5.2'
|
gem 'browser', '~> 2.5.2'
|
||||||
gem 'cancancan', '~> 2.1.2'
|
gem 'cancancan', '~> 2.1.2'
|
||||||
gem 'ckeditor', '~> 4.2.3'
|
gem 'ckeditor', '~> 4.2.3'
|
||||||
|
|||||||
@@ -68,6 +68,9 @@ GEM
|
|||||||
babel-source (>= 4.0, < 6)
|
babel-source (>= 4.0, < 6)
|
||||||
execjs (~> 2.0)
|
execjs (~> 2.0)
|
||||||
bcrypt (3.1.11)
|
bcrypt (3.1.11)
|
||||||
|
best_in_place (3.0.3)
|
||||||
|
actionpack (>= 3.2)
|
||||||
|
railties (>= 3.2)
|
||||||
browser (2.5.2)
|
browser (2.5.2)
|
||||||
builder (3.2.3)
|
builder (3.2.3)
|
||||||
bullet (5.7.1)
|
bullet (5.7.1)
|
||||||
@@ -504,6 +507,7 @@ DEPENDENCIES
|
|||||||
ahoy_matey (~> 1.6.0)
|
ahoy_matey (~> 1.6.0)
|
||||||
ancestry (~> 3.0.1)
|
ancestry (~> 3.0.1)
|
||||||
autoprefixer-rails (~> 8.2.0)
|
autoprefixer-rails (~> 8.2.0)
|
||||||
|
best_in_place (~> 3.0.1)
|
||||||
browser (~> 2.5.2)
|
browser (~> 2.5.2)
|
||||||
bullet (~> 5.7.0)
|
bullet (~> 5.7.0)
|
||||||
byebug (~> 10.0.0)
|
byebug (~> 10.0.0)
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
//= require jquery-ui/widgets/autocomplete
|
//= require jquery-ui/widgets/autocomplete
|
||||||
//= require jquery-ui/widgets/sortable
|
//= require jquery-ui/widgets/sortable
|
||||||
//= require jquery-fileupload/basic
|
//= require jquery-fileupload/basic
|
||||||
|
//= require best_in_place
|
||||||
//= require foundation
|
//= require foundation
|
||||||
//= require turbolinks
|
//= require turbolinks
|
||||||
//= require ckeditor/loader
|
//= require ckeditor/loader
|
||||||
@@ -81,6 +82,7 @@
|
|||||||
//= require globalize
|
//= require globalize
|
||||||
//= require clipboard
|
//= require clipboard
|
||||||
//= require clipboard_button
|
//= require clipboard_button
|
||||||
|
//= require best_in_place_initialize
|
||||||
|
|
||||||
var initialize_modules = function() {
|
var initialize_modules = function() {
|
||||||
App.Comments.initialize();
|
App.Comments.initialize();
|
||||||
@@ -127,6 +129,7 @@ var initialize_modules = function() {
|
|||||||
App.Managers.initialize();
|
App.Managers.initialize();
|
||||||
App.Globalize.initialize();
|
App.Globalize.initialize();
|
||||||
App.ClipboardButton.initialize();
|
App.ClipboardButton.initialize();
|
||||||
|
App.BestInPlace.initialize();
|
||||||
};
|
};
|
||||||
|
|
||||||
$(function(){
|
$(function(){
|
||||||
|
|||||||
@@ -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
0
app/assets/javascripts/rem.min.js
vendored
Executable file → Normal file
0
app/assets/javascripts/respond.min.js
vendored
Executable file → Normal file
0
app/assets/javascripts/respond.min.js
vendored
Executable file → Normal file
@@ -34,10 +34,14 @@ class Dashboard::PollsController < Dashboard::BaseController
|
|||||||
def update
|
def update
|
||||||
authorize! :manage_polls, proposal
|
authorize! :manage_polls, proposal
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
if poll.update(poll_params)
|
if poll.update(poll_params)
|
||||||
redirect_to proposal_dashboard_poll_path(proposal, poll), notice: t("flash.actions.update.poll")
|
format.html { redirect_to proposal_dashboard_poll_path(proposal, poll), notice: t("flash.actions.update.poll") }
|
||||||
|
format.json { respond_with_bip(poll) }
|
||||||
else
|
else
|
||||||
render :edit
|
format.html { render :edit }
|
||||||
|
format.json { respond_with_bip(poll) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ module Abilities
|
|||||||
can [:create, :destroy, :manage], ::Poll::BoothAssignment
|
can [:create, :destroy, :manage], ::Poll::BoothAssignment
|
||||||
can [:create, :destroy], ::Poll::OfficerAssignment
|
can [:create, :destroy], ::Poll::OfficerAssignment
|
||||||
can [:read, :create, :update], Poll::Question
|
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::Page
|
||||||
can :manage, SiteCustomization::Image
|
can :manage, SiteCustomization::Image
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ module Abilities
|
|||||||
proposal.author.id == user.id
|
proposal.author.id == user.id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
can :results, Poll do |poll|
|
||||||
|
poll.related&.author&.id == user.id
|
||||||
|
end
|
||||||
|
|
||||||
can [:retire_form, :retire], Proposal, author_id: user.id
|
can [:retire_form, :retire], Proposal, author_id: user.id
|
||||||
|
|
||||||
can :read, Legislation::Proposal
|
can :read, Legislation::Proposal
|
||||||
|
|||||||
@@ -26,6 +26,20 @@
|
|||||||
</a>
|
</a>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<% if current_user && current_user.administrator? ||
|
<% if can?(:results, @poll) || can?(:stats, @poll) %>
|
||||||
(@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 current_user && current_user.administrator? || @poll.results_enabled? %>
|
||||||
|
<% if can?(:results, @poll) %>
|
||||||
<% if controller_name == "polls" && action_name == "results" %>
|
<% if controller_name == "polls" && action_name == "results" %>
|
||||||
<li class="is-active">
|
<li class="is-active">
|
||||||
<h2><%= t("polls.show.results_menu") %></h2>
|
<h2><%= t("polls.show.results_menu") %></h2>
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if current_user && current_user.administrator? || @poll.stats_enabled? %>
|
<% if can?(:stats, @poll) %>
|
||||||
<% if controller_name == "polls" && action_name == "stats" %>
|
<% if controller_name == "polls" && action_name == "stats" %>
|
||||||
<li class="is-active">
|
<li class="is-active">
|
||||||
<h2><%= t("polls.show.stats_menu") %></h2>
|
<h2><%= t("polls.show.stats_menu") %></h2>
|
||||||
|
|||||||
@@ -573,7 +573,9 @@ en:
|
|||||||
responses:
|
responses:
|
||||||
one: "%{count} response"
|
one: "%{count} response"
|
||||||
other: "%{count} responses"
|
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:
|
form:
|
||||||
add_question: Add question
|
add_question: Add question
|
||||||
question_fields:
|
question_fields:
|
||||||
|
|||||||
@@ -574,6 +574,8 @@ es:
|
|||||||
one: "%{count} respuesta"
|
one: "%{count} respuesta"
|
||||||
other: "%{count} respuestas"
|
other: "%{count} respuestas"
|
||||||
view_responses: Ver 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:
|
form:
|
||||||
add_question: Añadir pregunta
|
add_question: Añadir pregunta
|
||||||
question_fields:
|
question_fields:
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ describe Abilities::Administrator do
|
|||||||
|
|
||||||
let(:user) { administrator.user }
|
let(:user) { administrator.user }
|
||||||
let(:administrator) { create(:administrator) }
|
let(:administrator) { create(:administrator) }
|
||||||
|
let(:poll) { create(:poll, :current, stats_enabled: false, results_enabled: false) }
|
||||||
|
|
||||||
let(:other_user) { create(:user) }
|
let(:other_user) { create(:user) }
|
||||||
let(:hidden_user) { create(:user, :hidden) }
|
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_not be_able_to(:destroy, budget_investment_document) }
|
||||||
it { should be_able_to(:manage, ProposalDashboardAction) }
|
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, AdministratorTask }
|
||||||
it { is_expected.to be_able_to :manage, administrator_task }
|
it { is_expected.to be_able_to :manage, administrator_task }
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -167,8 +167,12 @@ describe Abilities::Common do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe 'proposal polls' do
|
describe 'proposal polls' do
|
||||||
|
let(:poll) { create(:poll, related: own_proposal) }
|
||||||
|
|
||||||
it { should be_able_to(:manage_polls, 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(:manage_polls, proposal) }
|
||||||
|
it { should_not be_able_to(:stats, poll) }
|
||||||
|
it { should be_able_to(:results, poll) }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'publishing proposals' do
|
describe 'publishing proposals' do
|
||||||
|
|||||||
@@ -35,4 +35,42 @@ describe Abilities::Everyone do
|
|||||||
it { should be_able_to(:read_results, finished_budget) }
|
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(:read_results, reviewing_ballot_budget) }
|
||||||
it { should_not be_able_to(:manage, ProposalDashboardAction) }
|
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
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user