From 21ead40e26ef6dd7e3722d89e3634c81d783f583 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Fri, 6 Apr 2018 11:54:31 +0200 Subject: [PATCH] Disable document upload & show with new setting When Setting allow_attached_documents is disabled (false value) the user should not be able to upload documents neither see the documents lists --- app/views/budgets/investments/_form.html.erb | 8 +++++--- .../investments/_investment_show.html.erb | 8 +++++--- app/views/legislation/proposals/show.html.erb | 8 +++++--- app/views/proposals/_form.html.erb | 8 +++++--- app/views/proposals/show.html.erb | 8 +++++--- spec/shared/features/documentable.rb | 17 +++++++++++++++++ spec/shared/features/nested_documentable.rb | 17 +++++++++++++++++ 7 files changed, 59 insertions(+), 15 deletions(-) diff --git a/app/views/budgets/investments/_form.html.erb b/app/views/budgets/investments/_form.html.erb index cc24ad651..c4c49a4aa 100644 --- a/app/views/budgets/investments/_form.html.erb +++ b/app/views/budgets/investments/_form.html.erb @@ -23,9 +23,11 @@ <% end %> -
- <%= render 'documents/nested_documents', documentable: @investment, f: f %> -
+ <% if feature?(:allow_attached_documents) %> +
+ <%= render 'documents/nested_documents', documentable: @investment, f: f %> +
+ <% end %> <% if feature?(:map) %>
diff --git a/app/views/budgets/investments/_investment_show.html.erb b/app/views/budgets/investments/_investment_show.html.erb index 18694e6ce..2ca4af278 100644 --- a/app/views/budgets/investments/_investment_show.html.erb +++ b/app/views/budgets/investments/_investment_show.html.erb @@ -51,9 +51,11 @@

<% end %> - <%= render 'documents/documents', - documents: investment.documents, - max_documents_allowed: Budget::Investment.max_documents_allowed %> + <% if feature?(:allow_attached_documents) %> + <%= render 'documents/documents', + documents: investment.documents, + max_documents_allowed: Budget::Investment.max_documents_allowed %> + <% end %> <%= render 'shared/tags', taggable: investment %> diff --git a/app/views/legislation/proposals/show.html.erb b/app/views/legislation/proposals/show.html.erb index a2d0c5ab7..1867644ca 100644 --- a/app/views/legislation/proposals/show.html.erb +++ b/app/views/legislation/proposals/show.html.erb @@ -80,9 +80,11 @@

<%= @proposal.question %>

- <%= render 'documents/documents', - documents: @proposal.documents, - max_documents_allowed: Proposal.max_documents_allowed %> + <% if feature?(:allow_attached_documents) %> + <%= render 'documents/documents', + documents: @proposal.documents, + max_documents_allowed: Proposal.max_documents_allowed %> + <% end %> <%= render 'shared/tags', taggable: @proposal %> diff --git a/app/views/proposals/_form.html.erb b/app/views/proposals/_form.html.erb index 6bf8c274a..f60397b17 100644 --- a/app/views/proposals/_form.html.erb +++ b/app/views/proposals/_form.html.erb @@ -52,9 +52,11 @@
<% end %> -
- <%= render 'documents/nested_documents', documentable: @proposal, f: f %> -
+ <% if feature?(:allow_attached_documents) %> +
+ <%= render 'documents/nested_documents', documentable: @proposal, f: f %> +
+ <% end %>
<%= f.label :geozone_id, t("proposals.form.geozone") %> diff --git a/app/views/proposals/show.html.erb b/app/views/proposals/show.html.erb index 3355251fc..21f4f0e58 100644 --- a/app/views/proposals/show.html.erb +++ b/app/views/proposals/show.html.erb @@ -106,9 +106,11 @@
<% end %> - <%= render 'documents/documents', - documents: @proposal.documents, - max_documents_allowed: Proposal.max_documents_allowed %> + <% if feature?(:allow_attached_documents) %> + <%= render 'documents/documents', + documents: @proposal.documents, + max_documents_allowed: Proposal.max_documents_allowed %> + <% end %> <%= render 'shared/tags', taggable: @proposal %> diff --git a/spec/shared/features/documentable.rb b/spec/shared/features/documentable.rb index 16fab74ce..7fe0dd146 100644 --- a/spec/shared/features/documentable.rb +++ b/spec/shared/features/documentable.rb @@ -68,6 +68,23 @@ shared_examples "documentable" do |documentable_factory_name, end + describe "When allow attached documents setting is disabled" do + before do + Setting['feature.allow_attached_documents'] = false + end + + after do + Setting['feature.allow_attached_documents'] = true + end + + scenario "Documents list should not be available" do + login_as(create(:user)) + visit send(documentable_path, arguments) + + expect(page).not_to have_css("#documents") + end + end + end context "Destroy" do diff --git a/spec/shared/features/nested_documentable.rb b/spec/shared/features/nested_documentable.rb index 9873772f3..1a47cc503 100644 --- a/spec/shared/features/nested_documentable.rb +++ b/spec/shared/features/nested_documentable.rb @@ -285,6 +285,23 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na end + describe "When allow attached documents setting is disabled" do + before do + Setting['feature.allow_attached_documents'] = false + end + + after do + Setting['feature.allow_attached_documents'] = true + end + + scenario "Add new document button should not be available" do + login_as user_to_login + visit send(path, arguments) + + expect(page).not_to have_content("Add new document") + end + end + end end