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
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.rbindex 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 userdef service_context(send_notifications: true, &block)- in_context(model, send_notifications, &block)+ in_context(model, send_notifications:, &block)enddef perform(params = {})diff --git a/app/services/base_services/copy.rb b/app/services/base_services/copy.rbindex 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.rbindex 2d84cae76d3..b306e51d1b6 100644--- a/app/services/base_services/create.rb+++ b/app/services/base_services/create.rb@@ -31,7 +31,7 @@ module BaseServicesprotecteddef service_context(send_notifications: true, &block)- in_user_context(send_notifications, &block)+ in_user_context(send_notifications:, &block)enddef instance(_params)diff --git a/app/services/relations/create_service.rb b/app/services/relations/create_service.rbindex 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::BaseServicedef initialize(user:)- @user = user+ superself.contract_class = Relations::CreateContractenddef perform(send_notifications: true, **attributes)- in_user_context(send_notifications) do+ in_user_context(send_notifications:) doupdate_relation ::Relation.new, attributesendenddiff --git a/app/services/relations/update_service.rb b/app/services/relations/update_service.rbindex 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::BaseServiceenddef perform(attributes)- in_context(attributes[:send_notifications]) do+ in_user_context(send_notifications: attributes[:send_notifications]) doupdate_relation model, attributesendenddiff --git a/app/services/shared/service_context.rb b/app/services/shared/service_context.rbindex b2bf4308ead..a68325fd901 100644--- a/app/services/shared/service_context.rb+++ b/app/services/shared/service_context.rb@@ -30,19 +30,19 @@ module Sharedmodule ServiceContextprivate- 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:, &)endend- def in_mutex_context(model, send_notifications = true, &)+ def in_mutex_context(model, send_notifications: true, &)result = nilOpenProject::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 Sharedresultend- def in_user_context(send_notifications = true, &)+ def in_user_context(send_notifications: true, &)result = nilActiveRecord::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 Sharedresultend- def without_context_transaction(send_notifications, &)+ def without_context_transaction(send_notifications:, &)User.execute_as user doJournal::NotificationConfiguration.with(send_notifications, &)enddiff --git a/app/services/wiki_pages/copy_service.rb b/app/services/wiki_pages/copy_service.rbindex 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::CopyServiceenddef call(send_notifications: true, copy_attachments: true, **attributes)- in_context(model, send_notifications) do+ in_context(model, send_notifications:) docopy(attributes, copy_attachments)endenddiff --git a/app/services/work_packages/bulk/bulked_service.rb b/app/services/work_packages/bulk/bulked_service.rbindex 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:) dobulk(params)endenddiff --git a/app/services/work_packages/copy_service.rb b/app/services/work_packages/copy_service.rbindex 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::CopyServiceenddef call(send_notifications: true, copy_attachments: true, **attributes)- in_context(work_package, send_notifications) do+ in_context(work_package, send_notifications:) docopy(attributes, copy_attachments, send_notifications)endenddiff --git a/app/services/work_packages/create_service.rb b/app/services/work_packages/create_service.rbindex 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::BaseCallabledef perform(work_package: WorkPackage.new,send_notifications: true,**attributes)- in_user_context(send_notifications) do+ in_user_context(send_notifications:) docreate(attributes, work_package)endenddiff --git a/spec/services/shared/service_context_integration_spec.rb b/spec/services/shared/service_context_integration_spec.rbindex 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 doenddef test_method_failure(model)- in_context model, true do+ in_context model doSetting.connection.execute <<~SQLINSERT INTO settings (name, value)VALUES ('test_setting', 'abc')@@ -53,7 +53,7 @@ describe Shared::ServiceContext, 'integration', type: :model doenddef test_method_success(model)- in_context model, true do+ in_context model doSetting.connection.execute <<~SQLINSERT INTO settings (name, value)VALUES ('test_setting', 'abc')