Set maximum number of documents on proposal and budget investments. Show alert on documents tab when maximum reached. Hide upload button when maximum reached.
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
class Budget
|
class Budget
|
||||||
class Investment < ActiveRecord::Base
|
class Investment < ActiveRecord::Base
|
||||||
|
|
||||||
include Measurable
|
include Measurable
|
||||||
include Sanitizable
|
include Sanitizable
|
||||||
include Taggable
|
include Taggable
|
||||||
@@ -13,6 +12,8 @@ class Budget
|
|||||||
acts_as_paranoid column: :hidden_at
|
acts_as_paranoid column: :hidden_at
|
||||||
include ActsAsParanoidAliases
|
include ActsAsParanoidAliases
|
||||||
|
|
||||||
|
MAX_DOCUMENTS_SIZE = 3
|
||||||
|
|
||||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
||||||
belongs_to :heading
|
belongs_to :heading
|
||||||
belongs_to :group
|
belongs_to :group
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ class Proposal < ActiveRecord::Base
|
|||||||
acts_as_paranoid column: :hidden_at
|
acts_as_paranoid column: :hidden_at
|
||||||
include ActsAsParanoidAliases
|
include ActsAsParanoidAliases
|
||||||
|
|
||||||
|
MAX_DOCUMENTS_SIZE = 3
|
||||||
RETIRE_OPTIONS = %w(duplicated started unfeasible done other)
|
RETIRE_OPTIONS = %w(duplicated started unfeasible done other)
|
||||||
|
|
||||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<div class="small-12 medium-9 column">
|
<div class="small-12 medium-9 column">
|
||||||
<%= back_link_to budget_investments_path(investment.budget, heading_id: investment.heading) %>
|
<%= back_link_to budget_investments_path(investment.budget, heading_id: investment.heading) %>
|
||||||
|
|
||||||
<% if can? :create, @document %>
|
<% if can?(:create, @document) && investment.documents.size < Budget::Investment::MAX_DOCUMENTS_SIZE %>
|
||||||
<%= link_to t("documents.upload_document"),
|
<%= link_to t("documents.upload_document"),
|
||||||
new_document_path(documentable_id:investment, documentable_type: investment.class.name, from: request.url),
|
new_document_path(documentable_id:investment, documentable_type: investment.class.name, from: request.url),
|
||||||
class: 'button hollow float-right' %>
|
class: 'button hollow float-right' %>
|
||||||
|
|||||||
@@ -21,7 +21,9 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="tabs-panel" id="tab-documents">
|
<div class="tabs-panel" id="tab-documents">
|
||||||
<%= render 'documents/documents', documents: @investment.documents %>
|
<%= render 'documents/documents',
|
||||||
|
documents: @investment.documents,
|
||||||
|
max_documents_size: Budget::Investment::MAX_DOCUMENTS_SIZE %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,4 +1,15 @@
|
|||||||
<% if documents.any? %>
|
<% if documents.any? %>
|
||||||
|
|
||||||
|
<% if documents.size == max_documents_size %>
|
||||||
|
<div class="row documents-list">
|
||||||
|
<div class="small-12 column">
|
||||||
|
<div class="callout primary text-center">
|
||||||
|
<%= t "documents.max_documents_size_reached" %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<div class="row documents-list">
|
<div class="row documents-list">
|
||||||
<div class="small-12 column">
|
<div class="small-12 column">
|
||||||
<table>
|
<table>
|
||||||
@@ -10,7 +21,9 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<% else %>
|
<% else %>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="small-12 column">
|
<div class="small-12 column">
|
||||||
<div class="callout primary text-center">
|
<div class="callout primary text-center">
|
||||||
@@ -18,4 +31,5 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
<div class="small-12 medium-9 column">
|
<div class="small-12 medium-9 column">
|
||||||
<%= back_link_to %>
|
<%= back_link_to %>
|
||||||
|
|
||||||
<% if can? :create, @document %>
|
<% if can?(:create, @document) && @proposal.documents.size < Proposal::MAX_DOCUMENTS_SIZE %>
|
||||||
<%= link_to t("documents.upload_document"),
|
<%= link_to t("documents.upload_document"),
|
||||||
new_document_path(documentable_id: @proposal, documentable_type: @proposal.class.name, from: request.url),
|
new_document_path(documentable_id: @proposal, documentable_type: @proposal.class.name, from: request.url),
|
||||||
class: 'button hollow float-right' %>
|
class: 'button hollow float-right' %>
|
||||||
@@ -164,6 +164,8 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="tabs-panel" id="tab-documents">
|
<div class="tabs-panel" id="tab-documents">
|
||||||
<%= render 'documents/documents', documents: @proposal.documents %>
|
<%= render 'documents/documents',
|
||||||
|
documents: @proposal.documents,
|
||||||
|
max_documents_size: Proposal::MAX_DOCUMENTS_SIZE %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ en:
|
|||||||
tab: Documents
|
tab: Documents
|
||||||
no_documents: Don't have uploaded documents
|
no_documents: Don't have uploaded documents
|
||||||
upload_document: Upload document
|
upload_document: Upload document
|
||||||
|
max_documents_size_reached: You have reached the maximum number of documents allowed! You have to delete one before you can upload another.
|
||||||
form:
|
form:
|
||||||
attachment_label: Choose attachment file
|
attachment_label: Choose attachment file
|
||||||
submit_button: Upload document
|
submit_button: Upload document
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ es:
|
|||||||
tab: Documentos
|
tab: Documentos
|
||||||
no_documents: No hay documentos subidos
|
no_documents: No hay documentos subidos
|
||||||
upload_document: Subir documento
|
upload_document: Subir documento
|
||||||
|
max_documents_size_reached: ¡Has alcanzado el número máximo de documentos permitidos! Tienes que eliminar uno antes de poder subir otro.
|
||||||
form:
|
form:
|
||||||
attachment_label: Selecciona un archivo
|
attachment_label: Selecciona un archivo
|
||||||
submit_button: Subir documento
|
submit_button: Subir documento
|
||||||
|
|||||||
@@ -429,7 +429,7 @@ feature 'Budget Investments' do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it_behaves_like "followable", "budget_investment", "budget_investment_path", {"budget_id": "budget_id", "id": "id"}
|
it_behaves_like "followable", "budget_investment", "budget_investment_path", { "budget_id": "budget_id", "id": "id" }
|
||||||
|
|
||||||
it_behaves_like "documentable", "budget_investment", "budget_investment_path", {"budget_id": "budget_id", "id": "id"}
|
it_behaves_like "documentable", "budget_investment", "budget_investment_path", {"budget_id": "budget_id", "id": "id"}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,15 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario "Should not display upload document button when maximum number of documents reached " do
|
||||||
|
create_list(:document, 3, documentable: documentable)
|
||||||
|
visit send(documentable_path, arguments)
|
||||||
|
|
||||||
|
within "##{dom_id(documentable)}" do
|
||||||
|
expect(page).not_to have_link("Upload document")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
scenario "Should display upload document button when user is logged in and is documentable owner" do
|
scenario "Should display upload document button when user is logged in and is documentable owner" do
|
||||||
login_as(user)
|
login_as(user)
|
||||||
|
|
||||||
@@ -58,6 +67,15 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
|
|||||||
|
|
||||||
let!(:document) { create(:document, documentable: documentable, user: documentable.author)}
|
let!(:document) { create(:document, documentable: documentable, user: documentable.author)}
|
||||||
|
|
||||||
|
scenario "Should display maximum number of documents alert when reached" do
|
||||||
|
create_list(:document, 2, documentable: documentable)
|
||||||
|
visit send(documentable_path, arguments)
|
||||||
|
|
||||||
|
within "#tab-documents" do
|
||||||
|
expect(page).to have_content "You have reached the maximum number of documents allowed! You have to delete one before you can upload another."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "Download action" do
|
describe "Download action" do
|
||||||
|
|
||||||
scenario "Should be able to anyone" do
|
scenario "Should be able to anyone" do
|
||||||
|
|||||||
Reference in New Issue
Block a user