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

Remove deprecated Setting::CallbackHelper (#11965)

Christophe Bliardf88889489ff2
diff --git a/app/models/setting.rb b/app/models/setting.rb
index 5ec0ec19e34..e45cb5d32a9 100644
--- a/app/models/setting.rb
+++ b/app/models/setting.rb
@@ -27,7 +27,6 @@
#++
class Setting < ApplicationRecord
- extend CallbacksHelper
extend Aliases
extend MailSettings
@@ -213,9 +212,6 @@ class Setting < ApplicationRecord
# Delete the cache
clear_cache(old_cache_key)
- # fire callbacks for name and pass as much information as possible
- fire_callbacks(name, new_value, old_value)
-
new_value
else
old_value
diff --git a/app/models/setting/callbacks_helper.rb b/app/models/setting/callbacks_helper.rb
deleted file mode 100644
index 93cc2ff2fd3..00000000000
--- a/app/models/setting/callbacks_helper.rb
+++ /dev/null
@@ -1,59 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2023 the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-
-class Setting
- module CallbacksHelper
- # register a callback for a setting named #name
- def register_callback(name, &)
- # register the block with the underlying notifications system
- notifier.subscribe(notification_event_for(name), &)
- end
- # register_callback is not used anymore in our code
- # it can be removed along with fire_callbacks in next major version
- OpenProject::Deprecation.deprecate_method(self, :register_callback)
-
- # instructs the underlying notifications system to publish all setting events for setting #name
- # based on the new and old setting objects different events can be triggered
- # currently, that's whenever a setting is set regardless whether the value changed
- def fire_callbacks(name, new_value, old_value)
- notifier.send(notification_event_for(name), value: new_value, old_value:)
- end
-
- private
-
- # encapsulates the event name broadcast to all subscribers
- def notification_event_for(name)
- "setting.#{name}.changed"
- end
-
- # the notifier to delegate to
- def notifier
- OpenProject::Notifications
- end
- end
-end
diff --git a/spec/models/setting_spec.rb b/spec/models/setting_spec.rb
index 596af9026a1..880e2187c99 100644
--- a/spec/models/setting_spec.rb
+++ b/spec/models/setting_spec.rb
@@ -455,68 +455,6 @@ describe Setting do
end
end
- # tests stuff regarding settings callbacks
- describe 'callbacks' do
- # collects data for the dummy callback
- let(:collector) { [] }
-
- # a dummy callback that collects data
- let(:callback) { lambda { |args| collector << args[:value] } }
-
- # registers the dummy callback
- before do
- described_class.register_callback(:default_projects_modules, &callback)
- end
-
- it 'calls a callback when a setting is set' do
- described_class.default_projects_modules = [:some_value]
- expect(collector).not_to be_empty
- end
-
- it 'calls no callback on invalid setting' do
- allow_any_instance_of(Setting).to receive(:valid?).and_return(false)
- described_class.default_projects_modules = 'invalid'
- expect(collector).to be_empty
- end
-
- it 'calls multiple callbacks when a setting is set' do
- described_class.register_callback(:default_projects_modules, &callback)
- described_class.default_projects_modules = [:some_value]
- expect(collector.size).to eq 2
- end
-
- it 'calls callbacks every time a setting is set' do
- described_class.default_projects_modules = [:some_value]
- described_class.default_projects_modules = [:some_value]
- expect(collector.size).to eq 2
- end
-
- it 'calls only the callbacks belonging to the changed setting' do
- described_class.register_callback(:host_name, &callback)
- described_class.default_projects_modules = [:some_value]
- expect(collector.size).to eq 1
- end
-
- it 'attaches to the right setting by passing a string' do
- described_class.register_callback('app_title', &callback)
- described_class.app_title = 'some title'
- expect(collector).not_to be_empty
- end
-
- it 'passes the new setting value to the callback' do
- described_class.default_projects_modules = [:some_value]
- expect(collector).to include [:some_value]
- end
-
- it 'optionally passes the old setting value to the callback as the second argument' do
- described_class.host_name = 'some name' # set old value
- cb = lambda { |args| collector << args[:old_value] }
- described_class.register_callback(:host_name, &cb)
- described_class.host_name = 'some other name'
- expect(collector).to include 'some name'
- end
- end
-
describe '.reload_mailer_settings!' do
before do
allow(ActionMailer::Base)