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
use standard interface for relation create service
ulferts8d72897f62ee
diff --git a/app/services/relations/create_service.rb b/app/services/relations/create_service.rbindex 958a5acd9c1..e160fc3042f 100644--- a/app/services/relations/create_service.rb+++ b/app/services/relations/create_service.rb@@ -34,9 +34,9 @@ class Relations::CreateService < Relations::BaseServiceself.contract_class = Relations::CreateContractend- def perform(relation, send_notifications: true)+ def perform(send_notifications: true, **attributes)in_user_context(send_notifications) do- update_relation relation, {}+ update_relation ::Relation.new, attributesendendenddiff --git a/lib/api/v3/work_packages/work_package_relations_api.rb b/lib/api/v3/work_packages/work_package_relations_api.rbindex c422c0f292e..7b318a1a1fc 100644--- a/lib/api/v3/work_packages/work_package_relations_api.rb+++ b/lib/api/v3/work_packages/work_package_relations_api.rb@@ -52,18 +52,12 @@ module API)end- post do- rep = parse_representer.new Relation.new, current_user: current_user- relation = rep.from_json request.body.read- service = ::Relations::CreateService.new user: current_user- call = service.call relation, send_notifications: (params[:notify] != 'false')-- if call.success?- representer.new call.result, current_user: current_user, embed_links: true- else- fail ::API::Errors::ErrorBase.create_and_merge_errors(call.all_errors.reject(&:empty?).first)- end- end+ post &::API::V3::Utilities::Endpoints::Create+ .new(model: Relation,+ params_modifier: ->(params) do+ params.merge(send_notifications: (params[:notify] != 'false'))+ end)+ .mountendendenddiff --git a/spec/services/relations/create_service_spec.rb b/spec/services/relations/create_service_spec.rbindex 306650e16e5..28738e73a0d 100644--- a/spec/services/relations/create_service_spec.rb+++ b/spec/services/relations/create_service_spec.rb@@ -30,6 +30,7 @@require 'spec_helper'+# rubocop:disable RSpec:MultipleMemoizedHelpersdescribe Relations::CreateService dolet(:work_package1_start_date) { nil }let(:work_package1_due_date) { Date.today }@@ -76,10 +77,14 @@ describe Relations::CreateService dolet(:symbols_for_base) { [] }subject do- instance.call(relation)+ instance.call(attributes)endbefore do+ allow(Relation)+ .to receive(:new)+ .and_return(relation)+allow(relation).to receive(:save).and_return(model_valid)@@ -238,7 +243,7 @@ describe Relations::CreateService doendend- context 'fro a different relationship' do+ context 'for a different relationship' dolet(:attributes) do{to: work_package1,@@ -264,3 +269,4 @@ describe Relations::CreateService doendendend+# rubocop:enable RSpec:MultipleMemoizedHelpers