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
Do not expose updatedAt changing for admins in work packages
Oliver Günther6e3000700e30
diff --git a/app/contracts/work_packages/create_contract.rb b/app/contracts/work_packages/create_contract.rbindex e8086638b26..9c8c735e7ad 100644--- a/app/contracts/work_packages/create_contract.rb+++ b/app/contracts/work_packages/create_contract.rb@@ -31,7 +31,7 @@ require "work_packages/base_contract"module WorkPackagesclass CreateContract < BaseContractinclude AdminWritableTimestamps- allow_writable_timestamps+ allow_writable_timestamps :created_atattribute :author_id,writable: -> { default_attributes_admin_writable? }diff --git a/config/locales/en.yml b/config/locales/en.ymlindex d0a8ec18b76..94721a3df2f 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -2900,7 +2900,7 @@ Project attributes and sections are defined in the <a href=%{admin_settings_url}setting_apiv3_write_readonly_attributes: "Write access to read-only attributes"setting_apiv3_write_readonly_attributes_instructions_html: >If enabled, the API will allow administrators to write static read-only attributes during creation,- such as createdAt and updatedAt timestamps.+ such as createdAt and author.<br/><strong>Warning:</strong> This setting has a use-case for e.g., importing data, but allowsadministrators to impersonate the creation of items as other users. All creation requests are beingdiff --git a/docs/api/apiv3/components/schemas/work_package_model.yml b/docs/api/apiv3/components/schemas/work_package_model.ymlindex 0f364c55fb4..e6fdbe4f794 100644--- a/docs/api/apiv3/components/schemas/work_package_model.yml+++ b/docs/api/apiv3/components/schemas/work_package_model.yml@@ -109,7 +109,7 @@ properties:updatedAt:type: stringformat: date-time- description: Time of the most recent change to the work package. Can be writable by admins with the `apiv3_write_readonly_attributes` setting enabled.+ description: Time of the most recent change to the work package.readOnly: true_links:type: objectdiff --git a/spec/contracts/work_packages/create_contract_spec.rb b/spec/contracts/work_packages/create_contract_spec.rbindex 810bca17a33..4820e03b582 100644--- a/spec/contracts/work_packages/create_contract_spec.rb+++ b/spec/contracts/work_packages/create_contract_spec.rb@@ -161,7 +161,7 @@ RSpec.describe WorkPackages::CreateContract dolet(:user) { build_stubbed(:admin) }it_behaves_like "can write", :created_at, 1.day.ago- it_behaves_like "can write", :updated_at, 1.day.ago+ it_behaves_like "can not write", :updated_at, 1.day.agoit_behaves_like "can write", :author_id, 1234enddiff --git a/spec/services/work_packages/create_service_integration_spec.rb b/spec/services/work_packages/create_service_integration_spec.rbindex 7c9b1373706..5ff940d2c41 100644--- a/spec/services/work_packages/create_service_integration_spec.rb+++ b/spec/services/work_packages/create_service_integration_spec.rb@@ -231,25 +231,41 @@ RSpec.describe WorkPackages::CreateService, "integration", type: :model doshared_let(:other_user) { create(:user) }let(:created_at) { 11.days.ago }- let(:updated_at) { 10.days.ago }let(:attributes) do{subject: "child",project:,author: other_user,- created_at:,- updated_at:+ created_at:}endcontext "when enabled", with_settings: { apiv3_write_readonly_attributes: true } do- it "updates the timestamps correctly" do+ it "sets created_at accordingly" doexpect(service_result).to be_successexpect(new_work_package.created_at).to be_within(1.second).of(created_at)- expect(new_work_package.updated_at).to be_within(1.second).of(updated_at)+ end+ end++ context "when enabled, but disallowed field", with_settings: { apiv3_write_readonly_attributes: true } do+ let(:attributes) do+ {+ subject: "child",+ project:,+ author: other_user,+ updated_at: created_at+ }+ end++ it "rejects updated_at" do+ expect(service_result)+ .not_to be_success++ expect(new_work_package.errors.symbols_for(:updated_at))+ .to contain_exactly(:error_readonly)endend@@ -260,9 +276,6 @@ RSpec.describe WorkPackages::CreateService, "integration", type: :model doexpect(new_work_package.errors.symbols_for(:created_at)).to contain_exactly(:error_readonly)-- expect(new_work_package.errors.symbols_for(:updated_at))- .to contain_exactly(:error_readonly)endendend