Defect #36940 » 0001-Fix-chained-custom-field-filter-doesn-t-work-for-Use.patch
| app/models/query.rb | ||
|---|---|---|
| 1178 | 1178 |
filter = available_filters[field] |
| 1179 | 1179 |
target_class = filter[:through].format.target_class |
| 1180 | 1180 | |
| 1181 |
# It target class name is User, filter custom values after the base class which is Principal |
|
| 1182 |
if target_class.name == User.name |
|
| 1183 |
target_class = filter[:through].format.target_class.base_class |
|
| 1184 |
end |
|
| 1185 | ||
| 1181 | 1186 |
"#{queried_table_name}.id #{not_in} IN (" +
|
| 1182 | 1187 |
"SELECT customized_id FROM #{CustomValue.table_name}" +
|
| 1183 | 1188 |
" WHERE customized_type='#{queried_class}' AND custom_field_id=#{custom_field_id}" +
|
| test/unit/query_test.rb | ||
|---|---|---|
| 948 | 948 |
assert_equal issue1, result.first |
| 949 | 949 |
end |
| 950 | 950 | |
| 951 |
def test_filter_on_chained_user_custom_field |
|
| 952 |
user = User.find(2) |
|
| 953 |
User.current = user |
|
| 954 | ||
| 955 |
user_cf = UserCustomField.find(4) |
|
| 956 |
user_cf.update! is_filter: true |
|
| 957 | ||
| 958 |
issue_cf = IssueCustomField.create!(:field_format => 'user', :is_for_all => true, :is_filter => true, :name => 'User custom field', :tracker_ids => [1]) |
|
| 959 |
issue1 = Issue.create!(:project_id => 1, :tracker_id => 1, :custom_field_values => {issue_cf.id.to_s => '2'}, :subject => 'Test', :author_id => 1)
|
|
| 960 | ||
| 961 |
query = IssueQuery.new(:name => '_', :project => Project.find(1)) |
|
| 962 |
query.filters = {"cf_#{issue_cf.id}.cf_#{user_cf.id}" => {:operator => '~', :values => ['01 42']}}
|
|
| 963 |
result = query.issues |
|
| 964 | ||
| 965 |
assert_equal 1, result.size |
|
| 966 |
assert_equal issue1, result.first |
|
| 967 |
end |
|
| 968 | ||
| 951 | 969 |
def test_filter_on_me_by_anonymous_user |
| 952 | 970 |
User.current = nil |
| 953 | 971 |
query = |