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

[#55255] Notifications are sent to the author if the author is member of a @mentioned group

Dombi Attilafbcae1e21a78
diff --git a/app/services/notifications/create_from_model_service.rb b/app/services/notifications/create_from_model_service.rb
index f51be96b049..8e109543519 100644
--- a/app/services/notifications/create_from_model_service.rb
+++ b/app/services/notifications/create_from_model_service.rb
@@ -288,24 +288,26 @@ class Notifications::CreateFromModelService
end
def mention_matches
- text = text_for_mentions
-
- user_ids_tag_after,
- user_ids_tag_before,
- user_ids_hash,
- user_login_names,
- group_ids_tag_after,
- group_ids_tag_before,
- group_ids_hash = text
- .scan(MENTION_PATTERN)
- .transpose
- .each(&:compact!)
-
- {
- user_ids: [user_ids_tag_after, user_ids_tag_before, user_ids_hash].flatten.compact,
- user_login_names: [user_login_names].flatten.compact,
- group_ids: [group_ids_tag_after, group_ids_tag_before, group_ids_hash].flatten.compact
- }
+ @mention_matches ||= begin
+ text = text_for_mentions
+
+ user_ids_tag_after,
+ user_ids_tag_before,
+ user_ids_hash,
+ user_login_names,
+ group_ids_tag_after,
+ group_ids_tag_before,
+ group_ids_hash = text
+ .scan(MENTION_PATTERN)
+ .transpose
+ .each(&:compact!)
+
+ {
+ user_ids: [user_ids_tag_after, user_ids_tag_before, user_ids_hash].flatten.compact,
+ user_login_names: [user_login_names].flatten.compact,
+ group_ids: [group_ids_tag_after, group_ids_tag_before, group_ids_hash].flatten.compact
+ }
+ end
end
def abort_sending?
@@ -328,10 +330,16 @@ class Notifications::CreateFromModelService
end
end
+ def user_not_mentioned_or_mentioned_indirectly(self_reason)
+ self_reason != NotificationSetting::MENTIONED ||
+ (mention_matches[:user_ids].exclude?(user_with_fallback.id) &&
+ mention_matches[:user_login_names].exclude?(user_with_fallback.login))
+ end
+
def remove_self_recipient(receivers)
if receivers.key?(user_with_fallback.id)
self_reasons = receivers[user_with_fallback.id]
- self_reasons.delete_if { |item| item != NotificationSetting::MENTIONED }
+ self_reasons.delete_if { |reason| user_not_mentioned_or_mentioned_indirectly(reason) }
if self_reasons.empty?
receivers.delete(user_with_fallback.id)
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..b4ff6befbe4 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
@@ -991,16 +991,7 @@ RSpec.describe Notifications::CreateFromModelService,
end
let(:author) { recipient }
- it_behaves_like "creates notification" do
- let(:notification_channel_reasons) do
- {
- read_ian: false,
- reason: :mentioned,
- mail_alert_sent: false,
- mail_reminder_sent: false
- }
- end
- end
+ it_behaves_like "creates no notification"
end
context "when there is already a notification for the journal (because it was aggregated)" do
@@ -1082,16 +1073,7 @@ RSpec.describe Notifications::CreateFromModelService,
end
let(:author) { recipient }
- it_behaves_like "creates notification" do
- let(:notification_channel_reasons) do
- {
- read_ian: false,
- reason: :mentioned,
- mail_alert_sent: false,
- mail_reminder_sent: false
- }
- end
- end
+ it_behaves_like "creates no notification"
end
end