diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index 73e90eb68..001d23446 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -1,24 +1,8 @@ class DocumentsController < ApplicationController before_action :authenticate_user! - before_action :find_documentable, except: :destroy - before_action :prepare_new_document, only: [:new] - before_action :prepare_document_for_creation, only: :create load_and_authorize_resource - def new - end - - def create - if @document.save - flash[:notice] = t "documents.actions.create.notice" - redirect_to params[:from] - else - flash[:alert] = t "documents.actions.create.alert" - render :new - end - end - def destroy respond_to do |format| format.html do @@ -39,25 +23,4 @@ class DocumentsController < ApplicationController end end - private - - def document_params - params.require(:document).permit(:title, :documentable_type, :documentable_id, - :attachment, :cached_attachment, :user_id) - end - - def find_documentable - @documentable = params[:documentable_type].constantize.find_or_initialize_by(id: params[:documentable_id]) - end - - def prepare_new_document - @document = Document.new(documentable: @documentable, user_id: current_user.id) - end - - def prepare_document_for_creation - @document = Document.new(document_params) - @document.documentable = @documentable - @document.user = current_user - end - end diff --git a/app/helpers/documentables_helper.rb b/app/helpers/documentables_helper.rb index b95ea80c6..8d9f85578 100644 --- a/app/helpers/documentables_helper.rb +++ b/app/helpers/documentables_helper.rb @@ -1,9 +1,5 @@ module DocumentablesHelper - def can_create_document?(documentable) - can?(:create, Document.new(documentable: documentable)) && documentable.documents.size < documentable.class.max_documents_allowed - end - def documentable_class(documentable) documentable.class.name.parameterize('_') end diff --git a/app/models/abilities/common.rb b/app/models/abilities/common.rb index 64b4c5476..e4e92abaf 100644 --- a/app/models/abilities/common.rb +++ b/app/models/abilities/common.rb @@ -37,7 +37,7 @@ module Abilities can [:create, :destroy], Follow - can [:create, :destroy, :new], Document, documentable: { author_id: user.id } + can [:destroy], Document, documentable: { author_id: user.id } can [:destroy], Image, imageable: { author_id: user.id } diff --git a/app/views/budgets/investments/_investment_show.html.erb b/app/views/budgets/investments/_investment_show.html.erb index fbd1ad364..e257de0bb 100644 --- a/app/views/budgets/investments/_investment_show.html.erb +++ b/app/views/budgets/investments/_investment_show.html.erb @@ -4,12 +4,6 @@
<%= back_link_to budget_investments_path(investment.budget, heading_id: investment.heading) %> - <% if can_create_document?(investment) %> - <%= link_to t("documents.upload_document"), - new_document_path(documentable_id:investment, documentable_type: investment.class.name, from: request.url), - class: 'button hollow float-right' %> - <% end %> - <% if can_destroy_image?(investment) %> <%= link_to t("images.remove_image"), image_path(investment.image, from: request.url), diff --git a/app/views/documents/_documents.html.erb b/app/views/documents/_documents.html.erb index e03c8c280..e36d88207 100644 --- a/app/views/documents/_documents.html.erb +++ b/app/views/documents/_documents.html.erb @@ -1,6 +1,6 @@ <% if documents.any? %> - <% if documents.size == max_documents_allowed && can?(:create, Document) %> + <% if documents.size == max_documents_allowed && can?(:destroy, Document) %>
diff --git a/app/views/documents/_form.html.erb b/app/views/documents/_form.html.erb deleted file mode 100644 index 216dbbb3b..000000000 --- a/app/views/documents/_form.html.erb +++ /dev/null @@ -1,63 +0,0 @@ -<%= form_for @document, - url: documents_path( - documentable_type: @document.documentable_type, - documentable_id: @document.documentable_id, - from: params[:from] - ), - html: { multipart: true, class: "documentable document-form" } do |f| %> - - <%= render 'shared/errors', resource: @document %> - -
- - <%= f.hidden_field :cached_attachment %> - -
- <%= f.text_field :title, placeholder: t("documents.new.form.title_placeholder") %> -
- -
-
- <%= f.label :attachment, t("documents.form.attachment_label"), class: 'button hollow' %> - <%= f.file_field :attachment, - accept: accepted_content_types_extensions(@document.documentable.class), - label: false, - class: 'js-document-attachment', - data: { - url: direct_uploads_url("direct_upload[resource_type]": @document.documentable_type, - "direct_upload[resource_id]": @document.documentable_id, - "direct_upload[resource_relation]": "documents"), - cached_attachment_input_field: "document_cached_attachment", - title_input_field: "document_title" - } %> - -
-
- <% if @document.cached_attachment.present? %> - <%= link_to t('documents.form.delete_button'), - direct_upload_destroy_url("direct_upload[resource_type]": @document.documentable_type, - "direct_upload[resource_id]": @document.documentable_id, - "direct_upload[resource_relation]": "documents", - "direct_upload[cached_attachment]": @document.cached_attachment), - method: :delete, - remote: true, - class: "delete remove-cached-attachment" %> - <% end %> -
-
- -
-

- <%= document_attachment_file_name(@document) %> -

-
- -
-
-
- -
- <%= f.submit(t("documents.form.submit_button"), class: "button expanded") %> -
-
-<% end %> diff --git a/app/views/proposals/show.html.erb b/app/views/proposals/show.html.erb index f9f3cca7c..96999ca7d 100644 --- a/app/views/proposals/show.html.erb +++ b/app/views/proposals/show.html.erb @@ -108,18 +108,10 @@