diff --git a/app/models/query.rb b/app/models/query.rb index 42309e01a..cd3a10f0a 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -302,7 +302,12 @@ class Query < ActiveRecord::Base end add_custom_fields_filters(IssueCustomField.find(:all, :conditions => {:is_filter => true, :is_for_all => true})) end - + + if User.current.allowed_to?(:set_issues_private, nil, :global => true) || + User.current.allowed_to?(:set_own_issues_private, nil, :global => true) + @available_filters["is_private"] = { :type => :list, :order => 15, :values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]] } + end + Tracker.disabled_core_fields(trackers).each {|field| @available_filters.delete field } @@ -704,6 +709,13 @@ class Query < ActiveRecord::Base end end + def sql_for_is_private_field(field, operator, value) + op = (operator == "=" ? 'IN' : 'NOT IN') + va = value.map {|v| v == '0' ? connection.quoted_false : connection.quoted_true}.uniq.join(',') + + "#{Issue.table_name}.is_private #{op} (#{va})" + end + private def sql_for_custom_field(field, operator, value, custom_field_id) diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb index 61f7a4b01..522d8d0a3 100644 --- a/test/unit/query_test.rb +++ b/test/unit/query_test.rb @@ -258,6 +258,36 @@ class QueryTest < ActiveSupport::TestCase assert issues.map(&:id).include?(3) end + def test_operator_is_on_is_private_field + # is_private filter only available for those who can set issues private + User.current = User.find(2) + + query = Query.new(:name => '_') + assert query.available_filters.key?('is_private') + + query.add_filter("is_private", '=', ['1']) + issues = find_issues_with_query(query) + assert issues.any? + assert_nil issues.detect {|issue| !issue.is_private?} + ensure + User.current = nil + end + + def test_operator_is_not_on_is_private_field + # is_private filter only available for those who can set issues private + User.current = User.find(2) + + query = Query.new(:name => '_') + assert query.available_filters.key?('is_private') + + query.add_filter("is_private", '!', ['1']) + issues = find_issues_with_query(query) + assert issues.any? + assert_nil issues.detect {|issue| issue.is_private?} + ensure + User.current = nil + end + def test_operator_greater_than query = Query.new(:project => Project.find(1), :name => '_') query.add_filter('done_ratio', '>=', ['40'])