Skip to content

Commit

Permalink
Merge pull request #2945 from consul/backport-legislation_proposals
Browse files Browse the repository at this point in the history
Add admin permissions in legislation proposals
  • Loading branch information
javierm committed Oct 3, 2018
2 parents 127eef3 + 388c1a9 commit 5c1d188
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/controllers/legislation/processes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def debate
set_process
@phase = :debate_phase

if @process.debate_phase.started?
if @process.debate_phase.started? || (current_user && current_user.administrator?)
render :debate
else
render :phase_not_open
Expand Down Expand Up @@ -90,7 +90,7 @@ def proposals
@phase = :proposals_phase
@proposals = ::Legislation::Proposal.where(process: @process).order('random()').page(params[:page])

if @process.proposals_phase.started?
if @process.proposals_phase.started? || (current_user && current_user.administrator?)
legislation_proposal_votes(@proposals)
render :proposals
else
Expand Down
4 changes: 4 additions & 0 deletions app/models/abilities/administrator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def initialize(user)
can :restore, Proposal
cannot :restore, Proposal, hidden_at: nil

can :create, Legislation::Proposal
can :show, Legislation::Proposal
can :proposals, ::Legislation::Process

can :restore, Legislation::Proposal
cannot :restore, Legislation::Proposal, hidden_at: nil

Expand Down
12 changes: 12 additions & 0 deletions spec/factories/legislations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@
result_publication_date { Date.current + 5.days }
end

trait :in_proposals_phase do
proposals_phase_start_date { Date.current - 1.day }
proposals_phase_end_date { Date.current + 2.days }
proposals_phase_enabled true
end

trait :upcoming_proposals_phase do
proposals_phase_start_date { Date.current + 1.day }
proposals_phase_end_date { Date.current + 2.days }
proposals_phase_enabled true
end

trait :published do
published true
end
Expand Down
20 changes: 20 additions & 0 deletions spec/features/legislation/processes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,5 +237,25 @@

include_examples "not published permissions", :result_publication_legislation_process_path
end

context 'proposals phase' do
scenario 'not open' do
process = create(:legislation_process, :upcoming_proposals_phase)

visit legislation_process_proposals_path(process)

expect(page).to have_content("This phase is not open yet")
end

scenario 'open' do
process = create(:legislation_process, :in_proposals_phase)

visit legislation_process_proposals_path(process)

expect(page).to have_content("There are no proposals")
end

include_examples "not published permissions", :legislation_process_proposals_path
end
end
end

0 comments on commit 5c1d188

Please sign in to comment.