diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb
index 001d23446..1d6df8d14 100644
--- a/app/controllers/documents_controller.rb
+++ b/app/controllers/documents_controller.rb
@@ -11,7 +11,7 @@ class DocumentsController < ApplicationController
else
flash[:alert] = t "documents.actions.destroy.alert"
end
- redirect_to params[:from]
+ redirect_to request.referer
end
format.js do
if @document.destroy
diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb
index bdc457bc0..847f1effc 100644
--- a/app/models/abilities/administrator.rb
+++ b/app/models/abilities/administrator.rb
@@ -93,6 +93,7 @@ module Abilities
cannot :comment_as_moderator, [::Legislation::Question, Legislation::Annotation, ::Legislation::Proposal]
can [:create], Document
+ can [:destroy], Document, documentable_type: "Poll::Question::Answer"
can [:create, :destroy], DirectUpload
can [:deliver], Newsletter, hidden_at: nil
diff --git a/app/views/admin/poll/questions/answers/documents.html.erb b/app/views/admin/poll/questions/answers/documents.html.erb
index 54dd25a18..933be2b94 100644
--- a/app/views/admin/poll/questions/answers/documents.html.erb
+++ b/app/views/admin/poll/questions/answers/documents.html.erb
@@ -14,18 +14,12 @@
<%= render 'shared/errors', resource: @answer %>
-
-
-
- <%= render 'documents/nested_documents', documentable: @answer, f: f %>
-
+
+ <%= render 'documents/nested_documents', documentable: @answer, f: f %>
+
-
-
- <%= f.submit(class: "button expanded", value: t("shared.save")) %>
-
-
-
+
+ <%= f.submit(class: "button expanded", value: t("shared.save")) %>
<% end %>
@@ -42,11 +36,17 @@
<%= link_to document.title, document.attachment.url %>
- <%= link_to t('documents.buttons.download_document'),
+ <%= link_to t("documents.buttons.download_document"),
document.attachment.url,
target: "_blank",
rel: "nofollow",
- class: 'button hollow' %>
+ class: "button hollow" %>
+
+ <%= link_to t("admin.shared.delete"),
+ document_path(document),
+ method: :delete,
+ class: "button hollow alert",
+ data: { confirm: t("admin.actions.confirm") } %>
|
<% end %>
diff --git a/app/views/documents/_document.html.erb b/app/views/documents/_document.html.erb
index bf549e92b..9075bdd7c 100644
--- a/app/views/documents/_document.html.erb
+++ b/app/views/documents/_document.html.erb
@@ -13,7 +13,8 @@
<% if can?(:destroy, document) %>
<%= link_to t("documents.buttons.destroy_document"),
- document_path(document, from: request.url), method: :delete,
+ document,
+ method: :delete,
data: { confirm: t("documents.actions.destroy.confirm") },
class: "delete" %>
<% end %>
diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml
index a86f8a315..0b51d9556 100644
--- a/config/locales/en/admin.yml
+++ b/config/locales/en/admin.yml
@@ -1187,6 +1187,7 @@ en:
author: Author
content: Content
created_at: Created at
+ delete: Delete
spending_proposals:
index:
geozone_filter_all: All zones
diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml
index d33d91211..dc8e66fb0 100644
--- a/config/locales/es/admin.yml
+++ b/config/locales/es/admin.yml
@@ -1187,6 +1187,7 @@ es:
author: Autor
content: Contenido
created_at: Fecha de creación
+ delete: Eliminar
spending_proposals:
index:
geozone_filter_all: Todos los ámbitos de actuación
diff --git a/spec/features/admin/poll/questions/answers/documents/documents_spec.rb b/spec/features/admin/poll/questions/answers/documents/documents_spec.rb
new file mode 100644
index 000000000..34d43a454
--- /dev/null
+++ b/spec/features/admin/poll/questions/answers/documents/documents_spec.rb
@@ -0,0 +1,44 @@
+require "rails_helper"
+
+feature "Documents" do
+
+ background do
+ admin = create(:administrator)
+ login_as(admin.user)
+ end
+
+ context "Index" do
+ scenario "Answer with no documents" do
+ answer = create(:poll_question_answer, question: create(:poll_question))
+ document = create(:document)
+
+ visit admin_answer_documents_path(answer)
+
+ expect(page).not_to have_content(document.title)
+ end
+
+ scenario "Answer with documents" do
+ answer = create(:poll_question_answer, question: create(:poll_question))
+ document = create(:document, documentable: answer)
+
+ visit admin_answer_documents_path(answer)
+
+ expect(page).to have_content(document.title)
+ end
+ end
+
+ scenario "Remove document from answer", :js do
+ answer = create(:poll_question_answer, question: create(:poll_question))
+ document = create(:document, documentable: answer)
+
+ visit admin_answer_documents_path(answer)
+ expect(page).to have_content(document.title)
+
+ accept_confirm "Are you sure?" do
+ click_link "Delete"
+ end
+
+ expect(page).not_to have_content(document.title)
+ end
+
+end