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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#45020] Replies to comments in which I was mentioned do create new, undesired notifications
Dombi Attila5f81d8a773fa
diff --git a/app/services/notifications/create_from_model_service.rb b/app/services/notifications/create_from_model_service.rbindex 003765e6e66..c4c14b598bb 100644--- a/app/services/notifications/create_from_model_service.rb+++ b/app/services/notifications/create_from_model_service.rb@@ -35,7 +35,14 @@ class Notifications::CreateFromModelServiceMENTION_GROUP_ID_PATTERN ='<mention[^>]*(?:data-type="group"[^>]*data-id="(\d+)")|(?:data-id="(\d+)"[^>]*data-type="group")[^>]*>)|(?:\bgroup#(\d+)\b'.freeze- MENTION_PATTERN = Regexp.new("(?:#{MENTION_USER_ID_PATTERN})|(?:#{MENTION_USER_LOGIN_PATTERN})|(?:#{MENTION_GROUP_ID_PATTERN})")+ COMBINED_MENTION_PATTERN =+ "(?:#{MENTION_USER_ID_PATTERN})|(?:#{MENTION_USER_LOGIN_PATTERN})|(?:#{MENTION_GROUP_ID_PATTERN})".freeze++ # Skip looking for mentions in quoted lines completely.+ # We need to allow an optional single white space before the ">", because the `#text_for_mentions`+ # method appends a white space to the journal details. With the notes it's not the case.+ NON_QUOTED_LINES = '^(?! ?> ).*'.freeze+ MENTION_PATTERN = Regexp.new("#{NON_QUOTED_LINES}#{COMBINED_MENTION_PATTERN}")def initialize(model)self.model = modeldiff --git a/spec/services/notifications/create_from_model_service_work_package_spec.rb b/spec/services/notifications/create_from_model_service_work_package_spec.rbindex 8b5c9e32083..8a42957671c 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@@ -173,7 +173,7 @@ describe Notifications::CreateFromModelService,endcontext 'when assignee is placeholder user' do- let(:recipient) { create :placeholder_user }+ let(:recipient) { create(:placeholder_user) }it_behaves_like 'creates no notification'end@@ -226,7 +226,7 @@ describe Notifications::CreateFromModelService,endcontext 'when responsible is placeholder user' do- let(:recipient) { create :placeholder_user }+ let(:recipient) { create(:placeholder_user) }it_behaves_like 'creates no notification'end@@ -855,6 +855,57 @@ describe Notifications::CreateFromModelService,endend+ context "when the added text contains a user mention tag inside a quote" do+ let(:note) do+ <<~NOTE+ #{recipient.name} wrote:+ > Hello <mention class="mention" data-id="#{recipient.id}" data-type="user" data-text="@#{recipient.name}">@#{recipient.name}</mention>+ NOTE+ end++ it_behaves_like 'creates no notification'+ end++ context "when the added text contains a user mention tag inside an invalid quote" do+ let(:note) do+ <<~NOTE+ #{recipient.name} wrote:+ >Hello <mention class="mention" data-id="#{recipient.id}" data-type="user" data-text="@#{recipient.name}">@#{recipient.name}</mention>+ NOTE+ end++ 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+ end++ context "when the added text contains a user mention tag inside a quote and outside" do+ let(:note) do+ <<~NOTE+ Hi <mention class="mention" data-id="#{recipient.id}" data-type="user" data-text="@#{recipient.name}">@#{recipient.name}</mention> :+ > Hello <mention class="mention" data-id="#{recipient.id}" data-type="user" data-text="@#{recipient.name}">@#{recipient.name}</mention>+ NOTE+ end++ 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+ end+context "when the recipient turned off mention notifications" dolet(:recipient_notification_settings) do[