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

open up updating existing notifications

ulferts1f8b81e04b98
diff --git a/app/services/notifications/create_from_model_service.rb b/app/services/notifications/create_from_model_service.rb
index ecd0b78aa0e..b471f7ecc78 100644
--- a/app/services/notifications/create_from_model_service.rb
+++ b/app/services/notifications/create_from_model_service.rb
@@ -72,12 +72,9 @@ class Notifications::CreateFromModelService
attr_accessor :model
# In case a notification already exists (because the journal was aggregated)
+ # an existing notification is updated
def update_or_create_notification(recipient_id, reason)
- if reason == :mentioned
- update_notification(recipient_id) or create_notification(recipient_id, reason)
- else
- create_notification(recipient_id, reason)
- end
+ update_notification(recipient_id, reason) or create_notification(recipient_id, reason)
end
def create_notification(recipient_id, reason)
@@ -98,15 +95,16 @@ class Notifications::CreateFromModelService
.call(notification_attributes)
end
- def update_notification(recipient_id)
+ def update_notification(recipient_id, reason)
existing_notification = Notification
- .find_by(journal_id: journal.id, recipient_id:, reason: :mentioned)
+ .find_by(resource:, journal:, recipient_id:)
return unless existing_notification
Notifications::UpdateService
.new(model: existing_notification, user:, contract_class: EmptyContract)
- .call(read_ian: false)
+ .call(read_ian: strategy.supports_ian? ? false : nil,
+ reason:)
end
def delete_outdated_notifications(current_recipient_ids)
diff --git a/spec/services/notifications/create_from_model_service_work_package_spec.rb b/spec/services/notifications/create_from_model_service_work_package_spec.rb
index 8c35743e420..57d8d815100 100644
--- a/spec/services/notifications/create_from_model_service_work_package_spec.rb
+++ b/spec/services/notifications/create_from_model_service_work_package_spec.rb
@@ -890,7 +890,7 @@ describe Notifications::CreateFromModelService,
context 'when there is already a notification for the journal (because it was aggregated)' do
let(:note) { "Hello user:\"#{recipient_login}\"" }
let!(:existing_notification) do
- create(:notification, journal:, recipient:, reason: :mentioned, read_ian: true)
+ create(:notification, resource:, journal:, recipient:, reason: :mentioned, read_ian: true)
end
it_behaves_like 'creates no notification'
@@ -906,7 +906,7 @@ describe Notifications::CreateFromModelService,
context 'when there is already a notification for the journal (aggregation) but the user is no longer mentioned' do
let(:note) { "Hello you" }
let!(:existing_notification) do
- create(:notification, journal:, recipient:, reason: :mentioned, read_ian: true)
+ create(:notification, resource:, journal:, recipient:, reason: :mentioned, read_ian: true)
end
it_behaves_like 'creates no notification'
@@ -1012,7 +1012,7 @@ describe Notifications::CreateFromModelService,
context 'when on aggregating the journal, sending of notifications is prevented' do
let!(:existing_notification) do
- create(:notification, journal:, recipient:, reason: :mentioned, read_ian: true)
+ create(:notification, resource:, journal:, recipient:, reason: :mentioned, read_ian: true)
end
let(:send_notifications) { false }
let(:user_property) { :watcher }