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

using the new query.remove_filter method provided by @ulferts and added more specific specs

Jonas Jabari8ea3e75bc789
diff --git a/modules/calendar/app/services/calendar/resolve_work_packages_service.rb b/modules/calendar/app/services/calendar/resolve_work_packages_service.rb
index 6dc47da8551..5d162f0efd3 100644
--- a/modules/calendar/app/services/calendar/resolve_work_packages_service.rb
+++ b/modules/calendar/app/services/calendar/resolve_work_packages_service.rb
@@ -31,7 +31,7 @@ module Calendar
def perform(query:)
raise ActiveRecord::RecordNotFound if query.nil?
- query = remove_date_range_filter(query)
+ query.remove_filter(:dates_interval)
work_packages = query.results.work_packages.includes(
:project, :assigned_to, :author, :priority, :status, :type
@@ -41,17 +41,5 @@ module Calendar
ServiceResult.success(result: work_packages_with_dates)
end
-
- protected
-
- def remove_date_range_filter(query)
- # TODO:
- # Is this the correct way of unscoping the calendar view state
- # in order to get all workpackages from the query?
- query.filters = query.filters
- .reject { |filter| filter.name == :dates_interval }
-
- query
- end
end
end
diff --git a/modules/calendar/spec/services/resolve_work_packages_service_spec.rb b/modules/calendar/spec/services/resolve_work_packages_service_spec.rb
index c147e6564ae..e8d78c7d87a 100644
--- a/modules/calendar/spec/services/resolve_work_packages_service_spec.rb
+++ b/modules/calendar/spec/services/resolve_work_packages_service_spec.rb
@@ -52,16 +52,26 @@ describe Calendar::ResolveWorkPackagesService, type: :model do
start_date: Date.tomorrow,
due_date: Time.zone.today + 7.days)
end
+ let(:work_package_with_due_date_far_in_the_past) do
+ create(:work_package, project:,
+ due_date: Time.zone.today - 180.days)
+ end
+ let(:work_package_with_due_date_far_in_the_future) do
+ create(:work_package, project:,
+ due_date: Time.zone.today + 180.days)
+ end
let(:work_packages) do
[
work_package_without_dates,
work_package_with_due_date,
work_package_with_start_date,
- work_package_with_start_and_due_date
+ work_package_with_start_and_due_date,
+ work_package_with_due_date_far_in_the_past,
+ work_package_with_due_date_far_in_the_future
]
end
let(:query) do
- create(:query,
+ create(:query_with_view_work_packages_calendar,
project:,
user: user1,
public: false)
@@ -73,6 +83,12 @@ describe Calendar::ResolveWorkPackagesService, type: :model do
context 'for a valid query' do
before do
+ # Add typical calendar filters which are present for calendar queries
+ query.add_filter(:dates_interval, "<>d", [Time.zone.today, Time.zone.today+30.days])
+
+ # login for this isolated test:
+ # in context of the whole iCalendar API flow, the user is not logged in but resolved from the token
+ # `User.execute_as()`` is then used in the service calling the service which is tested here
login_as(user1)
end
@@ -85,7 +101,9 @@ describe Calendar::ResolveWorkPackagesService, type: :model do
.to include(
work_package_with_start_date,
work_package_with_due_date,
- work_package_with_start_and_due_date
+ work_package_with_start_and_due_date,
+ work_package_with_due_date_far_in_the_past,
+ work_package_with_due_date_far_in_the_future
)
expect(result)
.not_to include(work_package_without_dates)