Adds Private filter to the issue list (#8577).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9920 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-07-05 13:51:56 +00:00
parent 1d7c0eb7c0
commit 196f96fff1
2 changed files with 43 additions and 1 deletions

View File

@ -302,7 +302,12 @@ class Query < ActiveRecord::Base
end end
add_custom_fields_filters(IssueCustomField.find(:all, :conditions => {:is_filter => true, :is_for_all => true})) add_custom_fields_filters(IssueCustomField.find(:all, :conditions => {:is_filter => true, :is_for_all => true}))
end 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| Tracker.disabled_core_fields(trackers).each {|field|
@available_filters.delete field @available_filters.delete field
} }
@ -704,6 +709,13 @@ class Query < ActiveRecord::Base
end end
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 private
def sql_for_custom_field(field, operator, value, custom_field_id) def sql_for_custom_field(field, operator, value, custom_field_id)

View File

@ -258,6 +258,36 @@ class QueryTest < ActiveSupport::TestCase
assert issues.map(&:id).include?(3) assert issues.map(&:id).include?(3)
end 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 def test_operator_greater_than
query = Query.new(:project => Project.find(1), :name => '_') query = Query.new(:project => Project.find(1), :name => '_')
query.add_filter('done_ratio', '>=', ['40']) query.add_filter('done_ratio', '>=', ['40'])