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

use WorkPackages::UpdateService to update work packages via changeset

ulferts60f2c7433d86
diff --git a/app/models/changeset.rb b/app/models/changeset.rb
index 648a90179ab..968f48402f1 100644
--- a/app/models/changeset.rb
+++ b/app/models/changeset.rb
@@ -231,15 +231,18 @@ class Changeset < ApplicationRecord
# don't change the status if the work package is closed
return if work_package.status && work_package.status.is_closed?
- journal_notes = I18n.t(:text_status_changed_by_changeset, value: text_tag, locale: Setting.default_language)
- work_package.add_journal(user: user || User.anonymous, notes: journal_notes)
- work_package.status = status
- if Setting.commit_fix_done_ratio.present?
- work_package.done_ratio = Setting.commit_fix_done_ratio.to_i
- end
- OpenProject::Hook.call_hook(:model_changeset_scan_commit_for_issue_ids_pre_issue_update,
- changeset: self, issue: work_package)
- if !work_package.save(validate: false) && logger
+ call = WorkPackages::UpdateService
+ .new(model: work_package,
+ user: user || User.anonymous)
+ .call(status:,
+ journal_notes: I18n.t(:text_status_changed_by_changeset,
+ value: text_tag,
+ locale: Setting.default_language))
+
+ # TODO: update changelog to state removal of
+ # :model_changeset_scan_commit_for_issue_ids_pre_issue_update
+ # and also of the setting commit_fix_done_ratio
+ if call.errors.any? && logger.present?
logger.warn("Work package ##{work_package.id} could not be saved by changeset #{id}: #{work_package.errors.full_messages}")
end
diff --git a/app/views/admin/settings/repositories_settings/show.html.erb b/app/views/admin/settings/repositories_settings/show.html.erb
index ae0b5f90747..7e7468ffd42 100644
--- a/app/views/admin/settings/repositories_settings/show.html.erb
+++ b/app/views/admin/settings/repositories_settings/show.html.erb
@@ -118,12 +118,6 @@ See COPYRIGHT and LICENSE files for more details.
<%= setting_select :commit_fix_status_id, [["--- #{t(:actionview_instancetag_blank_option)} ---", '0', { disabled: true }]] + Status.all.collect{ |status| [status.name, status.id.to_s] }, label: false %>
</div>
</div>
- <div class="form--field -vertical">
- <%= styled_label_tag :settings_commit_fix_done_ratio, WorkPackage.human_attribute_name(:done_ratio) %>
- <div class="form--field-container">
- <%= setting_select :commit_fix_done_ratio, (0..10).to_a.collect {|r| ["#{r*10} %", "#{r*10}"] }, blank: :label_no_change_option, label: false %>
- </div>
- </div>
</div>
</div>
<div class="form--field">
diff --git a/config/constants/settings/definition.rb b/config/constants/settings/definition.rb
index 1e52d2d96ed..3777da14c0d 100644
--- a/config/constants/settings/definition.rb
+++ b/config/constants/settings/definition.rb
@@ -230,10 +230,6 @@ module Settings
default: nil,
writable: false
},
- commit_fix_done_ratio: {
- description: "Progress to apply when commit fixes work package",
- default: 100
- },
commit_fix_keywords: {
description: "Keywords to look for in commit for fixing work packages",
default: "fixes,closes"
diff --git a/docs/release-notes/14-0-0/README.md b/docs/release-notes/14-0-0/README.md
index b95a1b42666..18f167ed8de 100644
--- a/docs/release-notes/14-0-0/README.md
+++ b/docs/release-notes/14-0-0/README.md
@@ -22,6 +22,18 @@ This change is to align the API with the terminology used in project management
For more information, see [#44054](https://community.openproject.org/work_packages/44054)
+### Removal of the model_changeset_scan_commit_for_issue_ids_pre_issue_update hook
+
+The `model_changeset_scan_commit_for_issue_ids_pre_issue_update` hook has been removed completely. This was made necessary as the code around it was not making use of the proper update mechanisms (Service objects) which lead to inconsistencies in the data, i.e. ancestor work packages.
+
+For more information, see [#40749](https://community.openproject.org/work_packages/40749)
+
+### Removal of the commit_fix_done_ratio setting
+
+Since the now a read only value, derived from work and remaining work, the `commit_fix_done_ratio` setting has been removed as setting the done_ratio value is no longer possible.
+
+For more information, see [#40749](https://community.openproject.org/work_packages/40749)
+
<!--more-->
## Bug fixes and changes
diff --git a/spec/models/changeset_spec.rb b/spec/models/changeset_spec.rb
index b5b51ae5171..46365cdf24c 100644
--- a/spec/models/changeset_spec.rb
+++ b/spec/models/changeset_spec.rb
@@ -129,23 +129,38 @@ RSpec.describe Changeset do
describe "#scan_comment_for_work_package_ids",
with_settings: {
- commit_fix_done_ratio: "90",
commit_ref_keywords: "refs , references, IssueID",
commit_fix_keywords: "fixes , closes",
- default_language: "en"
+ default_language: "en",
+ work_package_done_ratio: "status"
} do
- let!(:user) { create(:admin, login: "dlopper") }
+ let!(:user) do
+ create(:admin,
+ login: "dlopper",
+ member_with_roles: { repository.project => role })
+ end
let!(:open_status) { create(:status) }
- let!(:closed_status) { create(:closed_status) }
+ let!(:closed_status) { create(:closed_status, default_done_ratio: 90) }
+ let!(:role) { create(:project_role, permissions: %i[view_work_packages edit_work_packages]) }
let!(:other_work_package) { create(:work_package, status: open_status) }
+ let!(:parent_work_package) { create(:work_package, subject: "Parent wp") }
+ let!(:workflow) do
+ create(:workflow,
+ old_status: open_status,
+ new_status: closed_status,
+ role:,
+ type: work_package.type)
+ end
let(:comments) { "Some fix made, fixes ##{work_package.id} and fixes ##{other_work_package.id}" }
with_virtual_subversion_repository do
let!(:work_package) do
create(:work_package,
project: repository.project,
- status: open_status)
+ status: open_status,
+ parent: parent_work_package,
+ estimated_hours: 100)
end
let(:changeset) do
create(:changeset,
@@ -291,8 +306,9 @@ RSpec.describe Changeset do
expect(work_package.status).to eq closed_status
expect(work_package.done_ratio).to eq 90
+ expect(work_package.remaining_hours).to eq 10
- # issue change
+ # journal updates
journal = work_package.journals.last
expect(journal.user).to eq user
@@ -302,6 +318,13 @@ RSpec.describe Changeset do
# due to other project
other_work_package.reload
expect(other_work_package.changesets).to eq []
+
+ # Expect the parent to be updated
+ parent_work_package.reload
+
+ expect(parent_work_package.done_ratio).to eq 0
+ expect(parent_work_package.derived_remaining_hours).to eq 10
+ expect(parent_work_package.derived_done_ratio).to eq 90
end
describe "with work package in parent project" do