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! [#48001] Restrict timestamps outside enterprise to "yesterday"in query timestamps backend
Dombi Attilae83eb05ea1e1
diff --git a/app/models/query.rb b/app/models/query.rbindex ff71834f2a2..0879f703c29 100644--- a/app/models/query.rb+++ b/app/models/query.rb@@ -54,7 +54,7 @@ class Query < ApplicationRecordvalidate :validate_sort_criteriavalidate :validate_group_byvalidate :validate_show_hierarchies- validate :validate_timestamps, unless: -> { EnterpriseToken.allows_to?(:baseline_comparison) }+ validate :validate_timestampsinclude Scopes::Scopedscopes :visible,@@ -144,8 +144,7 @@ class Query < ApplicationRecordenddef validate_timestamps- forbidden_timestamps = timestamps.select { |t| t.to_time < Date.yesterday }-+ forbidden_timestamps = timestamps - allowed_timestampsif forbidden_timestamps.any?errors.add :timestamps, :forbidden, values: forbidden_timestamps.join(", ")end@@ -175,6 +174,7 @@ class Query < ApplicationRecordvalid_group_by_subset!valid_sort_criteria_subset!valid_column_subset!+ valid_timestamps_subset!enddef add_filter(field, operator, values)@@ -425,6 +425,12 @@ class Query < ApplicationRecordendend+ def allowed_timestamps+ return timestamps if EnterpriseToken.allows_to?(:baseline_comparison)++ timestamps.reject { |t| t.to_time < Date.yesterday }+ end+def valid_filter_subset!filters.each(&:valid_values!).select! do |filter|filter.available? && filter.valid?@@ -450,4 +456,8 @@ class Query < ApplicationRecordself.column_names &= available_namesend++ def valid_timestamps_subset!+ self.timestamps &= allowed_timestamps+ endenddiff --git a/spec/lib/api/v3/work_packages/work_package_representer_spec.rb b/spec/lib/api/v3/work_packages/work_package_representer_spec.rbindex c825d9dea6f..e76d83cf74a 100644--- a/spec/lib/api/v3/work_packages/work_package_representer_spec.rb+++ b/spec/lib/api/v3/work_packages/work_package_representer_spec.rb@@ -1418,7 +1418,7 @@ describe API::V3::WorkPackages::WorkPackageRepresenter domember_with_permissions: %i[view_work_packages view_file_links])end- describe 'attributesByTimestamp', with_flag: { show_changes: true } do+ describe 'attributesByTimestamp', with_ee: %i[baseline_comparison], with_flag: { show_changes: true } doit 'states whether the work package matches the query filters at the timestamp' doexpect(subject).to be_json_eql(true.to_json)diff --git a/spec/models/journable/with_historic_attributes_spec.rb b/spec/models/journable/with_historic_attributes_spec.rbindex 32dcd7ca42a..7e973018510 100644--- a/spec/models/journable/with_historic_attributes_spec.rb+++ b/spec/models/journable/with_historic_attributes_spec.rb@@ -28,7 +28,8 @@require 'spec_helper'-describe Journable::WithHistoricAttributes, with_flag: { show_changes: true } do+describe Journable::WithHistoricAttributes,+ with_ee: %i[baseline_comparison], with_flag: { show_changes: true } docreate_shared_association_defaults_for_work_package_factoryshared_let(:baseline_time) { "2022-01-01".to_time }diff --git a/spec/models/query/results_filter_on_historic_data_spec.rb b/spec/models/query/results_filter_on_historic_data_spec.rbindex 86e8a4016da..cad5a905199 100644--- a/spec/models/query/results_filter_on_historic_data_spec.rb+++ b/spec/models/query/results_filter_on_historic_data_spec.rb@@ -30,6 +30,7 @@ require 'spec_helper'describe Query::Results,'Filter on historic data',+ with_ee: %i[baseline_comparison],with_flag: { show_changes: true },with_mail: false dolet(:historic_time) { "2022-08-01".to_datetime }diff --git a/spec/models/query/timestamps_spec.rb b/spec/models/query/timestamps_spec.rbindex ce96173dd44..5aaf6fff699 100644--- a/spec/models/query/timestamps_spec.rb+++ b/spec/models/query/timestamps_spec.rb@@ -28,7 +28,8 @@require 'spec_helper'-describe Query::Timestamps, with_flag: { show_changes: true } do+describe Query::Timestamps,+ with_ee: %i[baseline_comparison], with_flag: { show_changes: true } dodescribe "#timestamps" dosubject { query.timestamps }diff --git a/spec/models/query_spec.rb b/spec/models/query_spec.rbindex dce4c856c69..fe99934f936 100644--- a/spec/models/query_spec.rb+++ b/spec/models/query_spec.rb@@ -577,7 +577,7 @@ describe Query,describe '#valid_subset!' dolet(:valid_status) { build_stubbed(:status) }- context 'filters' do+ context 'with filters' dobefore doallow(Status).to receive(:all)@@ -630,7 +630,7 @@ describe Query,endend- context 'group_by' do+ context 'with group_by' dobefore doquery.group_by = group_byend@@ -656,7 +656,7 @@ describe Query,endend- context 'sort_criteria' do+ context 'with sort_criteria' dobefore doquery.sort_criteria = sort_byend@@ -701,7 +701,7 @@ describe Query,endend- context 'columns' do+ context 'with columns' dobefore doquery.column_names = columnsend@@ -740,7 +740,7 @@ describe Query,endend- context 'highlighted_attributes' do+ context 'with highlighted_attributes' dolet(:highlighted_attributes) { %i{status priority due_date foo} }before do@@ -754,6 +754,31 @@ describe Query,.to match_array %i{status priority due_date}endend++ context 'with timestamps', with_flag: { show_changes: true } do+ let(:timestamps) do+ [3.weeks.ago.iso8601, 'oneWeekAgo@12:00+00:00', 'oneDayAgo@12:00+00:00', 'PT0S']+ end++ before do+ query.timestamps = timestamps+ query.valid_subset!+ end++ context 'without EE', with_ee: false do+ it 'removes the forbidden values' do+ expect(query.timestamps)+ .to match_array %w{oneDayAgo@12:00+00:00 PT0S}+ end+ end++ context 'with EE', with_ee: %i[baseline_comparison] do+ it 'allows all valid values' do+ expect(query.timestamps)+ .to match_array timestamps+ end+ end+ endenddescribe '#filter_for' do