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

Indicate WP subject as non-writable when generated

Jan Sandbrinkefa3f1846f02
diff --git a/lib/api/v3/work_packages/schema/base_work_package_schema.rb b/lib/api/v3/work_packages/schema/base_work_package_schema.rb
index d7b8bbb692d..fa181776205 100644
--- a/lib/api/v3/work_packages/schema/base_work_package_schema.rb
+++ b/lib/api/v3/work_packages/schema/base_work_package_schema.rb
@@ -53,6 +53,7 @@ module API
def writable?(property)
property = property.to_s
+ return false if property == "subject" && type&.replacement_pattern_defined_for?(:subject)
# Special case for milestones + date property
property = "start_date" if property == "date" && milestone?
diff --git a/spec/lib/api/v3/work_packages/schema/specific_work_package_schema_spec.rb b/spec/lib/api/v3/work_packages/schema/specific_work_package_schema_spec.rb
index 92c2c88a88c..d429d80fa30 100644
--- a/spec/lib/api/v3/work_packages/schema/specific_work_package_schema_spec.rb
+++ b/spec/lib/api/v3/work_packages/schema/specific_work_package_schema_spec.rb
@@ -299,6 +299,16 @@ RSpec.describe API::V3::WorkPackages::Schema::SpecificWorkPackageSchema do
expect(subject).to be_writable(:priority)
end
end
+
+ describe "subject" do
+ it { is_expected.to be_writable(:subject) }
+
+ context "when the type has automatic subject generation enabled" do
+ let(:type) { build_stubbed(:type, patterns: { subject: { blueprint: "Hello world", enabled: true } }) }
+
+ it { is_expected.not_to be_writable(:subject) }
+ end
+ end
end
describe "#assignable_custom_field_values" do
diff --git a/spec/lib/api/v3/work_packages/schema/typed_work_package_schema_spec.rb b/spec/lib/api/v3/work_packages/schema/typed_work_package_schema_spec.rb
index 41affd8de2b..cd0cf54566a 100644
--- a/spec/lib/api/v3/work_packages/schema/typed_work_package_schema_spec.rb
+++ b/spec/lib/api/v3/work_packages/schema/typed_work_package_schema_spec.rb
@@ -83,6 +83,18 @@ RSpec.describe API::V3::WorkPackages::Schema::TypedWorkPackageSchema do
it "finish date is writable" do
expect(subject).to be_writable(:due_date)
end
+
+ it "subject is writable" do
+ expect(subject).to be_writable(:subject)
+ end
+
+ context "when the type has automatic subject generation enabled" do
+ let(:type) { create(:type, patterns: { subject: { blueprint: "Hello world", enabled: true } }) }
+
+ it "subject is not writable" do
+ expect(subject).not_to be_writable(:subject)
+ end
+ end
end
describe "#milestone?" do