From b82367b1819da2640ee783cb0a24e7d3efa12373 Mon Sep 17 00:00:00 2001 From: Jan Schulz-Hofen Date: Sat, 5 Dec 2026 23:05:34 +0100 Subject: [PATCH] Add "any" operator to the status filter of the projects list The status filter of the projects list only offers "is" and "is not". To see projects of every status, a user has to remove the filter, and to filter by status again, add it again. The filter now has the type list_optional, as the status filter of the users list has. This adds the operators "any" and "none". The default stays "is active". --- app/models/project_query.rb | 2 +- test/unit/project_query_test.rb | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/models/project_query.rb b/app/models/project_query.rb index 4464eb1..a29bdb6 100644 --- a/app/models/project_query.rb +++ b/app/models/project_query.rb @@ -66,7 +66,7 @@ class ProjectQuery < Query def initialize_available_filters add_available_filter( "status", - :type => :list, :values => lambda {project_statuses_values} + :type => :list_optional, :values => lambda {project_statuses_values} ) add_available_filter( "id", diff --git a/test/unit/project_query_test.rb b/test/unit/project_query_test.rb index 2b8c0ea..5eb71d7 100644 --- a/test/unit/project_query_test.rb +++ b/test/unit/project_query_test.rb @@ -42,6 +42,26 @@ class ProjectQueryTest < ActiveSupport::TestCase assert_equal ['1', '5'], values.map(&:second) end + def test_project_statuses_filter_should_offer_the_any_operator + query = ProjectQuery.new(:name => '_') + type = query.available_filters['status'][:type] + assert_include '*', query.operators_by_filter_type[type] + end + + def test_project_statuses_filter_with_any_operator_should_return_active_and_closed_projects + User.current = User.find(1) + closed = Project.find(2) + closed.update_attribute(:status, Project::STATUS_CLOSED) + + query = ProjectQuery.new(:name => '_') + query.filters = {'status' => {:operator => '*', :values => ['']}} + assert query.valid? + + projects = query.results_scope.to_a + assert_include closed, projects + assert_include Project.find(1), projects + end + def test_default_columns q = ProjectQuery.new assert q.columns.any? -- 2.47.3