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

fix signaling on the mail_alert_sent

ulferts4896c34178d2
diff --git a/app/services/notifications/create_from_model_service.rb b/app/services/notifications/create_from_model_service.rb
index f51be96b049..4685fb7d3c0 100644
--- a/app/services/notifications/create_from_model_service.rb
+++ b/app/services/notifications/create_from_model_service.rb
@@ -111,9 +111,9 @@ class Notifications::CreateFromModelService
journal:,
actor: user_with_fallback,
reason:,
- read_ian: strategy.supports_ian? ? false : nil,
- mail_reminder_sent: strategy.supports_mail_digest? ? false : nil,
- mail_alert_sent: strategy.supports_mail? ? false : nil
+ read_ian: strategy.supports_ian?(reason) ? false : nil,
+ mail_reminder_sent: strategy.supports_mail_digest?(reason) ? false : nil,
+ mail_alert_sent: strategy.supports_mail?(reason) ? false : nil
}
Notifications::CreateService
@@ -129,7 +129,7 @@ class Notifications::CreateFromModelService
Notifications::UpdateService
.new(model: existing_notification, user:, contract_class: EmptyContract)
- .call(read_ian: strategy.supports_ian? ? false : nil,
+ .call(read_ian: strategy.supports_ian?(reason) ? false : nil,
reason:)
end
diff --git a/app/services/notifications/create_from_model_service/comment_strategy.rb b/app/services/notifications/create_from_model_service/comment_strategy.rb
index 1a3cd14f061..dd139575ebd 100644
--- a/app/services/notifications/create_from_model_service/comment_strategy.rb
+++ b/app/services/notifications/create_from_model_service/comment_strategy.rb
@@ -35,15 +35,15 @@ module Notifications::CreateFromModelService::CommentStrategy
:view_news
end
- def self.supports_ian?
+ def self.supports_ian?(_reason)
false
end
- def self.supports_mail_digest?
+ def self.supports_mail_digest?(_reason)
false
end
- def self.supports_mail?
+ def self.supports_mail?(_reason)
true
end
diff --git a/app/services/notifications/create_from_model_service/message_strategy.rb b/app/services/notifications/create_from_model_service/message_strategy.rb
index eb34f9c56ca..0e7084c0943 100644
--- a/app/services/notifications/create_from_model_service/message_strategy.rb
+++ b/app/services/notifications/create_from_model_service/message_strategy.rb
@@ -35,15 +35,15 @@ module Notifications::CreateFromModelService::MessageStrategy
:view_messages
end
- def self.supports_ian?
+ def self.supports_ian?(_reason)
false
end
- def self.supports_mail_digest?
+ def self.supports_mail_digest?(_reason)
false
end
- def self.supports_mail?
+ def self.supports_mail?(_reason)
true
end
diff --git a/app/services/notifications/create_from_model_service/news_strategy.rb b/app/services/notifications/create_from_model_service/news_strategy.rb
index 38f963cd296..2a2ae7d4ee4 100644
--- a/app/services/notifications/create_from_model_service/news_strategy.rb
+++ b/app/services/notifications/create_from_model_service/news_strategy.rb
@@ -35,15 +35,15 @@ module Notifications::CreateFromModelService::NewsStrategy
:view_news
end
- def self.supports_ian?
+ def self.supports_ian?(_reason)
false
end
- def self.supports_mail_digest?
+ def self.supports_mail_digest?(_reason)
false
end
- def self.supports_mail?
+ def self.supports_mail?(_reason)
true
end
diff --git a/app/services/notifications/create_from_model_service/wiki_page_strategy.rb b/app/services/notifications/create_from_model_service/wiki_page_strategy.rb
index 8aadeaf57ca..3dc3a8e3609 100644
--- a/app/services/notifications/create_from_model_service/wiki_page_strategy.rb
+++ b/app/services/notifications/create_from_model_service/wiki_page_strategy.rb
@@ -35,15 +35,15 @@ module Notifications::CreateFromModelService::WikiPageStrategy
:view_wiki_pages
end
- def self.supports_ian?
+ def self.supports_ian?(_reason)
false
end
- def self.supports_mail_digest?
+ def self.supports_mail_digest?(_reason)
false
end
- def self.supports_mail?
+ def self.supports_mail?(_reason)
true
end
diff --git a/app/services/notifications/create_from_model_service/work_package_strategy.rb b/app/services/notifications/create_from_model_service/work_package_strategy.rb
index ff078b9aa16..c4150e8cf12 100644
--- a/app/services/notifications/create_from_model_service/work_package_strategy.rb
+++ b/app/services/notifications/create_from_model_service/work_package_strategy.rb
@@ -35,16 +35,16 @@ module Notifications::CreateFromModelService::WorkPackageStrategy
:view_work_packages
end
- def self.supports_ian?
+ def self.supports_ian?(_reason)
true
end
- def self.supports_mail_digest?
+ def self.supports_mail_digest?(_reason)
true
end
- def self.supports_mail?
- true
+ def self.supports_mail?(reason)
+ reason == :mentioned
end
def self.watcher_users(journal)
diff --git a/app/workers/notifications/with_marked_notifications.rb b/app/workers/notifications/with_marked_notifications.rb
index e56639dc620..e99d1b2e63b 100644
--- a/app/workers/notifications/with_marked_notifications.rb
+++ b/app/workers/notifications/with_marked_notifications.rb
@@ -37,16 +37,21 @@ module Notifications
def with_marked_notifications(notification_ids)
Notification.transaction do
- mark_notifications_sent(notification_ids)
+ # It might be decided by the callers that the notifications should not be sent after all which
+ # is signaled by `nil`. This happens e.g. for work packages where users might have disabled the
+ # immediate_reminders for mentioned.
+ was_sent = yield
- yield
+ mark_notifications_sent(notification_ids, was_sent.present? ? !!was_sent : nil)
+
+ was_sent
end
end
- def mark_notifications_sent(notification_ids)
+ def mark_notifications_sent(notification_ids, was_sent)
Notification
.where(id: Array(notification_ids))
- .update_all(notification_marked_attribute => true, updated_at: Time.current)
+ .update_all(notification_marked_attribute => was_sent, updated_at: Time.current)
end
end
end
diff --git a/modules/documents/app/services/notifications/create_from_model_service/document_strategy.rb b/modules/documents/app/services/notifications/create_from_model_service/document_strategy.rb
index d2855acbcef..8198cb5470c 100644
--- a/modules/documents/app/services/notifications/create_from_model_service/document_strategy.rb
+++ b/modules/documents/app/services/notifications/create_from_model_service/document_strategy.rb
@@ -35,15 +35,15 @@ module Notifications::CreateFromModelService::DocumentStrategy
:view_documents
end
- def self.supports_ian?
+ def self.supports_ian?(_reason)
false
end
- def self.supports_mail_digest?
+ def self.supports_mail_digest?(_reason)
false
end
- def self.supports_mail?
+ def self.supports_mail?(_reason)
true
end
diff --git a/spec/features/notifications/reminder_mail_spec.rb b/spec/features/notifications/reminder_mail_spec.rb
index d2e8dbde9f0..aa7eb9f0aa8 100644
--- a/spec/features/notifications/reminder_mail_spec.rb
+++ b/spec/features/notifications/reminder_mail_spec.rb
@@ -2,13 +2,13 @@ require "spec_helper"
require_relative "../users/notifications/shared_examples"
RSpec.describe "Reminder email sending", js: false do
- let!(:project) { create(:project, members: { current_user => role }) }
- let!(:mute_project) { create(:project, members: { current_user => role }) }
+ let!(:project) { create(:project, members: { receiving_user => role }) }
+ let!(:mute_project) { create(:project, members: { receiving_user => role }) }
let(:role) { create(:project_role, permissions: %i[view_work_packages]) }
let(:other_user) { create(:user) }
let(:work_package) { create(:work_package, project:) }
- let(:watched_work_package) { create(:work_package, project:, watcher_users: [current_user]) }
- let(:involved_work_package) { create(:work_package, project:, assigned_to: current_user) }
+ let(:watched_work_package) { create(:work_package, project:, watcher_users: [receiving_user]) }
+ let(:involved_work_package) { create(:work_package, project:, assigned_to: receiving_user) }
# GoodJob::Job#cron_at is used for scheduling the reminder mails.
# It needs to be within a time frame eligible for sending out mails for the chosen
# time zone. For the time zone Hawaii (UTC-10) this means 8:00:00 as the job has a cron tab to be run every 15 min.
@@ -27,13 +27,7 @@ RSpec.describe "Reminder email sending", js: false do
# between the changes to a work package and the reminder mail being sent out.
let(:work_package_update_time) { ActiveSupport::TimeZone["Pacific/Honolulu"].parse("2021-09-30T01:50:34").utc }
- around do |example|
- Timecop.travel(work_package_update_time) do
- example.run
- end
- end
-
- current_user do
+ let!(:receiving_user) do
create(
:user,
preferences: {
@@ -61,25 +55,29 @@ RSpec.describe "Reminder email sending", js: false do
)
end
- before do
- watched_work_package
- work_package
- involved_work_package
+ around do |example|
+ Timecop.travel(work_package_update_time) do
+ example.run
+ end
+ end
+ before do
ActiveJob::Base.disable_test_adapter
-
- scheduled_job
end
it "sends a digest mail based on the configuration", with_settings: { journal_aggregation_time_minutes: 0 } do
# Perform some actions the user listens to
User.execute_as other_user do
+ watched_work_package
+ work_package
+ involved_work_package
+
note = <<~NOTE
Hey <mention class="mention"
- data-id="#{current_user.id}"
+ data-id="#{receiving_user.id}"
data-type="user"
- data-text="@#{current_user.name}">
- @#{current_user.name}
+ data-text="@#{receiving_user.name}">
+ @#{receiving_user.name}
</mention>
NOTE
@@ -93,10 +91,15 @@ RSpec.describe "Reminder email sending", js: false do
involved_work_package.save!
end
- 2.times { GoodJob.perform_inline }
+ GoodJob.perform_inline
+ scheduled_job
+ GoodJob.perform_inline
expect(ActionMailer::Base.deliveries.length).to be 1
+ # 3 work package created
+ # 3 times updated (1 for each work package)
+ # One of those was a mention for which the user opted out to not receive immediate notifications
expect(ActionMailer::Base.deliveries.first.subject)
- .to eql "OpenProject - 1 unread notification including a mention"
+ .to eql "OpenProject - 6 unread notifications including a mention"
end
end
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 6c28374eb00..c111c961133 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
@@ -121,7 +121,7 @@ RSpec.describe Notifications::CreateFromModelService,
{
read_ian: false,
reason: :assigned,
- mail_alert_sent: false,
+ mail_alert_sent: nil,
mail_reminder_sent: false
}
end
@@ -139,7 +139,7 @@ RSpec.describe Notifications::CreateFromModelService,
{
read_ian: false,
reason: :assigned,
- mail_alert_sent: false,
+ mail_alert_sent: nil,
mail_reminder_sent: false
}
end
@@ -168,7 +168,7 @@ RSpec.describe Notifications::CreateFromModelService,
{
read_ian: false,
reason: :assigned,
- mail_alert_sent: false,
+ mail_alert_sent: nil,
mail_reminder_sent: false
}
end
@@ -212,7 +212,7 @@ RSpec.describe Notifications::CreateFromModelService,
{
read_ian: false,
reason: :responsible,
- mail_alert_sent: false,
+ mail_alert_sent: nil,
mail_reminder_sent: false
}
end
@@ -265,7 +265,7 @@ RSpec.describe Notifications::CreateFromModelService,
{
read_ian: false,
reason: :watched,
- mail_alert_sent: false,
+ mail_alert_sent: nil,
mail_reminder_sent: false
}
end
@@ -283,7 +283,7 @@ RSpec.describe Notifications::CreateFromModelService,
{
read_ian: false,
reason: :watched,
- mail_alert_sent: false,
+ mail_alert_sent: nil,
mail_reminder_sent: false
}
end
@@ -332,7 +332,7 @@ RSpec.describe Notifications::CreateFromModelService,
{
read_ian: false,
reason: :created,
- mail_alert_sent: false,
+ mail_alert_sent: nil,
mail_reminder_sent: false
}
end
@@ -350,7 +350,7 @@ RSpec.describe Notifications::CreateFromModelService,
{
read_ian: false,
reason: :created,
- mail_alert_sent: false,
+ mail_alert_sent: nil,
mail_reminder_sent: false
}
end
@@ -380,7 +380,7 @@ RSpec.describe Notifications::CreateFromModelService,
{
read_ian: false,
reason: :created,
- mail_alert_sent: false,
+ mail_alert_sent: nil,
mail_reminder_sent: false
}
end
@@ -429,7 +429,7 @@ RSpec.describe Notifications::CreateFromModelService,
{
read_ian: false,
reason: :shared,
- mail_alert_sent: false,
+ mail_alert_sent: nil,
mail_reminder_sent: false
}
end
@@ -477,7 +477,7 @@ RSpec.describe Notifications::CreateFromModelService,
{
read_ian: false,
reason: :created,
- mail_alert_sent: false,
+ mail_alert_sent: nil,
mail_reminder_sent: false
}
end
@@ -533,7 +533,7 @@ RSpec.describe Notifications::CreateFromModelService,
{
read_ian: false,
reason: :commented,
- mail_alert_sent: false,
+ mail_alert_sent: nil,
mail_reminder_sent: false
}
end
@@ -582,7 +582,7 @@ RSpec.describe Notifications::CreateFromModelService,
{
read_ian: false,
reason: :processed,
- mail_alert_sent: false,
+ mail_alert_sent: nil,
mail_reminder_sent: false
}
end
@@ -631,7 +631,7 @@ RSpec.describe Notifications::CreateFromModelService,
{
read_ian: false,
reason: :prioritized,
- mail_alert_sent: false,
+ mail_alert_sent: nil,
mail_reminder_sent: false
}
end
@@ -680,7 +680,7 @@ RSpec.describe Notifications::CreateFromModelService,
{
read_ian: false,
reason: :scheduled,
- mail_alert_sent: false,
+ mail_alert_sent: nil,
mail_reminder_sent: false
}
end
@@ -729,7 +729,7 @@ RSpec.describe Notifications::CreateFromModelService,
{
read_ian: false,
reason: :scheduled,
- mail_alert_sent: false,
+ mail_alert_sent: nil,
mail_reminder_sent: false
}
end
@@ -762,7 +762,7 @@ RSpec.describe Notifications::CreateFromModelService,
{
read_ian: false,
reason: :assigned,
- mail_alert_sent: false,
+ mail_alert_sent: nil,
mail_reminder_sent: false
}
end
diff --git a/spec/services/notifications/mail_service_mentioned_integration_spec.rb b/spec/services/notifications/mail_service_mentioned_integration_spec.rb
index 22bb27e282e..392b5b43339 100644
--- a/spec/services/notifications/mail_service_mentioned_integration_spec.rb
+++ b/spec/services/notifications/mail_service_mentioned_integration_spec.rb
@@ -75,7 +75,7 @@ RSpec.describe Notifications::MailService, "Mentioned integration", type: :model
expect(assigned_notification).to be_present
expect(assigned_notification.recipient).to eq assignee
expect(assigned_notification.read_ian).to be false
- expect(assigned_notification.mail_alert_sent).to be false
+ expect(assigned_notification.mail_alert_sent).to be_nil
end
it "triggers only one mention notification mail when editing attributes afterwards" do