filter_after_updated_by_and_last_updated_by_v3.patch

Toshi MARUYAMA, 2016-11-07 13:10

Download (7.59 KB)

View differences:

app/models/issue_query.rb
124 124
    add_available_filter "priority_id",
125 125
      :type => :list, :values => IssuePriority.all.collect{|s| [s.name, s.id.to_s] }
126 126

  
127
    author_values = []
128
    author_values << ["<< #{l(:label_me)} >>", "me"] if User.current.logged?
129
    author_values += users.collect{|s| [s.name, s.id.to_s] }
127
    user_values = []
128
    user_values << ["<< #{l(:label_me)} >>", "me"] if User.current.logged?
129
    user_values += users.collect{|s| [s.name, s.id.to_s] }
130 130
    add_available_filter("author_id",
131
      :type => :list, :values => author_values
132
    ) unless author_values.empty?
131
      :type => :list, :values => user_values
132
    ) unless user_values.empty?
133 133

  
134 134
    assigned_to_values = []
135 135
    assigned_to_values << ["<< #{l(:label_me)} >>", "me"] if User.current.logged?
......
194 194
        :values => subprojects.collect{|s| [s.name, s.id.to_s] }
195 195
    end
196 196

  
197
    unless user_values.empty?
198
      add_available_filter("updated_by",
199
        :type => :list, :values => user_values
200
      )
201

  
202
      add_available_filter("last_updated_by",
203
        :type => :list, :values => user_values
204
      )
205
    end
206

  
197 207
    add_custom_fields_filters(issue_custom_fields)
198 208

  
199 209
    add_associations_custom_fields_filters :project, :author, :assigned_to, :fixed_version
......
504 514
    end
505 515
  end
506 516

  
517
  def sql_for_updated_by_field(field, operator, value)
518
    db_table = Journal.table_name
519

  
520
    "#{Issue.table_name}.id IN (SELECT #{db_table}.journalized_id FROM #{db_table} WHERE #{db_table}.journalized_type='Issue' AND #{db_table}.journalized_id = #{Issue.table_name}.id AND " +
521
      sql_for_field(field, operator, value, db_table, 'user_id') + ')'
522
  end
523

  
524
  def sql_for_last_updated_by_field(field, operator, value)
525
    db_table = Journal.table_name
526

  
527
    "#{Issue.table_name}.id IN (SELECT max(#{db_table}.journalized_id) FROM #{db_table} WHERE #{db_table}.journalized_type='Issue' AND #{db_table}.created_on = #{Issue.table_name}.updated_on AND #{db_table}.journalized_id = #{Issue.table_name}.id AND " +
528
      sql_for_field(field, operator, value, db_table, 'user_id') + ')'
529
  end
530

  
507 531
  def sql_for_relations(field, operator, value, options={})
508 532
    relation_options = IssueRelation::TYPES[field]
509 533
    return relation_options unless relation_options
app/models/query.rb
696 696
      operator = operator_for(field)
697 697

  
698 698
      # "me" value substitution
699
      if %w(assigned_to_id author_id user_id watcher_id).include?(field)
699
      if %w(assigned_to_id author_id user_id watcher_id updated_by last_updated_by).include?(field)
700 700
        if v.delete("me")
701 701
          if User.current.logged?
702 702
            v.push(User.current.id.to_s)
config/locales/en.yml
365 365
  field_default_version: Default version
366 366
  field_remote_ip: IP address
367 367
  field_textarea_font: Font used for text areas
368
  field_updated_by: Updated by
369
  field_last_updated_by: Last updated by
368 370

  
369 371
  setting_app_title: Application title
370 372
  setting_app_subtitle: Application subtitle
test/fixtures/issues.yml
2 2
issues_001:
3 3
  created_on: <%= 3.days.ago.to_s(:db) %>
4 4
  project_id: 1
5
  updated_on: <%= 1.day.ago.to_s(:db) %>
5
  updated_on: <%= 1.days.ago.to_date.to_s(:db) %>
6 6
  priority_id: 4
7 7
  subject: Cannot print recipes
8 8
  id: 1
......
96 96
issues_006:
97 97
  created_on: <%= 1.minute.ago.to_s(:db) %>
98 98
  project_id: 5
99
  updated_on: <%= 1.minute.ago.to_s(:db) %>
99
  updated_on: <%= 1.days.ago.to_date.to_s(:db) %>
100 100
  priority_id: 4
101 101
  subject: Issue of a private subproject
102 102
  id: 6
......
252 252
  id: 14
253 253
  created_on: <%= 15.days.ago.to_s(:db) %>
254 254
  project_id: 3
255
  updated_on: <%= 15.days.ago.to_s(:db) %>
255
  updated_on: <%= 15.days.ago.to_date.to_s(:db) %>
256 256
  priority_id: 5
257 257
  subject: Private issue on public project
258 258
  fixed_version_id:
test/fixtures/journals.yml
14 14
  user_id: 2
15 15
  journalized_id: 1
16 16
journals_003:
17
  created_on: <%= 1.days.ago.to_date.to_s(:db) %>
17
  created_on: 2006-07-19 21:09:50 +02:00
18 18
  notes: "A comment with inline image: !picture.jpg! and a reference to #1 and r2."
19 19
  id: 3
20 20
  journalized_type: Issue
......
29 29
  journalized_id: 6
30 30
journals_005:
31 31
  id: 5
32
  created_on: <%= 1.days.ago.to_date.to_s(:db) %>
32
  created_on: <%= 15.days.ago.to_date.to_s(:db) %>
33 33
  notes: "A comment on a private issue."
34 34
  user_id: 2
35 35
  journalized_type: Issue
36 36
  journalized_id: 14
37
journals_006:
38
  id: 6
39
  created_on: 2006-07-19 21:07:27 +02:00
40
  notes: "New updates"
41
  user_id: 3
42
  journalized_type: Issue
43
  journalized_id: 3
test/unit/issue_test.rb
2702 2702
  end
2703 2703

  
2704 2704
  def test_last_journal_id_without_journals_should_return_nil
2705
    assert_nil Issue.find(3).last_journal_id
2705
    assert_nil Issue.find(4).last_journal_id
2706 2706
  end
2707 2707

  
2708 2708
  def test_journals_after_should_return_journals_with_greater_id
test/unit/query_test.rb
29 29
           :queries,
30 30
           :projects_trackers,
31 31
           :custom_fields_trackers,
32
           :workflows
32
           :workflows, :journals
33 33

  
34 34
  def setup
35 35
    User.current = nil
......
691 691
    assert !result.include?(i3)
692 692
  end
693 693

  
694
  def test_filter_updated_by
695
    query = IssueQuery.new(:name => '_')
696
    filter_name = "updated_by"
697
    assert_include filter_name, query.available_filters.keys
698

  
699
    query.filters = {filter_name => {:operator => '=', :values => [2]}}
700
    assert_equal [1,2,14], find_issues_with_query(query).map(&:id).uniq.sort
701

  
702
    query.filters = {filter_name => {:operator => '=', :values => [4]}}
703
    assert_equal [], find_issues_with_query(query).map(&:id).uniq.sort
704

  
705
    query.filters = {filter_name => {:operator => '!', :values => [3]}, 'project_id' => {:operator => '=', :values =>[3]}}
706
    assert_equal [14], find_issues_with_query(query).map(&:id).uniq.sort
707
  end
708

  
709
  def test_filter_updated_by_me
710
    User.current = User.find(1)
711

  
712
    query = IssueQuery.new(:name => '_', :filters => { "updated_by" => {:operator => '=', :values => ['me']}})
713
    assert_equal [1,6], find_issues_with_query(query).map(&:id).uniq.sort
714
  end
715

  
716
  def test_filter_last_updated_by
717
    query = IssueQuery.new(:name => '_')
718
    filter_name = "last_updated_by"
719
    assert_include filter_name, query.available_filters.keys
720

  
721
    query.filters = {filter_name => {:operator => '=', :values => [2]}}
722
    assert_equal [1,2,14], find_issues_with_query(query).map(&:id).uniq.sort
723

  
724
    query.filters = {filter_name => {:operator => '!', :values => [1,2]}}
725
    assert_equal [3], find_issues_with_query(query).map(&:id).uniq.sort
726
  end
727

  
694 728
  def test_user_custom_field_filtered_on_me
695 729
    User.current = User.find(2)
696 730
    cf = IssueCustomField.create!(:field_format => 'user', :is_for_all => true, :is_filter => true, :name => 'User custom field', :tracker_ids => [1])