Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport] Simplify legislation proposals customization #2946

Merged
merged 5 commits into from
Oct 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/controllers/legislation/proposals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ class Legislation::ProposalsController < Legislation::BaseController
include CommentableActions
include FlagActions

load_and_authorize_resource :process, class: "Legislation::Process"
load_and_authorize_resource :proposal, class: "Legislation::Proposal", through: :process

before_action :parse_tag_filter, only: :index
before_action :load_categories, only: [:index, :new, :create, :edit, :map, :summary]
before_action :load_geozones, only: [:edit, :map, :summary]

before_action :authenticate_user!, except: [:index, :show, :map, :summary]
load_and_authorize_resource :process, class: "Legislation::Process"
load_and_authorize_resource :proposal, class: "Legislation::Proposal", through: :process

invisible_captcha only: [:create, :update], honeypot: :subtitle

Expand Down
4 changes: 4 additions & 0 deletions app/helpers/legislation_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ def format_date(date)
def format_date_for_calendar_form(date)
l(date, format: "%d/%m/%Y") if date
end

def new_legislation_proposal_link_text(process)
t("proposals.index.start_proposal")
end
end
28 changes: 28 additions & 0 deletions app/views/legislation/processes/_proposals_content.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<div class="row">
<div class="debate-chooser">
<div class="row">
<div class="small-12 medium-9 column">
<div class="legislation-proposals">
<% if proposals.empty? %>
<div class="callout primary">
<p><%= t("legislation.processes.proposals.empty_proposals") %></p>
</div>
<% else %>
<%= render proposals %>
<%= paginate proposals %>
<% end %>
</div>
</div>

<div class="small-12 medium-3 column">
<% if process.proposals_phase.open? %>
<p><%= link_to new_legislation_proposal_link_text(process),
new_legislation_process_proposal_path(process),
class: 'button expanded',
id: 'create-new-proposal' %></p>
<% end %>
<%= render 'legislation/proposals/categories', taggable: process %>
</div>
</div>
</div>
</div>
26 changes: 1 addition & 25 deletions app/views/legislation/processes/proposals.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,4 @@

<%= render 'key_dates', process: @process, phase: :proposals %>

<div class="row">
<div class="debate-chooser">
<div class="row">
<div class="small-12 medium-9 column">
<div class="legislation-proposals">
<% if @proposals.empty? %>
<div class="callout primary">
<p><%= t('.empty_proposals') %></p>
</div>
<% else %>
<%= render @proposals %>
<%= paginate @proposals %>
<% end %>
</div>
</div>

<div class="small-12 medium-3 column">
<% if @process.proposals_phase.open? %>
<p><%= link_to t("proposals.index.start_proposal"), new_legislation_process_proposal_path(@process), class: 'button expanded' %></p>
<% end %>
<%= render 'legislation/proposals/categories', taggable: @process %>
</div>
</div>
</div>
</div>
<%= render 'proposals_content', process: @process, proposals: @proposals %>
22 changes: 11 additions & 11 deletions db/dev_seeds/legislation_processes.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
section "Creating legislation processes" do
5.times do
9.times do |i|
Legislation::Process.create!(title: Faker::Lorem.sentence(3).truncate(60),
description: Faker::Lorem.paragraphs.join("\n\n"),
summary: Faker::Lorem.paragraph,
additional_info: Faker::Lorem.paragraphs.join("\n\n"),
proposals_description: Faker::Lorem.paragraph,
start_date: Date.current - 3.days,
end_date: Date.current + 3.days,
debate_start_date: Date.current - 3.days,
debate_end_date: Date.current - 1.day,
proposals_phase_start_date: Date.current - 3.days,
proposals_phase_end_date: Date.current - 1.day,
draft_publication_date: Date.current + 1.day,
allegations_start_date: Date.current + 2.days,
allegations_end_date: Date.current + 3.days,
result_publication_date: Date.current + 4.days,
start_date: Date.current + (i - 7).days,
end_date: Date.current + (i - 1).days,
debate_start_date: Date.current + (i - 7).days,
debate_end_date: Date.current + (i - 5).days,
proposals_phase_start_date: Date.current + (i - 7).days,
proposals_phase_end_date: Date.current + (i - 5).days,
draft_publication_date: Date.current + (i - 3).days,
allegations_start_date: Date.current + (i - 2).days,
allegations_end_date: Date.current + (i - 1).days,
result_publication_date: Date.current + i.days,
debate_phase_enabled: true,
allegations_phase_enabled: true,
draft_publication_enabled: true,
Expand Down
10 changes: 10 additions & 0 deletions spec/features/legislation/processes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,16 @@
expect(page).to have_content("There are no proposals")
end

scenario 'create proposal button redirects to register path if user is not logged in' do
process = create(:legislation_process, :in_proposals_phase)

visit legislation_process_proposals_path(process)
click_link "Create a proposal"

expect(page).to have_current_path new_user_session_path
expect(page).to have_content "You must sign in or register to continue"
end

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