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

rely on caller to reset the journal notification setting

ulferts2ed7a6994303
diff --git a/app/models/journal/notification_configuration.rb b/app/models/journal/notification_configuration.rb
index 3a5946bc918..6d36b33fb9a 100644
--- a/app/models/journal/notification_configuration.rb
+++ b/app/models/journal/notification_configuration.rb
@@ -30,12 +30,6 @@
class Journal::NotificationConfiguration
class << self
- attr_reader :active
-
- def reset
- self.active = true
- end
-
def with(send_notifications, &block)
old_value = active
@@ -46,15 +40,13 @@ class Journal::NotificationConfiguration
self.active = old_value
end
- def with_reset(&block)
- block.call
- ensure
- reset
+ def active?
+ active
end
protected
- attr_writer :active
+ attr_accessor :active
end
self.active = true
diff --git a/lib/plugins/acts_as_journalized/lib/redmine/acts/journalized/save_hooks.rb b/lib/plugins/acts_as_journalized/lib/redmine/acts/journalized/save_hooks.rb
index 03bd529099c..ccd751837fb 100644
--- a/lib/plugins/acts_as_journalized/lib/redmine/acts/journalized/save_hooks.rb
+++ b/lib/plugins/acts_as_journalized/lib/redmine/acts/journalized/save_hooks.rb
@@ -69,7 +69,7 @@ module Redmine::Acts::Journalized
end
def save_journals
- with_journal_attributes_and_notification_reset do
+ with_ensured_journal_attributes do
add_journal = journals.empty? || JournalManager.changed?(self) || !@journal_notes.empty?
if add_journal
@@ -77,7 +77,7 @@ module Redmine::Acts::Journalized
OpenProject::Notifications.send('journal_created',
journal: journal,
- send_notification: Journal::NotificationConfiguration.active)
+ send_notification: Journal::NotificationConfiguration.active?)
end
end
@@ -90,15 +90,6 @@ module Redmine::Acts::Journalized
private
- def with_journal_attributes_and_notification_reset
- with_ensured_journal_attributes do
- # Need to clear the notification setting after each usage otherwise it might be cached
- Journal::NotificationConfiguration.with_reset do
- yield
- end
- end
- end
-
def with_ensured_journal_attributes
@journal_user ||= User.current
@journal_notes ||= ''
diff --git a/spec/models/journal/notification_configuration_spec.rb b/spec/models/journal/notification_configuration_spec.rb
index d34a952aee5..6a47ebf47db 100644
--- a/spec/models/journal/notification_configuration_spec.rb
+++ b/spec/models/journal/notification_configuration_spec.rb
@@ -30,7 +30,7 @@ require 'spec_helper'
describe Journal::NotificationConfiguration, type: :model do
describe '.with' do
- let!(:send_notification_before) { described_class.active }
+ let!(:send_notification_before) { described_class.active? }
let(:proc_called_counter) { OpenStruct.new called: false, send_notifications: !send_notification_before }
let(:proc) { Proc.new { proc_called_counter.called = true } }
@@ -51,7 +51,7 @@ describe Journal::NotificationConfiguration, type: :model do
it 'resets the send_notifications to the value before' do
described_class.with !send_notification_before, &proc
- expect(described_class.active)
+ expect(described_class.active?)
.to eql send_notification_before
end
@@ -60,7 +60,7 @@ describe Journal::NotificationConfiguration, type: :model do
expect { described_class.with(!send_notification_before) { raise ArgumentError } }
.to raise_error ArgumentError
- expect(described_class.active)
+ expect(described_class.active?)
.to eql send_notification_before
end
end