Add "me" to user custom fields filters #1046
Adapted from
28f9605fe2
by Jean-Philippe Lang
This commit is contained in:
parent
5c7a3a53c2
commit
e4386f61da
|
@ -383,8 +383,10 @@ class Query < ActiveRecord::Base
|
|||
next unless v and !v.empty?
|
||||
operator = operator_for(field)
|
||||
|
||||
# "me" value subsitution
|
||||
if %w(assigned_to_id author_id watcher_id).include?(field)
|
||||
# "me" value substitution
|
||||
if %w(assigned_to_id author_id watcher_id).include?(field) ||
|
||||
# user custom fields
|
||||
available_filters.has_key?(field) && available_filters[field][:format] == 'user'
|
||||
v.push(User.current.logged? ? User.current.id.to_s : "0") if v.delete("me")
|
||||
end
|
||||
|
||||
|
@ -640,11 +642,15 @@ class Query < ActiveRecord::Base
|
|||
options = { :type => :list, :values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]], :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
|
||||
|
||||
|
|
|
@ -222,6 +222,28 @@ class QueryTest < ActiveSupport::TestCase
|
|||
find_issues_with_query(query)
|
||||
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])
|
||||
|
||||
project = Project.find(1)
|
||||
tracker = Tracker.find(1)
|
||||
project.trackers << tracker unless project.trackers.include?(tracker)
|
||||
|
||||
issue = Issue.create!(:project => project, :tracker => tracker, :subject => 'Test', :author_id => 1)
|
||||
issue.update_attribute(:custom_field_values, {cf.id.to_s => '2'})
|
||||
|
||||
query = Query.new(:name => '_', :project => project)
|
||||
filter = query.available_filters["cf_#{cf.id}"]
|
||||
assert_not_nil filter
|
||||
assert filter[:values].map{|v| v[1]}.include?('me')
|
||||
|
||||
query.filters = { "cf_#{cf.id}" => {:operator => '=', :values => ['me']}}
|
||||
result = query.issues
|
||||
assert_equal 1, result.size
|
||||
assert issue, result.first
|
||||
end
|
||||
|
||||
def test_filter_watched_issues
|
||||
User.current = User.find(1)
|
||||
query = Query.new(:name => '_', :filters => { 'watcher_id' => {:operator => '=', :values => ['me']}})
|
||||
|
|
Loading…
Reference in New Issue