##// END OF EJS Templates
Filters show issues with unused custom fields (#13537)....
Jean-Philippe Lang -
r11903:59b935aa469c
parent child
Show More
@@ -28,6 +28,15 class IssueCustomField < CustomField
28 28 super || (roles & user.roles_for_project(project)).present?
29 29 end
30 30
31 def visibility_by_project_condition(*args)
32 sql = super
33 additional_sql = "#{Issue.table_name}.tracker_id IN (SELECT tracker_id FROM #{table_name_prefix}custom_fields_trackers#{table_name_suffix} WHERE custom_field_id = #{id})"
34 unless is_for_all?
35 additional_sql << " AND #{Issue.table_name}.project_id IN (SELECT project_id FROM #{table_name_prefix}custom_fields_projects#{table_name_suffix} WHERE custom_field_id = #{id})"
36 end
37 "((#{sql}) AND (#{additional_sql}))"
38 end
39
31 40 def validate_custom_field
32 41 super
33 42 errors.add(:base, l(:label_role_plural) + ' ' + l('activerecord.errors.messages.blank')) unless visible? || roles.present?
@@ -17,3 +17,12 custom_fields_trackers_005:
17 17 custom_fields_trackers_006:
18 18 custom_field_id: 6
19 19 tracker_id: 3
20 custom_fields_trackers_007:
21 custom_field_id: 8
22 tracker_id: 1
23 custom_fields_trackers_008:
24 custom_field_id: 8
25 tracker_id: 2
26 custom_fields_trackers_009:
27 custom_field_id: 8
28 tracker_id: 3
@@ -219,7 +219,7 class QueryTest < ActiveSupport::TestCase
219 219 end
220 220
221 221 def test_operator_is_on_integer_custom_field
222 f = IssueCustomField.create!(:name => 'filter', :field_format => 'int', :is_for_all => true, :is_filter => true)
222 f = IssueCustomField.create!(:name => 'filter', :field_format => 'int', :is_for_all => true, :is_filter => true, :trackers => Tracker.all)
223 223 CustomValue.create!(:custom_field => f, :customized => Issue.find(1), :value => '7')
224 224 CustomValue.create!(:custom_field => f, :customized => Issue.find(2), :value => '12')
225 225 CustomValue.create!(:custom_field => f, :customized => Issue.find(3), :value => '')
@@ -232,7 +232,7 class QueryTest < ActiveSupport::TestCase
232 232 end
233 233
234 234 def test_operator_is_on_integer_custom_field_should_accept_negative_value
235 f = IssueCustomField.create!(:name => 'filter', :field_format => 'int', :is_for_all => true, :is_filter => true)
235 f = IssueCustomField.create!(:name => 'filter', :field_format => 'int', :is_for_all => true, :is_filter => true, :trackers => Tracker.all)
236 236 CustomValue.create!(:custom_field => f, :customized => Issue.find(1), :value => '7')
237 237 CustomValue.create!(:custom_field => f, :customized => Issue.find(2), :value => '-12')
238 238 CustomValue.create!(:custom_field => f, :customized => Issue.find(3), :value => '')
@@ -246,7 +246,7 class QueryTest < ActiveSupport::TestCase
246 246 end
247 247
248 248 def test_operator_is_on_float_custom_field
249 f = IssueCustomField.create!(:name => 'filter', :field_format => 'float', :is_filter => true, :is_for_all => true)
249 f = IssueCustomField.create!(:name => 'filter', :field_format => 'float', :is_filter => true, :is_for_all => true, :trackers => Tracker.all)
250 250 CustomValue.create!(:custom_field => f, :customized => Issue.find(1), :value => '7.3')
251 251 CustomValue.create!(:custom_field => f, :customized => Issue.find(2), :value => '12.7')
252 252 CustomValue.create!(:custom_field => f, :customized => Issue.find(3), :value => '')
@@ -259,7 +259,7 class QueryTest < ActiveSupport::TestCase
259 259 end
260 260
261 261 def test_operator_is_on_float_custom_field_should_accept_negative_value
262 f = IssueCustomField.create!(:name => 'filter', :field_format => 'float', :is_filter => true, :is_for_all => true)
262 f = IssueCustomField.create!(:name => 'filter', :field_format => 'float', :is_filter => true, :is_for_all => true, :trackers => Tracker.all)
263 263 CustomValue.create!(:custom_field => f, :customized => Issue.find(1), :value => '7.3')
264 264 CustomValue.create!(:custom_field => f, :customized => Issue.find(2), :value => '-12.7')
265 265 CustomValue.create!(:custom_field => f, :customized => Issue.find(3), :value => '')
@@ -274,7 +274,7 class QueryTest < ActiveSupport::TestCase
274 274
275 275 def test_operator_is_on_multi_list_custom_field
276 276 f = IssueCustomField.create!(:name => 'filter', :field_format => 'list', :is_filter => true, :is_for_all => true,
277 :possible_values => ['value1', 'value2', 'value3'], :multiple => true)
277 :possible_values => ['value1', 'value2', 'value3'], :multiple => true, :trackers => Tracker.all)
278 278 CustomValue.create!(:custom_field => f, :customized => Issue.find(1), :value => 'value1')
279 279 CustomValue.create!(:custom_field => f, :customized => Issue.find(1), :value => 'value2')
280 280 CustomValue.create!(:custom_field => f, :customized => Issue.find(3), :value => 'value1')
@@ -292,7 +292,7 class QueryTest < ActiveSupport::TestCase
292 292
293 293 def test_operator_is_not_on_multi_list_custom_field
294 294 f = IssueCustomField.create!(:name => 'filter', :field_format => 'list', :is_filter => true, :is_for_all => true,
295 :possible_values => ['value1', 'value2', 'value3'], :multiple => true)
295 :possible_values => ['value1', 'value2', 'value3'], :multiple => true, :trackers => Tracker.all)
296 296 CustomValue.create!(:custom_field => f, :customized => Issue.find(1), :value => 'value1')
297 297 CustomValue.create!(:custom_field => f, :customized => Issue.find(1), :value => 'value2')
298 298 CustomValue.create!(:custom_field => f, :customized => Issue.find(3), :value => 'value1')
@@ -355,7 +355,7 class QueryTest < ActiveSupport::TestCase
355 355 end
356 356
357 357 def test_operator_greater_than_on_int_custom_field
358 f = IssueCustomField.create!(:name => 'filter', :field_format => 'int', :is_filter => true, :is_for_all => true)
358 f = IssueCustomField.create!(:name => 'filter', :field_format => 'int', :is_filter => true, :is_for_all => true, :trackers => Tracker.all)
359 359 CustomValue.create!(:custom_field => f, :customized => Issue.find(1), :value => '7')
360 360 CustomValue.create!(:custom_field => f, :customized => Issue.find(2), :value => '12')
361 361 CustomValue.create!(:custom_field => f, :customized => Issue.find(3), :value => '')
@@ -383,7 +383,7 class QueryTest < ActiveSupport::TestCase
383 383 end
384 384
385 385 def test_operator_lesser_than_on_date_custom_field
386 f = IssueCustomField.create!(:name => 'filter', :field_format => 'date', :is_filter => true, :is_for_all => true)
386 f = IssueCustomField.create!(:name => 'filter', :field_format => 'date', :is_filter => true, :is_for_all => true, :trackers => Tracker.all)
387 387 CustomValue.create!(:custom_field => f, :customized => Issue.find(1), :value => '2013-04-11')
388 388 CustomValue.create!(:custom_field => f, :customized => Issue.find(2), :value => '2013-05-14')
389 389 CustomValue.create!(:custom_field => f, :customized => Issue.find(3), :value => '')
@@ -459,7 +459,7 class QueryTest < ActiveSupport::TestCase
459 459 def test_operator_date_between
460 460 query = IssueQuery.new(:name => '_')
461 461 query.add_filter('due_date', '><', ['2011-06-23', '2011-07-10'])
462 assert_match /issues\.due_date > '2011-06-22 23:59:59(\.9+)?' AND issues\.due_date <= '2011-07-10 23:59:59(\.9+)?/, query.statement
462 assert_match /issues\.due_date > '2011-06-22 23:59:59(\.9+)?' AND issues\.due_date <= '2011-07-10 23:59:59(\.9+)?'/, query.statement
463 463 find_issues_with_query(query)
464 464 end
465 465
@@ -660,6 +660,34 class QueryTest < ActiveSupport::TestCase
660 660 User.current = nil
661 661 end
662 662
663 def test_filter_on_custom_field_should_ignore_projects_with_field_disabled
664 field = IssueCustomField.generate!(:trackers => Tracker.all, :project_ids => [1, 3, 4], :is_filter => true)
665 Issue.generate!(:project_id => 3, :tracker_id => 2, :custom_field_values => {field.id.to_s => 'Foo'})
666 Issue.generate!(:project_id => 4, :tracker_id => 2, :custom_field_values => {field.id.to_s => 'Foo'})
667
668 query = IssueQuery.new(:name => '_', :project => Project.find(1))
669 query.filters = {"cf_#{field.id}" => {:operator => '=', :values => ['Foo']}}
670 assert_equal 2, find_issues_with_query(query).size
671
672 field.project_ids = [1, 3] # Disable the field for project 4
673 field.save!
674 assert_equal 1, find_issues_with_query(query).size
675 end
676
677 def test_filter_on_custom_field_should_ignore_trackers_with_field_disabled
678 field = IssueCustomField.generate!(:tracker_ids => [1, 2], :is_for_all => true, :is_filter => true)
679 Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {field.id.to_s => 'Foo'})
680 Issue.generate!(:project_id => 1, :tracker_id => 2, :custom_field_values => {field.id.to_s => 'Foo'})
681
682 query = IssueQuery.new(:name => '_', :project => Project.find(1))
683 query.filters = {"cf_#{field.id}" => {:operator => '=', :values => ['Foo']}}
684 assert_equal 2, find_issues_with_query(query).size
685
686 field.tracker_ids = [1] # Disable the field for tracker 2
687 field.save!
688 assert_equal 1, find_issues_with_query(query).size
689 end
690
663 691 def test_filter_on_project_custom_field
664 692 field = ProjectCustomField.create!(:name => 'Client', :is_filter => true, :field_format => 'string')
665 693 CustomValue.create!(:custom_field => field, :customized => Project.find(3), :value => 'Foo')
General Comments 0
You need to be logged in to leave comments. Login now