Project

General

Profile

Feature #17720 » filter_after_updated_by_and_last_updated_by_v4.patch

Marius BĂLTEANU, 2017-01-16 19:20

View differences:

app/models/issue_query.rb
165 165

  
166 166
    add_available_filter "issue_id", :type => :integer, :label => :label_issue
167 167

  
168
    add_available_filter("updated_by",
169
      :type => :list, :values => lambda { author_values }
170
    )
171

  
172
    add_available_filter("last_updated_by",
173
      :type => :list, :values => lambda { author_values }
174
    )
175

  
168 176
    Tracker.disabled_core_fields(trackers).each {|field|
169 177
      delete_available_filter field
170 178
    }
......
463 471
    end
464 472
  end
465 473

  
474
  def sql_for_updated_by_field(field, operator, value)
475
    db_table = Journal.table_name
476

  
477
    query = "#{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 " +
478
      sql_for_field(field, operator, value, db_table, 'user_id') + ')'
479

  
480
    logger.debug("==="*20)
481
    logger.debug(query)
482
    logger.debug("==="*20)
483

  
484
    query
485
  end
486

  
487
  def sql_for_last_updated_by_field(field, operator, value)
488
    db_table = Journal.table_name
489

  
490
    "#{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 " +
491
      sql_for_field(field, operator, value, db_table, 'user_id') + ')'
492
  end
493

  
466 494
  def sql_for_relations(field, operator, value, options={})
467 495
    relation_options = IssueRelation::TYPES[field]
468 496
    return relation_options unless relation_options
app/models/query.rb
798 798
      operator = operator_for(field)
799 799

  
800 800
      # "me" value substitution
801
      if %w(assigned_to_id author_id user_id watcher_id).include?(field)
801
      if %w(assigned_to_id author_id user_id watcher_id updated_by last_updated_by).include?(field)
802 802
        if v.delete("me")
803 803
          if User.current.logged?
804 804
            v.push(User.current.id.to_s)
config/locales/en.yml
369 369
  field_default_version: Default version
370 370
  field_remote_ip: IP address
371 371
  field_textarea_font: Font used for text areas
372
  field_updated_by: Updated by
373
  field_last_updated_by: Last updated by
372 374

  
373 375
  setting_app_title: Application title
374 376
  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
2715 2715
  end
2716 2716

  
2717 2717
  def test_last_journal_id_without_journals_should_return_nil
2718
    assert_nil Issue.find(3).last_journal_id
2718
    assert_nil Issue.find(4).last_journal_id
2719 2719
  end
2720 2720

  
2721 2721
  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
......
719 719
    end
720 720
  end
721 721

  
722
  def test_filter_updated_by
723
    query = IssueQuery.new(:name => '_')
724
    filter_name = "updated_by"
725
    assert_include filter_name, query.available_filters.keys
726

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

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

  
733
    query.filters = {filter_name => {:operator => '!', :values => [3]}, 'project_id' => {:operator => '=', :values =>[3]}}
734
    assert_equal [14], find_issues_with_query(query).map(&:id).uniq.sort
735
  end
736

  
737
  def test_filter_updated_by_me
738
    User.current = User.find(1)
739

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

  
744
  def test_filter_last_updated_by
745
    query = IssueQuery.new(:name => '_')
746
    filter_name = "last_updated_by"
747
    assert_include filter_name, query.available_filters.keys
748

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

  
752
    query.filters = {filter_name => {:operator => '!', :values => [1,2]}}
753
    assert_equal [3], find_issues_with_query(query).map(&:id).uniq.sort
754
  end
755

  
722 756
  def test_user_custom_field_filtered_on_me
723 757
    User.current = User.find(2)
724 758
    cf = IssueCustomField.create!(:field_format => 'user', :is_for_all => true, :is_filter => true, :name => 'User custom field', :tracker_ids => [1])
(4-4/8)