Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Allow own deletion

Oliver Günther61fec026b125
diff --git a/app/components/admin/quarantined_attachments/row_component.rb b/app/components/admin/quarantined_attachments/row_component.rb
index fec101fa34f..efe85f946bf 100644
--- a/app/components/admin/quarantined_attachments/row_component.rb
+++ b/app/components/admin/quarantined_attachments/row_component.rb
@@ -63,8 +63,6 @@ module Admin
end
def override_link
- return if User.current == attachment.author
-
helpers.link_to(
helpers.op_icon('icon icon-unlocked'),
{ controller: '/admin/attachments/quarantined_attachments', action: :override, id: model },
@@ -75,8 +73,6 @@ module Admin
end
def delete_link
- return if User.current == attachment.author
-
helpers.link_to(
helpers.op_icon('icon icon-delete'),
{ controller: '/admin/attachments/quarantined_attachments', action: :destroy, id: model },
diff --git a/app/controllers/admin/attachments/quarantined_attachments_controller.rb b/app/controllers/admin/attachments/quarantined_attachments_controller.rb
index f2d4286e408..f1fd4b6a5dc 100644
--- a/app/controllers/admin/attachments/quarantined_attachments_controller.rb
+++ b/app/controllers/admin/attachments/quarantined_attachments_controller.rb
@@ -34,7 +34,6 @@ module Admin
before_action :find_quarantined_attachments
before_action :find_attachment, only: %i[override destroy]
- before_action :prevent_same_user, only: %i[override destroy]
menu_item :attachment_quarantine
@@ -88,13 +87,6 @@ module Admin
rescue ActiveRecord::RecordNotFound
render_404
end
-
- def prevent_same_user
- if current_user == @attachment.author
- flash[:error] = t('antivirus_scan.quarantined_attachments.error_cannot_act_self')
- redirect_to action: :index
- end
- end
end
end
end
diff --git a/spec/features/admin/attachments/quarantined_attachments_spec.rb b/spec/features/admin/attachments/quarantined_attachments_spec.rb
index 616f6c44949..c60fcb218cb 100644
--- a/spec/features/admin/attachments/quarantined_attachments_spec.rb
+++ b/spec/features/admin/attachments/quarantined_attachments_spec.rb
@@ -56,7 +56,7 @@ RSpec.describe 'Quarantined attachments', :js, :with_cuprite do
page.within("#quarantined_attachment_#{own_quarantined_attachment.id}") do
expect(page).to have_no_link I18n.t('antivirus_scan.quarantined_attachments.override')
- expect(page).to have_no_link I18n.t('antivirus_scan.quarantined_attachments.delete')
+ expect(page).to have_link I18n.t('antivirus_scan.quarantined_attachments.delete')
end
page.within("#quarantined_attachment_#{quarantined_attachment.id}") do
diff --git a/spec/requests/admin/attachments/quarantined_attachments_spec.rb b/spec/requests/admin/attachments/quarantined_attachments_spec.rb
index e4754349acc..d760013b57f 100644
--- a/spec/requests/admin/attachments/quarantined_attachments_spec.rb
+++ b/spec/requests/admin/attachments/quarantined_attachments_spec.rb
@@ -29,15 +29,13 @@
require 'spec_helper'
RSpec.describe 'Quarantined attachments',
+ with_ee: %i[virus_scanning],
type: :rails_request do
shared_let(:other_author) { create(:user) }
shared_let(:admin) { create(:admin) }
shared_let(:container) { create(:work_package) }
- shared_let(:own_quarantined_attachment) do
- create(:attachment, container:, status: :quarantined, author: admin, filename: 'my-own.txt')
- end
shared_let(:quarantined_attachment) do
create(:attachment, container:, status: :quarantined, author: other_author, filename: 'other-1.txt')
end
@@ -61,28 +59,21 @@ RSpec.describe 'Quarantined attachments',
end
describe 'DELETE /admin/quarantined_attachments/:id' do
- it 'allows management other attachments' do
+ it 'allows management of attachments' do
delete admin_quarantined_attachment_path(quarantined_attachment)
expect(response).to be_redirect
expect { quarantined_attachment.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
- it 'disallows own attachments' do
- delete admin_quarantined_attachment_path(own_quarantined_attachment)
- expect(response).to be_redirect
-
- expect { own_quarantined_attachment.reload }.not_to raise_error
- end
-
it 'fails to find if not quarantined' do
delete admin_quarantined_attachment_path(scanned_attachment)
- expect(response).to have_http_status 404
+ expect(response).to have_http_status :not_found
end
end
describe 'PATCH /admin/quarantined_attachments/:id/override' do
- it 'allows management other attachments' do
+ it 'allows management of attachments' do
patch override_admin_quarantined_attachment_path(quarantined_attachment)
expect(response).to be_redirect
@@ -90,17 +81,9 @@ RSpec.describe 'Quarantined attachments',
expect(quarantined_attachment).to be_status_scanned
end
- it 'disallows own attachments' do
- patch override_admin_quarantined_attachment_path(own_quarantined_attachment)
- expect(response).to be_redirect
-
- own_quarantined_attachment.reload
- expect(own_quarantined_attachment).to be_status_quarantined
- end
-
it 'fails to find if not quarantined' do
patch override_admin_quarantined_attachment_path(scanned_attachment)
- expect(response).to have_http_status 404
+ expect(response).to have_http_status :not_found
end
end
end