Add abilities to documentable authors and admins to create and destroy documents.

This commit is contained in:
Senén Rodero Rodríguez
2017-07-21 11:55:15 +02:00
parent 34d06dad04
commit c92827e89e
4 changed files with 36 additions and 0 deletions

View File

@@ -73,6 +73,7 @@ module Abilities
can [:manage], ::Legislation::Question can [:manage], ::Legislation::Question
cannot :comment_as_moderator, [::Legislation::Question, Legislation::Annotation] cannot :comment_as_moderator, [::Legislation::Question, Legislation::Annotation]
can [:create, :destroy], Document
end end
end end
end end

View File

@@ -36,6 +36,8 @@ module Abilities
can [:create, :destroy], Follow can [:create, :destroy], Follow
can [:create, :destroy], Document, documentable: { author_id: user.id }
unless user.organization? unless user.organization?
can :vote, Debate can :vote, Debate
can :vote, Comment can :vote, Comment

View File

@@ -12,8 +12,12 @@ describe "Abilities::Administrator" do
let(:debate) { create(:debate) } let(:debate) { create(:debate) }
let(:comment) { create(:comment) } let(:comment) { create(:comment) }
let(:proposal) { create(:proposal) } let(:proposal) { create(:proposal) }
let(:budget_investment) { create(:budget_investment) }
let(:legislation_question) { create(:legislation_question) } let(:legislation_question) { create(:legislation_question) }
let(:proposal_document) { build(:document, documentable: proposal) }
let(:budget_investment_document) { build(:document, documentable: budget_investment) }
let(:hidden_debate) { create(:debate, :hidden) } let(:hidden_debate) { create(:debate, :hidden) }
let(:hidden_comment) { create(:comment, :hidden) } let(:hidden_comment) { create(:comment, :hidden) }
let(:hidden_proposal) { create(:proposal, :hidden) } let(:hidden_proposal) { create(:proposal, :hidden) }
@@ -71,4 +75,12 @@ describe "Abilities::Administrator" do
it { should be_able_to(:valuate, create(:budget_investment, budget: create(:budget, phase: 'valuating'))) } it { should be_able_to(:valuate, create(:budget_investment, budget: create(:budget, phase: 'valuating'))) }
it { should be_able_to(:valuate, create(:budget_investment, budget: create(:budget, phase: 'finished'))) } it { should be_able_to(:valuate, create(:budget_investment, budget: create(:budget, phase: 'finished'))) }
it { should be_able_to(:new, proposal_document) }
it { should be_able_to(:create, proposal_document) }
it { should be_able_to(:destroy, proposal_document) }
it { should be_able_to(:new, budget_investment_document) }
it { should be_able_to(:create, budget_investment_document) }
it { should be_able_to(:destroy, budget_investment_document) }
end end

View File

@@ -54,6 +54,11 @@ describe "Abilities::Common" do
let(:incoming_poll_question_from_other_geozone) { create(:poll_question, poll: incoming_poll_from_other_geozone) } let(:incoming_poll_question_from_other_geozone) { create(:poll_question, poll: incoming_poll_from_other_geozone) }
let(:incoming_poll_question_from_all_geozones) { create(:poll_question, poll: incoming_poll) } let(:incoming_poll_question_from_all_geozones) { create(:poll_question, poll: incoming_poll) }
let(:own_proposal_document) { build(:document, documentable: own_proposal) }
let(:proposal_document) { build(:document, documentable: proposal) }
let(:own_budget_investment_document) { build(:document, documentable: own_investment_in_accepting_budget) }
let(:budget_investment_document) { build(:document, documentable: investment_in_accepting_budget) }
it { should be_able_to(:index, Debate) } it { should be_able_to(:index, Debate) }
it { should be_able_to(:show, debate) } it { should be_able_to(:show, debate) }
it { should be_able_to(:vote, debate) } it { should be_able_to(:vote, debate) }
@@ -82,6 +87,22 @@ describe "Abilities::Common" do
it { should_not be_able_to(:create, DirectMessage) } it { should_not be_able_to(:create, DirectMessage) }
it { should_not be_able_to(:show, DirectMessage) } it { should_not be_able_to(:show, DirectMessage) }
it { should be_able_to(:new, own_proposal_document) }
it { should be_able_to(:create, own_proposal_document) }
it { should be_able_to(:destroy, own_proposal_document) }
it { should_not be_able_to(:new, proposal_document) }
it { should_not be_able_to(:create, proposal_document) }
it { should_not be_able_to(:destroy, proposal_document) }
it { should be_able_to(:new, own_budget_investment_document) }
it { should be_able_to(:create, own_budget_investment_document) }
it { should be_able_to(:destroy, own_budget_investment_document) }
it { should_not be_able_to(:new, budget_investment_document) }
it { should_not be_able_to(:create, budget_investment_document) }
it { should_not be_able_to(:destroy, budget_investment_document) }
describe 'flagging content' do describe 'flagging content' do
it { should be_able_to(:flag, debate) } it { should be_able_to(:flag, debate) }
it { should be_able_to(:unflag, debate) } it { should be_able_to(:unflag, debate) }