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
skip validating automatically calculated values
ulferts8868186415ae
diff --git a/app/contracts/work_packages/update_dependent_contract.rb b/app/contracts/work_packages/update_dependent_contract.rbnew file mode 100644index 00000000000..f18fbf18ec1--- /dev/null+++ b/app/contracts/work_packages/update_dependent_contract.rb@@ -0,0 +1,36 @@+# OpenProject is an open source project management software.+# Copyright (C) 2010-2022 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.++# Disables all validations but still allows to be queried for assignable_* (e.g. statuses)+# that are necessary whenever a dependent (e.g. descendant of a work package) is moved to a project+# where the type is switched.+module WorkPackages+ class UpdateDependentContract < UpdateContract+ def validate+ true+ end+ end+enddiff --git a/app/services/base_services/base_contracted.rb b/app/services/base_services/base_contracted.rbindex f671b42ecbd..390df28969f 100644--- a/app/services/base_services/base_contracted.rb+++ b/app/services/base_services/base_contracted.rb@@ -50,12 +50,12 @@ module BaseServices# Determine the type of context# this service is running in# e.g., within a resource lock or just executing as the given user- def service_context(&)- in_context(model, true, &)+ def service_context(send_notifications: true, &block)+ in_context(model, send_notifications, &block)enddef perform(params = {})- service_context do+ service_context(send_notifications: (params || {}).fetch(:send_notifications, true)) doservice_call = validate_params(params)service_call = before_perform(params, service_call) if service_call.success?service_call = validate_contract(service_call) if service_call.success?diff --git a/app/services/base_services/copy.rb b/app/services/base_services/copy.rbindex e98aa0b7faf..0cc3cf5b5e1 100644--- a/app/services/base_services/copy.rb+++ b/app/services/base_services/copy.rb@@ -94,7 +94,7 @@ module BaseServices### Disabling sending regular notifications- def service_context(&)+ def service_context(*_args, &)in_context(model, false, &)enddiff --git a/app/services/base_services/create.rb b/app/services/base_services/create.rbindex 6b52e4d96b4..5154536913f 100644--- a/app/services/base_services/create.rb+++ b/app/services/base_services/create.rb@@ -30,8 +30,8 @@ module BaseServicesclass Create < Writeprotected- def service_context(&)- in_user_context(true, &)+ def service_context(send_notifications: true, &block)+ in_user_context(send_notifications, &block)enddef instance(_params)diff --git a/app/services/journals/create_service.rb b/app/services/journals/create_service.rbindex 10c292de88e..fd792c3bdad 100644--- a/app/services/journals/create_service.rb+++ b/app/services/journals/create_service.rb@@ -54,9 +54,6 @@ module Journalsreturn ServiceResult.new success: true unless journaldestroy_predecessor(journal)-- journal-reload_journalstouch_journable(journal)diff --git a/app/services/relations/base_service.rb b/app/services/relations/base_service.rbindex 23f1dcf080e..e42f5db1a0d 100644--- a/app/services/relations/base_service.rb+++ b/app/services/relations/base_service.rb@@ -70,7 +70,7 @@ class Relations::BaseService < ::BaseServices::BaseCallable# The to-work_package will not be altered by the schedule service so# we do not have to save the result of the service.save_result = if schedule_result.success?- schedule_result.dependent_results.all? { |dr| !dr.result.changed? || dr.result.save }+ schedule_result.dependent_results.all? { |dr| !dr.result.changed? || dr.result.save(validate: false) }end || falseschedule_result.success = save_resultdiff --git a/app/services/work_packages/update_service.rb b/app/services/work_packages/update_service.rbindex 33ef46869f3..ce1a947b6b2 100644--- a/app/services/work_packages/update_service.rb+++ b/app/services/work_packages/update_service.rb@@ -71,7 +71,7 @@ class WorkPackages::UpdateService < ::BaseServices::UpdateWorkPackages::SetAttributesService.new(user:,model: descendant,- contract_class: EmptyContract)+ contract_class: WorkPackages::UpdateDependentContract).call(attributes)enddiff --git a/modules/backlogs/lib/open_project/backlogs/list.rb b/modules/backlogs/lib/open_project/backlogs/list.rbindex 9b07e1aa6d0..c38edb717c6 100644--- a/modules/backlogs/lib/open_project/backlogs/list.rb+++ b/modules/backlogs/lib/open_project/backlogs/list.rb@@ -83,9 +83,11 @@ module OpenProject::Backlogs::List# Overwriting acts/list to avoid it calling save.# Calling save will remove the changes/saved_changes information.+ # rubocop:disable Style/OptionalBooleanParameterdef set_list_position(new_position, _raise_exception_if_save_fails = false)update_columns(position: new_position)end+ # rubocop:enable Style/OptionalBooleanParameterdef fix_other_work_package_positionsif changes.slice('project_id', 'type_id', 'version_id').present?diff --git a/spec/requests/api/v3/work_packages/dependent_errors_spec.rb b/spec/requests/api/v3/work_packages/dependent_errors_spec.rbdeleted file mode 100644index 19cabf4492c..00000000000--- a/spec/requests/api/v3/work_packages/dependent_errors_spec.rb+++ /dev/null@@ -1,198 +0,0 @@-#-- copyright-# OpenProject is an open source project management software.-# Copyright (C) 2012-2022 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.-#++--require 'spec_helper'-require 'rack/test'--describe 'API v3 Work package resource', type: :request, content_type: :json do- include Rack::Test::Methods- include Capybara::RSpecMatchers- include API::V3::Utilities::PathHelper-- let(:work_package) do- create(- :work_package,- project_id: project.id,- parent:,- subject: "Updated WorkPackage"- )- end-- let!(:parent) do- create(:work_package, project_id: project.id, type:, subject: "Invalid Dependent WorkPackage").tap do |parent|- parent.custom_values.create custom_field: custom_field, value: custom_field.possible_values.first.id-- cv = parent.custom_values.last- cv.update_column :value, "0"- end- end-- let(:project) do- create(:project, identifier: 'deperr', public: false).tap do |project|- project.types << type- end- end-- let(:type) do- create(:type).tap do |type|- type.custom_fields << custom_field- end- end-- let(:status) { create :status }-- let(:custom_field) do- create(- :list_wp_custom_field,- name: "Gate",- possible_values: %w(A B C),- is_required: true- )- end-- let(:role) { create(:role, permissions:) }- let(:permissions) { %i[view_work_packages edit_work_packages create_work_packages] }-- let(:current_user) do- create(:user, member_in_project: project, member_through_role: role)- end-- let(:dependent_error_result) do- proc do |instance, _attributes, work_package|- result = ServiceResult.new(success: true, result: (instance.respond_to?(:model) && instance.model) || work_package)- dep = parent- dep.errors.add :base, "invalid", message: "invalid"-- result.add_dependent!(ServiceResult.new(success: false, errors: dep.errors, result: dep))-- result- end- end-- before do- login_as current_user- end-- describe '#patch' do- let(:path) { api_v3_paths.work_package work_package.id }- let(:valid_params) do- {- _type: 'WorkPackage',- lockVersion: work_package.lock_version- }- end-- subject(:response) { last_response }-- shared_context 'patch request' do- before do- patch path, params.to_json, 'CONTENT_TYPE' => 'application/json'- end- end-- before do- allow_any_instance_of(WorkPackages::UpdateService).to receive(:update_dependent, &dependent_error_result)- end-- context 'attribute' do- let(:params) { valid_params.merge(startDate: "2018-05-23") }-- include_context 'patch request'-- it { expect(response.status).to eq(422) }-- it 'responds with an error' do- expected_error = {- _type: "Error",- errorIdentifier: "urn:openproject-org:api:v3:errors:PropertyConstraintViolation",- message: "Error attempting to alter dependent object: Work package ##{parent.id} - #{parent.subject}: invalid",- _embedded: {- details: {- attribute: "base"- }- }- }-- expect(subject.body).to be_json_eql(expected_error.to_json)- end- end- end-- describe '#post' do- let(:current_user) { create :admin }-- let(:path) { api_v3_paths.work_packages }- let(:valid_params) do- {- _type: 'WorkPackage',- lockVersion: 0,- _links: {- author: { href: "/api/v3/users/#{current_user.id}" },- project: { href: "/api/v3/projects/#{project.id}" },- status: { href: "/api/v3/statuses/#{status.id}" },- priority: { href: "/api/v3/priorities/#{work_package.priority.id}" }- }- }- end-- subject(:response) { last_response }-- shared_context 'post request' do- before do- post path, params.to_json, 'CONTENT_TYPE' => 'application/json'- end- end-- before do- allow_any_instance_of(WorkPackages::CreateService).to receive(:create, &dependent_error_result)- end-- context 'request' do- let(:params) { valid_params.merge(subject: "Test Subject") }-- include_context 'post request'-- it { expect(response.status).to eq(422) }-- it 'responds with an error' do- expected_error = {- _type: "Error",- errorIdentifier: "urn:openproject-org:api:v3:errors:PropertyConstraintViolation",- message: "Error attempting to alter dependent object: Work package ##{parent.id} - #{parent.subject}: invalid",- _embedded: {- details: {- attribute: "base"- }- }- }-- expect(subject.body).to be_json_eql(expected_error.to_json)- end- end- end-end