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

no mail on empty wp update

ulferts59f907560e63
diff --git a/app/models/journal.rb b/app/models/journal.rb
index 1435c8fa757..18417060ed1 100644
--- a/app/models/journal.rb
+++ b/app/models/journal.rb
@@ -121,6 +121,10 @@ class Journal < ActiveRecord::Base
predecessor
end
+ def noop?
+ (!notes || notes&.empty?) && get_changes.empty?
+ end
+
private
def save_data
diff --git a/app/models/journal/aggregated_journal.rb b/app/models/journal/aggregated_journal.rb
index 90279cd3122..83f9bece403 100644
--- a/app/models/journal/aggregated_journal.rb
+++ b/app/models/journal/aggregated_journal.rb
@@ -346,6 +346,7 @@ class Journal::AggregatedJournal
:project,
:data,
:data=,
+ :noop?,
to: :journal
# Initializes a new AggregatedJournal. Allows to explicitly set a predecessor, if it is already
diff --git a/app/services/notifications/journal_wp_mail_service.rb b/app/services/notifications/journal_wp_mail_service.rb
index e3e6c3f7ffe..6a0f55ade25 100644
--- a/app/services/notifications/journal_wp_mail_service.rb
+++ b/app/services/notifications/journal_wp_mail_service.rb
@@ -39,7 +39,7 @@ class Notifications::JournalWPMailService
private
def journal_complete_mail(journal, send_mails)
- return nil unless send_mail?(journal, send_mails)
+ return nil if abort_sending?(journal, send_mails)
author = User.find_by(id: journal.user_id) || DeletedUser.first
@@ -129,5 +129,9 @@ class Notifications::JournalWPMailService
def notification_enabled?(name)
Setting.notified_events.include?(name)
end
+
+ def abort_sending?(journal, send_mails)
+ !send_mail?(journal, send_mails) || journal.noop?
+ end
end
end
diff --git a/lib/api/v3/activities/activity_representer.rb b/lib/api/v3/activities/activity_representer.rb
index c82e69b53c4..83bbfd9c5e5 100644
--- a/lib/api/v3/activities/activity_representer.rb
+++ b/lib/api/v3/activities/activity_representer.rb
@@ -70,7 +70,7 @@ module API
formattable_property :notes,
as: :comment,
getter: ->(*) {
- text = if empty?
+ text = if represented.noop?
"_#{I18n.t(:'journals.changes_retracted')}_"
else
represented.notes
@@ -97,7 +97,7 @@ module API
date_time_property :created_at
def _type
- if empty? || represented.notes.present?
+ if represented.noop? || represented.notes.present?
'Activity::Comment'
else
'Activity'
@@ -117,10 +117,6 @@ module API
def render_details(journal, no_html: false)
journal.details.map { |d| journal.render_detail(d, no_html: no_html) }
end
-
- def empty?
- represented.get_changes.empty? && represented.notes.empty?
- end
end
end
end
diff --git a/spec/services/notifications/journal_wp_mail_service_spec.rb b/spec/services/notifications/journal_wp_mail_service_spec.rb
index 847d5462b78..4c2d6dfb0bb 100644
--- a/spec/services/notifications/journal_wp_mail_service_spec.rb
+++ b/spec/services/notifications/journal_wp_mail_service_spec.rb
@@ -333,6 +333,19 @@ describe Notifications::JournalWPMailService do
it_behaves_like 'mentioned'
end
end
+
+ context 'aggregated journal is empty' do
+ let(:journal) { journal_2_empty_change }
+ let(:journal_2_empty_change) do
+ work_package.add_journal(author, 'temp')
+ work_package.save(validate: false)
+ work_package.journals.last.tap do |j|
+ j.update_column(:notes, nil)
+ end
+ end
+
+ it_behaves_like 'sends no mail'
+ end
end
describe 'initialization' do