Adds "me" to user custom fields filters (#9923).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8638 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
919d0a68c3
commit
980b6db5c0
|
@ -688,6 +688,12 @@ class Query < ActiveRecord::Base
|
|||
def sql_for_custom_field(field, operator, value, custom_field_id)
|
||||
db_table = CustomValue.table_name
|
||||
db_field = 'value'
|
||||
filter = @available_filters[field]
|
||||
if filter && filter[:format] == 'user'
|
||||
if value.delete('me')
|
||||
value.push User.current.id.to_s
|
||||
end
|
||||
end
|
||||
"#{Issue.table_name}.id IN (SELECT #{Issue.table_name}.id FROM #{Issue.table_name} LEFT OUTER JOIN #{db_table} ON #{db_table}.customized_type='Issue' AND #{db_table}.customized_id=#{Issue.table_name}.id AND #{db_table}.custom_field_id=#{custom_field_id} WHERE " +
|
||||
sql_for_field(field, operator, value, db_table, db_field, true) + ')'
|
||||
end
|
||||
|
@ -816,11 +822,15 @@ class Query < ActiveRecord::Base
|
|||
options = { :type => :float, :order => 20 }
|
||||
when "user", "version"
|
||||
next unless project
|
||||
options = { :type => :list_optional, :values => field.possible_values_options(project), :order => 20}
|
||||
values = field.possible_values_options(project)
|
||||
if User.current.logged? && field.field_format == 'user'
|
||||
values.unshift ["<< #{l(:label_me)} >>", "me"]
|
||||
end
|
||||
options = { :type => :list_optional, :values => values, :order => 20}
|
||||
else
|
||||
options = { :type => :string, :order => 20 }
|
||||
end
|
||||
@available_filters["cf_#{field.id}"] = options.merge({ :name => field.name })
|
||||
@available_filters["cf_#{field.id}"] = options.merge({ :name => field.name, :format => field.field_format })
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -413,6 +413,23 @@ class QueryTest < ActiveSupport::TestCase
|
|||
assert !result.include?(i3)
|
||||
end
|
||||
|
||||
def test_user_custom_field_filtered_on_me
|
||||
User.current = User.find(2)
|
||||
cf = IssueCustomField.create!(:field_format => 'user', :is_for_all => true, :is_filter => true, :name => 'User custom field', :tracker_ids => [1])
|
||||
issue1 = Issue.create!(:project_id => 1, :tracker_id => 1, :custom_field_values => {cf.id.to_s => '2'}, :subject => 'Test', :author_id => 1)
|
||||
issue2 = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {cf.id.to_s => '3'})
|
||||
|
||||
query = Query.new(:name => '_', :project => Project.find(1))
|
||||
filter = query.available_filters["cf_#{cf.id}"]
|
||||
assert_not_nil filter
|
||||
assert_include 'me', filter[:values].map{|v| v[1]}
|
||||
|
||||
query.filters = { "cf_#{cf.id}" => {:operator => '=', :values => ['me']}}
|
||||
result = query.issues
|
||||
assert_equal 1, result.size
|
||||
assert issue1, result.first
|
||||
end
|
||||
|
||||
def test_filter_my_projects
|
||||
User.current = User.find(2)
|
||||
query = Query.new(:name => '_')
|
||||
|
|
Loading…
Reference in New Issue