Skip to content

Commit

Permalink
Do not expose updatedAt changing for admins in work packages
Browse files Browse the repository at this point in the history
The field may be updating due to external changes (causes, default
values, rescheduling)
  • Loading branch information
oliverguenther committed Mar 25, 2024
1 parent 20ec8fd commit 910c60c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/contracts/work_packages/create_contract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
module WorkPackages
class CreateContract < BaseContract
include AdminWritableTimestamps
allow_writable_timestamps
allow_writable_timestamps :created_at

attribute :author_id,
writable: -> { default_attributes_admin_writable? }
Expand Down
2 changes: 1 addition & 1 deletion spec/contracts/work_packages/create_contract_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
let(: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.ago
it_behaves_like "can write", :author_id, 1234
end

Expand Down
29 changes: 21 additions & 8 deletions spec/services/work_packages/create_service_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,25 +231,41 @@
shared_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:
}
end

context "when enabled", with_settings: { apiv3_write_readonly_attributes: true } do
it "updates the timestamps correctly" do
it "sets created_at accordingly" do
expect(service_result)
.to be_success

expect(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)
end
end

Expand All @@ -260,9 +276,6 @@

expect(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)
end
end
end
Expand Down

0 comments on commit 910c60c

Please sign in to comment.