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
fixup! [#46555] Extend Query resource in APIv3 by timestamps
Dombi Attila732cd020dcc5
diff --git a/app/contracts/queries/base_contract.rb b/app/contracts/queries/base_contract.rbindex 03fb42596be..18bdf8dc577 100644--- a/app/contracts/queries/base_contract.rb+++ b/app/contracts/queries/base_contract.rb@@ -60,6 +60,7 @@ module Queriesvalidate :validate_projectvalidate :user_allowed_to_make_public+ validate :timestamps_are_parsabledef validate_projecterrors.add :project, :error_not_found if project_id.present? && !project_visible?@@ -82,5 +83,13 @@ module Querieserrors.add :public, :error_unauthorizedendend++ def timestamps_are_parsable+ invalid_timestamps = model.timestamps.reject(&:valid?)++ if invalid_timestamps.any?+ errors.add :timestamps, :invalid, values: invalid_timestamps.join(", ")+ end+ endendenddiff --git a/app/models/query/timestamps.rb b/app/models/query/timestamps.rbindex c111d3c6550..1f4360719cd 100644--- a/app/models/query/timestamps.rb+++ b/app/models/query/timestamps.rb@@ -32,9 +32,6 @@ module Query::Timestampsincluded doserialize :timestamps, Array- validates :timestamps, length: { maximum: 2 }- validate :timestamps_are_parsable-# Returns the timestamps the query should be evaluated at.## In the database, the timestamps are stored as ISO8601 strings.@@ -51,8 +48,8 @@ module Query::Timestampstimestamps.any? ? timestamps : [Timestamp.now]end- def timestamps=(array)- super(array.collect { |element| element.respond_to?(:iso8601) ? element.iso8601 : element })+ def timestamps=(params)+ super(Array(params).collect { |element| element.respond_to?(:iso8601) ? element.iso8601 : element })end# Does this query perform a historic search?@@ -60,15 +57,5 @@ module Query::Timestampsdef historic?timestamps != [Timestamp.now]end-- private-- def timestamps_are_parsable- invalid_timestamps = timestamps.reject(&:valid?)-- if invalid_timestamps.any?- errors.add :timestamps, :invalid, values: invalid_timestamps.join(", ")- end- endendenddiff --git a/config/locales/en.yml b/config/locales/en.ymlindex 6a82614d2e3..dee0ecc8f39 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -810,7 +810,6 @@ en:timestamps:invalid: "Timestamps contain invalid values: %{values}"format: "%{message}"- too_long: "Timestamps are too long (maximum is %{count} values)."group_by_hierarchies_exclusive: "is mutually exclusive with group by '%{group_by}'. You cannot activate both."filters:custom_fields:diff --git a/docs/api/apiv3/tags/basic_objects.yml b/docs/api/apiv3/tags/basic_objects.ymlindex d9815f95435..5d8f371b209 100644--- a/docs/api/apiv3/tags/basic_objects.yml+++ b/docs/api/apiv3/tags/basic_objects.yml@@ -235,6 +235,8 @@ description: |-* `Duration` - refers to an ISO 8601 duration, e.g. "P1DT18H"+ * `Timestamp` - refers to an ISO 8601 combined date and time, e.g. "2014-05-21T13:37:00Z" or to an ISO 8601 duration, e.g. "P1DT18H"+## ColorsColors are represented in RGB using hexadecimal notation as specified in [CSS Color Module Level 3](https://www.w3.org/TR/css3-color/).diff --git a/spec/requests/api/v3/queries/create_form_api_spec.rb b/spec/requests/api/v3/queries/create_form_api_spec.rbindex 29712e574fa..714f6267dca 100644--- a/spec/requests/api/v3/queries/create_form_api_spec.rb+++ b/spec/requests/api/v3/queries/create_form_api_spec.rb@@ -455,6 +455,14 @@ describe "POST /api/v3/queries/form" doexpect(form.dig("_embedded", "payload", "timestamps")).to eq timestampsend+ context 'with one timestamp is present only' do+ let(:timestamps) { "PT0S" }++ it 'has the timestamp set' do+ expect(form.dig("_embedded", "payload", "timestamps")).to eq [timestamps]+ end+ end+context "with the project referred to by its identifier" dolet(:override_params) dolinks = parameters[:_links]@@ -474,7 +482,7 @@ describe "POST /api/v3/queries/form" doendcontext "with groupBy specified as a GET parameter" do- let(:path) { api_v3_paths.create_query_form + "?groupBy=author" }+ let(:path) { "#{api_v3_paths.create_query_form}?groupBy=author" }let(:override_params) dolinks = parameters[:_links]@@ -577,17 +585,6 @@ describe "POST /api/v3/queries/form" do.to eq "Timestamps contain invalid values: invalid, invalid2"endend-- context 'when there are too many values' do- let(:override_params) do- { timestamps: [2.weeks.ago.iso8601, 1.week.ago.iso8601, "P0D"] }- end-- it "returns a validation error" do- expect(form.dig("_embedded", "validationErrors", "timestamps", "message"))- .to eq "Timestamps are too long (maximum is 2 values)."- end- endendcontext "with an unauthorized user trying to set the query public" dodiff --git a/spec/requests/api/v3/queries/update_form_api_spec.rb b/spec/requests/api/v3/queries/update_form_api_spec.rbindex f75605a0da3..ca61121979d 100644--- a/spec/requests/api/v3/queries/update_form_api_spec.rb+++ b/spec/requests/api/v3/queries/update_form_api_spec.rb@@ -438,6 +438,14 @@ describe "POST /api/v3/queries/form" doexpect(form.dig("_embedded", "payload", "timestamps")).to eq timestampsend+ context 'with one timestamp is present only' do+ let(:timestamps) { "PT0S" }++ it 'has the timestamp set' do+ expect(form.dig("_embedded", "payload", "timestamps")).to eq [timestamps]+ end+ end+context "with the project referred to by its identifier" dolet(:override_params) dolinks = parameters[:_links]@@ -544,17 +552,6 @@ describe "POST /api/v3/queries/form" do.to eq "Timestamps contain invalid values: invalid, invalid2"endend-- context 'when there are too many values' do- let(:override_params) do- { timestamps: [2.weeks.ago.iso8601, 1.week.ago.iso8601, "P0D"] }- end-- it "returns a validation error" do- expect(form.dig("_embedded", "validationErrors", "timestamps", "message"))- .to eq "Timestamps are too long (maximum is 2 values)."- end- endendcontext "with an unauthorized user trying to set the query public" do