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

add new fields to API schema

Klaus Zanders60c90a3753de
diff --git a/modules/costs/lib/api/v3/time_entries/schemas/time_entry_schema_representer.rb b/modules/costs/lib/api/v3/time_entries/schemas/time_entry_schema_representer.rb
index ef7efd5f554..c5906a0e9d3 100644
--- a/modules/costs/lib/api/v3/time_entries/schemas/time_entry_schema_representer.rb
+++ b/modules/costs/lib/api/v3/time_entries/schemas/time_entry_schema_representer.rb
@@ -50,6 +50,15 @@ module API
schema :spent_on,
type: "Date"
+ schema :start_time,
+ type: "DateTime",
+ required: -> { TimeEntry.must_track_start_and_end_time? },
+ writable: -> { TimeEntry.can_track_start_and_end_time? }
+
+ schema :end_time,
+ type: "DateTime",
+ writable: false
+
schema :hours,
type: "Duration"
diff --git a/modules/costs/spec/lib/api/v3/time_entries/schemas/time_entry_schema_representer_spec.rb b/modules/costs/spec/lib/api/v3/time_entries/schemas/time_entry_schema_representer_spec.rb
index 3eee3e2c138..c30734b03df 100644
--- a/modules/costs/spec/lib/api/v3/time_entries/schemas/time_entry_schema_representer_spec.rb
+++ b/modules/costs/spec/lib/api/v3/time_entries/schemas/time_entry_schema_representer_spec.rb
@@ -108,6 +108,53 @@ RSpec.describe API::V3::TimeEntries::Schemas::TimeEntrySchemaRepresenter do
end
end
+ describe "startTime" do
+ let(:path) { "startTime" }
+
+ before do
+ allow(TimeEntry).to receive_messages(
+ can_track_start_and_end_time?: can_track_times,
+ must_track_start_and_end_time?: must_track_times
+ )
+ end
+
+ context "when start- and end-time tracking is disabled" do
+ let(:can_track_times) { false }
+ let(:must_track_times) { false }
+
+ it_behaves_like "has basic schema properties" do
+ let(:type) { "DateTime" }
+ let(:name) { TimeEntry.human_attribute_name("start_time") }
+ let(:required) { false }
+ let(:writable) { false }
+ end
+ end
+
+ context "when start- and end-time tracking is enabled" do
+ let(:can_track_times) { true }
+ let(:must_track_times) { false }
+
+ it_behaves_like "has basic schema properties" do
+ let(:type) { "DateTime" }
+ let(:name) { TimeEntry.human_attribute_name("start_time") }
+ let(:required) { false }
+ let(:writable) { true }
+ end
+ end
+
+ context "when start- and end-time tracking is enforced" do
+ let(:can_track_times) { true }
+ let(:must_track_times) { true }
+
+ it_behaves_like "has basic schema properties" do
+ let(:type) { "DateTime" }
+ let(:name) { TimeEntry.human_attribute_name("start_time") }
+ let(:required) { true }
+ let(:writable) { true }
+ end
+ end
+ end
+
describe "hours" do
let(:path) { "hours" }