Merge pull request #3231 from consul/poll-answer-documents
[Backport] Allow admins delete poll answer documents
This commit is contained in:
@@ -11,7 +11,7 @@ class DocumentsController < ApplicationController
|
|||||||
else
|
else
|
||||||
flash[:alert] = t "documents.actions.destroy.alert"
|
flash[:alert] = t "documents.actions.destroy.alert"
|
||||||
end
|
end
|
||||||
redirect_to params[:from]
|
redirect_to request.referer
|
||||||
end
|
end
|
||||||
format.js do
|
format.js do
|
||||||
if @document.destroy
|
if @document.destroy
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ module Abilities
|
|||||||
cannot :comment_as_moderator, [::Legislation::Question, Legislation::Annotation, ::Legislation::Proposal]
|
cannot :comment_as_moderator, [::Legislation::Question, Legislation::Annotation, ::Legislation::Proposal]
|
||||||
|
|
||||||
can [:create], Document
|
can [:create], Document
|
||||||
|
can [:destroy], Document, documentable_type: "Poll::Question::Answer"
|
||||||
can [:create, :destroy], DirectUpload
|
can [:create, :destroy], DirectUpload
|
||||||
|
|
||||||
can [:deliver], Newsletter, hidden_at: nil
|
can [:deliver], Newsletter, hidden_at: nil
|
||||||
|
|||||||
@@ -14,19 +14,13 @@
|
|||||||
|
|
||||||
<%= render 'shared/errors', resource: @answer %>
|
<%= render 'shared/errors', resource: @answer %>
|
||||||
|
|
||||||
<div class="row">
|
<div class="documents">
|
||||||
<div class="small-12 column">
|
|
||||||
<div class="documents small-12">
|
|
||||||
<%= render 'documents/nested_documents', documentable: @answer, f: f %>
|
<%= render 'documents/nested_documents', documentable: @answer, f: f %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="small-12 medium-6 large-2">
|
||||||
<div class="actions small-12 medium-4 margin-top">
|
|
||||||
<%= f.submit(class: "button expanded", value: t("shared.save")) %>
|
<%= f.submit(class: "button expanded", value: t("shared.save")) %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if @answer.documents.present? %>
|
<% if @answer.documents.present? %>
|
||||||
@@ -42,11 +36,17 @@
|
|||||||
<%= link_to document.title, document.attachment.url %>
|
<%= link_to document.title, document.attachment.url %>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
<%= link_to t('documents.buttons.download_document'),
|
<%= link_to t("documents.buttons.download_document"),
|
||||||
document.attachment.url,
|
document.attachment.url,
|
||||||
target: "_blank",
|
target: "_blank",
|
||||||
rel: "nofollow",
|
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") } %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -13,7 +13,8 @@
|
|||||||
<% if can?(:destroy, document) %>
|
<% if can?(:destroy, document) %>
|
||||||
<br>
|
<br>
|
||||||
<%= link_to t("documents.buttons.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") },
|
data: { confirm: t("documents.actions.destroy.confirm") },
|
||||||
class: "delete" %>
|
class: "delete" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -1187,6 +1187,7 @@ en:
|
|||||||
author: Author
|
author: Author
|
||||||
content: Content
|
content: Content
|
||||||
created_at: Created at
|
created_at: Created at
|
||||||
|
delete: Delete
|
||||||
spending_proposals:
|
spending_proposals:
|
||||||
index:
|
index:
|
||||||
geozone_filter_all: All zones
|
geozone_filter_all: All zones
|
||||||
|
|||||||
@@ -1187,6 +1187,7 @@ es:
|
|||||||
author: Autor
|
author: Autor
|
||||||
content: Contenido
|
content: Contenido
|
||||||
created_at: Fecha de creación
|
created_at: Fecha de creación
|
||||||
|
delete: Eliminar
|
||||||
spending_proposals:
|
spending_proposals:
|
||||||
index:
|
index:
|
||||||
geozone_filter_all: Todos los ámbitos de actuación
|
geozone_filter_all: Todos los ámbitos de actuación
|
||||||
|
|||||||
@@ -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
|
||||||
Reference in New Issue
Block a user