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

refactor: use keyword arg for send_notifications

Christophe Bliard31725683a66d
diff --git a/app/services/base_services/base_contracted.rb b/app/services/base_services/base_contracted.rb
index 362edc9c1fb..59e61d991c4 100644
--- a/app/services/base_services/base_contracted.rb
+++ b/app/services/base_services/base_contracted.rb
@@ -51,7 +51,7 @@ module BaseServices
# this service is running in
# e.g., within a resource lock or just executing as the given user
def service_context(send_notifications: true, &block)
- in_context(model, send_notifications, &block)
+ in_context(model, send_notifications:, &block)
end
def perform(params = {})
diff --git a/app/services/base_services/copy.rb b/app/services/base_services/copy.rb
index edf0f3db8a8..cb37d14c4e1 100644
--- a/app/services/base_services/copy.rb
+++ b/app/services/base_services/copy.rb
@@ -93,8 +93,8 @@ module BaseServices
##
# Disabling sending regular notifications
- def service_context(*_args, &)
- in_context(model, false, &)
+ def service_context(*, &)
+ in_context(model, send_notifications: false, &)
end
##
diff --git a/app/services/base_services/create.rb b/app/services/base_services/create.rb
index 2d84cae76d3..b306e51d1b6 100644
--- a/app/services/base_services/create.rb
+++ b/app/services/base_services/create.rb
@@ -31,7 +31,7 @@ module BaseServices
protected
def service_context(send_notifications: true, &block)
- in_user_context(send_notifications, &block)
+ in_user_context(send_notifications:, &block)
end
def instance(_params)
diff --git a/app/services/relations/create_service.rb b/app/services/relations/create_service.rb
index a20fb2ef050..9c9b5fe0c23 100644
--- a/app/services/relations/create_service.rb
+++ b/app/services/relations/create_service.rb
@@ -28,12 +28,12 @@
class Relations::CreateService < Relations::BaseService
def initialize(user:)
- @user = user
+ super
self.contract_class = Relations::CreateContract
end
def perform(send_notifications: true, **attributes)
- in_user_context(send_notifications) do
+ in_user_context(send_notifications:) do
update_relation ::Relation.new, attributes
end
end
diff --git a/app/services/relations/update_service.rb b/app/services/relations/update_service.rb
index dbf6b3b8b47..50ae88716c4 100644
--- a/app/services/relations/update_service.rb
+++ b/app/services/relations/update_service.rb
@@ -36,7 +36,7 @@ class Relations::UpdateService < Relations::BaseService
end
def perform(attributes)
- in_context(attributes[:send_notifications]) do
+ in_user_context(send_notifications: attributes[:send_notifications]) do
update_relation model, attributes
end
end
diff --git a/app/services/shared/service_context.rb b/app/services/shared/service_context.rb
index b2bf4308ead..a68325fd901 100644
--- a/app/services/shared/service_context.rb
+++ b/app/services/shared/service_context.rb
@@ -30,19 +30,19 @@ module Shared
module ServiceContext
private
- def in_context(model, send_notifications = true, &)
+ def in_context(model, send_notifications: true, &)
if model
- in_mutex_context(model, send_notifications, &)
+ in_mutex_context(model, send_notifications:, &)
else
- in_user_context(send_notifications, &)
+ in_user_context(send_notifications:, &)
end
end
- def in_mutex_context(model, send_notifications = true, &)
+ def in_mutex_context(model, send_notifications: true, &)
result = nil
OpenProject::Mutex.with_advisory_lock_transaction(model) do
- result = without_context_transaction(send_notifications, &)
+ result = without_context_transaction(send_notifications:, &)
raise ActiveRecord::Rollback if result.failure?
end
@@ -50,11 +50,11 @@ module Shared
result
end
- def in_user_context(send_notifications = true, &)
+ def in_user_context(send_notifications: true, &)
result = nil
ActiveRecord::Base.transaction do
- result = without_context_transaction(send_notifications, &)
+ result = without_context_transaction(send_notifications:, &)
raise ActiveRecord::Rollback if result.failure?
end
@@ -62,7 +62,7 @@ module Shared
result
end
- def without_context_transaction(send_notifications, &)
+ def without_context_transaction(send_notifications:, &)
User.execute_as user do
Journal::NotificationConfiguration.with(send_notifications, &)
end
diff --git a/app/services/wiki_pages/copy_service.rb b/app/services/wiki_pages/copy_service.rb
index ff299aa3bfd..53f35130962 100644
--- a/app/services/wiki_pages/copy_service.rb
+++ b/app/services/wiki_pages/copy_service.rb
@@ -42,7 +42,7 @@ class WikiPages::CopyService
end
def call(send_notifications: true, copy_attachments: true, **attributes)
- in_context(model, send_notifications) do
+ in_context(model, send_notifications:) do
copy(attributes, copy_attachments)
end
end
diff --git a/app/services/work_packages/bulk/bulked_service.rb b/app/services/work_packages/bulk/bulked_service.rb
index c639f0f8176..225cbc3bcdd 100644
--- a/app/services/work_packages/bulk/bulked_service.rb
+++ b/app/services/work_packages/bulk/bulked_service.rb
@@ -43,7 +43,8 @@ module WorkPackages
# This is not an all or nothing service. We currently accept that
# one work package might be moved while another one fails.
# Personally, I'd rather wrap it in a transaction.
- without_context_transaction(params[:send_notification] == '1') do
+ send_notifications = params[:send_notification] == '1'
+ without_context_transaction(send_notifications:) do
bulk(params)
end
end
diff --git a/app/services/work_packages/copy_service.rb b/app/services/work_packages/copy_service.rb
index 54bf4117995..8fe83319a1d 100644
--- a/app/services/work_packages/copy_service.rb
+++ b/app/services/work_packages/copy_service.rb
@@ -42,7 +42,7 @@ class WorkPackages::CopyService
end
def call(send_notifications: true, copy_attachments: true, **attributes)
- in_context(work_package, send_notifications) do
+ in_context(work_package, send_notifications:) do
copy(attributes, copy_attachments, send_notifications)
end
end
diff --git a/app/services/work_packages/create_service.rb b/app/services/work_packages/create_service.rb
index ef5650b73d9..2658710d8fd 100644
--- a/app/services/work_packages/create_service.rb
+++ b/app/services/work_packages/create_service.rb
@@ -41,7 +41,7 @@ class WorkPackages::CreateService < BaseServices::BaseCallable
def perform(work_package: WorkPackage.new,
send_notifications: true,
**attributes)
- in_user_context(send_notifications) do
+ in_user_context(send_notifications:) do
create(attributes, work_package)
end
end
diff --git a/spec/services/shared/service_context_integration_spec.rb b/spec/services/shared/service_context_integration_spec.rb
index a434b6c4cb6..3127af96ee5 100644
--- a/spec/services/shared/service_context_integration_spec.rb
+++ b/spec/services/shared/service_context_integration_spec.rb
@@ -42,7 +42,7 @@ describe Shared::ServiceContext, 'integration', type: :model do
end
def test_method_failure(model)
- in_context model, true do
+ in_context model do
Setting.connection.execute <<~SQL
INSERT INTO settings (name, value)
VALUES ('test_setting', 'abc')
@@ -53,7 +53,7 @@ describe Shared::ServiceContext, 'integration', type: :model do
end
def test_method_success(model)
- in_context model, true do
+ in_context model do
Setting.connection.execute <<~SQL
INSERT INTO settings (name, value)
VALUES ('test_setting', 'abc')