Merge pull request #23325 from opf/bug/74927-unable-to-change-a-parent-on-bulk-edit-of-work-packages-with-semantic-id

[#74927] Unable to change a parent on bulk edit of work packages with semantic ID
This commit is contained in:
Tom Hykel
2026-06-03 13:39:06 +02:00
committed by GitHub
2 changed files with 47 additions and 0 deletions
@@ -130,9 +130,20 @@ class WorkPackages::BulkController < ApplicationController
attributes = permitted_params.update_work_package
attributes[:custom_field_values] = transform_attributes(attributes[:custom_field_values])
attributes = attributes_with_normalized_parent_id(attributes)
transform_attributes(attributes)
end
def attributes_with_normalized_parent_id(attributes)
raw = attributes[:parent_id]
return attributes unless WorkPackage::SemanticIdentifier.semantic_id?(raw.to_s)
wp = WorkPackage.find_by_display_id(raw)
# If the semantic ID hasn't resolved to a proper package, default to 0, which is an invalid value
# that will trigger errors in the main update service
attributes.merge(parent_id: wp ? wp.id : 0)
end
def user
current_user
end
@@ -681,6 +681,42 @@ RSpec.describe WorkPackages::BulkController, with_settings: { journal_aggregatio
expect(new_parent.due_date).to eq(task2.due_date)
end
end
describe "bulk parent assignment with semantic identifiers",
with_settings: { work_packages_identifier: "semantic" } do
let(:sem_project) do
create(:project, identifier: "SEMPROJ", types: [type]).tap do |p|
create(:member, project: p, principal: user, roles: [role])
end
end
let(:parent_wp) { create(:work_package, project: sem_project).reload }
let(:child1) { create(:work_package, project: sem_project).reload }
let(:child2) { create(:work_package, project: sem_project).reload }
it "accepts a semantic identifier and assigns the parent" do
put :update,
params: {
ids: [child1.id, child2.id],
work_package: { parent_id: parent_wp.identifier }
}
expect(response).to have_http_status(:found)
expect(child1.reload.parent_id).to eq(parent_wp.id)
expect(child2.reload.parent_id).to eq(parent_wp.id)
end
it "reports an error for an unknown semantic identifier" do
put :update,
params: {
ids: [child1.id, child2.id],
work_package: { parent_id: "SEMPROJ-9999" }
}
expect(flash[:error]).to be_present
expect(child1.reload.parent_id).to be_nil
expect(child2.reload.parent_id).to be_nil
end
end
end
describe "#destroy" do