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

Remove add_attachment as no longer in use

Oliver Günther88ea8062656d
diff --git a/modules/documents/app/controllers/documents_controller.rb b/modules/documents/app/controllers/documents_controller.rb
index fecaad6b917..f03b3bced4d 100644
--- a/modules/documents/app/controllers/documents_controller.rb
+++ b/modules/documents/app/controllers/documents_controller.rb
@@ -87,6 +87,8 @@ class DocumentsController < ApplicationController
model: @document,
args: document_params
+ binding.pry
+
if call.success?
flash[:notice] = I18n.t(:notice_successful_update)
redirect_to action: 'show', id: @document
@@ -102,45 +104,8 @@ class DocumentsController < ApplicationController
redirect_to controller: '/documents', action: 'index', project_id: @project
end
- def add_attachment
- current_attachments = @document.attachments.pluck(:id)
- call = attachable_update_call ::Documents::UpdateService,
- model: @document,
- args: document_params
-
- if call.success?
- added = call.result
- .attachments
- .reject { |a| current_attachments.include?(a.id) }
-
- notify_attachments added
- end
-
- redirect_to action: 'show', id: @document
- end
-
private
- def notify_attachments(added)
- return if added.empty?
-
- document_added_recipients.find_each do |user|
- DocumentsMailer.attachments_added(user, added).deliver_later
- end
- end
-
- def document_added_recipients
- notified_users = NotificationSetting
- .where(project_id: nil, channel: NotificationSetting.channels[:mail])
- .where(NotificationSetting::DOCUMENT_ADDED => true)
- .where.not(user_id: current_user.id)
- .select(:user_id)
-
- User
- .allowed(:view_documents, @project)
- .where(id: notified_users)
- end
-
def document_params
params.fetch(:document, {}).permit('category_id', 'title', 'description')
end
diff --git a/modules/documents/config/routes.rb b/modules/documents/config/routes.rb
index c27add9a046..ad06898df4a 100644
--- a/modules/documents/config/routes.rb
+++ b/modules/documents/config/routes.rb
@@ -31,9 +31,5 @@ OpenProject::Application.routes.draw do
resources :documents, only: %i[create new index]
end
- resources :documents, except: %i[create new index] do
- member do
- post 'add_attachment'
- end
- end
+ resources :documents, except: %i[create new index]
end
diff --git a/modules/documents/lib/open_project/documents/engine.rb b/modules/documents/lib/open_project/documents/engine.rb
index 1751ab68da3..cc36e73729c 100644
--- a/modules/documents/lib/open_project/documents/engine.rb
+++ b/modules/documents/lib/open_project/documents/engine.rb
@@ -46,7 +46,7 @@ module OpenProject::Documents
project_module :documents do |_map|
permission :view_documents, documents: %i[index show download]
permission :manage_documents, {
- documents: %i[new create edit update destroy add_attachment]
+ documents: %i[new create edit update destroy]
}, require: :loggedin
end
diff --git a/modules/documents/spec/controllers/documents_controller_spec.rb b/modules/documents/spec/controllers/documents_controller_spec.rb
index 597bb515779..9a0d0e6d610 100644
--- a/modules/documents/spec/controllers/documents_controller_spec.rb
+++ b/modules/documents/spec/controllers/documents_controller_spec.rb
@@ -129,6 +129,12 @@ describe DocumentsController do
.with(:create_notifications, document.journals.last, true)
end
+ it 'does trigger a workflow job for the document' do
+ expect(Notifications::WorkflowJob)
+ .to have_been_enqueued
+ .with(:create_notifications, document.journals.last, true)
+ end
+
describe "with attachments" do
let(:uncontainered) { FactoryBot.create :attachment, container: nil, author: admin }
@@ -173,90 +179,6 @@ describe DocumentsController do
end
end
- describe '#add_attachment' do
- let(:recipient) { nil }
- let(:uncontainered) { FactoryBot.create :attachment, container: nil, author: admin }
-
- before do
- allow(DocumentsMailer)
- .to receive(:attachments_added)
- .and_call_original
-
- recipient
- document
-
- post :add_attachment,
- params: {
- id: document.id,
- attachments: { '1' => { id: uncontainered.id } }
- }
- end
-
- it "adds the attachment" do
- expect(response).to be_redirect
- document.reload
- expect(document.attachments.length).to eq(1)
- expect(uncontainered.reload).to eq document.attachments.first
- end
-
- it 'does not trigger a mail for the current user' do
- expect(DocumentsMailer)
- .not_to have_received(:attachments_added)
- .with(current_user, *any_args)
- end
-
- context 'with a user that does not want to be notified' do
- let!(:recipient) do
- FactoryBot.create :user,
- member_in_project: project,
- notification_settings: [
- FactoryBot.build(:mail_notification_setting,
- NotificationSetting::DOCUMENT_ADDED => false)
- ]
- end
-
- it 'does not trigger an attachment job' do
- expect(DocumentsMailer)
- .not_to have_received(:attachments_added)
- .with(recipient, *any_args)
- end
- end
-
- context 'with a user the document is not visible for' do
- let!(:recipient) do
- FactoryBot.create :user,
- notification_settings: [
- FactoryBot.build(:mail_notification_setting,
- NotificationSetting::DOCUMENT_ADDED => true)
- ]
- end
-
- it 'does not trigger an attachment job' do
- expect(DocumentsMailer)
- .not_to have_received(:attachments_added)
- .with(recipient, *any_args)
- end
- end
-
- context 'with a user that wants to be notified' do
- let!(:recipient) do
- FactoryBot.create :user,
- member_in_project: project,
- member_with_permissions: %i[view_documents],
- notification_settings: [
- FactoryBot.build(:mail_notification_setting,
- NotificationSetting::DOCUMENT_ADDED => true)
- ]
- end
-
- it 'does trigger an attachment job' do
- expect(DocumentsMailer)
- .to have_received(:attachments_added)
- .with(recipient, *any_args)
- end
- end
- end
-
describe "destroy" do
before do
document