diff --git a/app/controllers/legislation/proposals_controller.rb b/app/controllers/legislation/proposals_controller.rb index 157c1f8a9..eb5ce4e2f 100644 --- a/app/controllers/legislation/proposals_controller.rb +++ b/app/controllers/legislation/proposals_controller.rb @@ -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 diff --git a/app/helpers/legislation_helper.rb b/app/helpers/legislation_helper.rb index a93c2fa47..d8dc77f87 100644 --- a/app/helpers/legislation_helper.rb +++ b/app/helpers/legislation_helper.rb @@ -6,4 +6,8 @@ module LegislationHelper 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 diff --git a/app/views/legislation/processes/_proposals_content.html.erb b/app/views/legislation/processes/_proposals_content.html.erb new file mode 100644 index 000000000..63a7ac926 --- /dev/null +++ b/app/views/legislation/processes/_proposals_content.html.erb @@ -0,0 +1,28 @@ +
+
+
+
+
+ <% if proposals.empty? %> +
+

<%= t("legislation.processes.proposals.empty_proposals") %>

+
+ <% else %> + <%= render proposals %> + <%= paginate proposals %> + <% end %> +
+
+ +
+ <% if process.proposals_phase.open? %> +

<%= link_to new_legislation_proposal_link_text(process), + new_legislation_process_proposal_path(process), + class: 'button expanded', + id: 'create-new-proposal' %>

+ <% end %> + <%= render 'legislation/proposals/categories', taggable: process %> +
+
+
+
diff --git a/app/views/legislation/processes/proposals.html.erb b/app/views/legislation/processes/proposals.html.erb index 0f6159845..eb8caa153 100644 --- a/app/views/legislation/processes/proposals.html.erb +++ b/app/views/legislation/processes/proposals.html.erb @@ -4,28 +4,4 @@ <%= render 'key_dates', process: @process, phase: :proposals %> -
-
-
-
-
- <% if @proposals.empty? %> -
-

<%= t('.empty_proposals') %>

-
- <% else %> - <%= render @proposals %> - <%= paginate @proposals %> - <% end %> -
-
- -
- <% if @process.proposals_phase.open? %> -

<%= link_to t("proposals.index.start_proposal"), new_legislation_process_proposal_path(@process), class: 'button expanded' %>

- <% end %> - <%= render 'legislation/proposals/categories', taggable: @process %> -
-
-
-
+<%= render 'proposals_content', process: @process, proposals: @proposals %> diff --git a/db/dev_seeds/legislation_processes.rb b/db/dev_seeds/legislation_processes.rb index fd4c5a190..4c71763a8 100644 --- a/db/dev_seeds/legislation_processes.rb +++ b/db/dev_seeds/legislation_processes.rb @@ -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, diff --git a/spec/features/legislation/processes_spec.rb b/spec/features/legislation/processes_spec.rb index 92a78499d..9989c5ee8 100644 --- a/spec/features/legislation/processes_spec.rb +++ b/spec/features/legislation/processes_spec.rb @@ -255,6 +255,16 @@ feature 'Legislation' do 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