Add_filter_value_of_watcher.patch

Mizuki ISHIKAWA, 2018-06-25 10:12

Download (2.64 KB)

View differences:

app/models/issue_query.rb
148 148

  
149 149
    if User.current.logged?
150 150
      add_available_filter "watcher_id",
151
        :type => :list, :values => [["<< #{l(:label_me)} >>", "me"]]
151
        :type => :list, :values => lambda { watcher_values }
152 152
    end
153 153

  
154 154
    add_available_filter("updated_by",
app/models/query.rb
564 564
    statuses.collect{|s| [s.name, s.id.to_s]}
565 565
  end
566 566

  
567
  def watcher_values
568
    watcher_values = [["<< #{l(:label_me)} >>", "me"]]
569
    watcher_values += self.users.map{|s| [s.name, s.id.to_s] } if User.current.allowed_to?(:view_issue_watchers, nil, :global => true)
570
    watcher_values
571
  end
572

  
567 573
  # Returns a scope of issue custom fields that are available as columns or filters
568 574
  def issue_custom_fields
569 575
    if project
test/functional/queries_controller_test.rb
685 685
    assert_include ["Dave Lopper", "3", "active"], json
686 686
    assert_include ["Dave2 Lopper2", "5", "locked"], json
687 687
  end
688

  
689
  def test_watcher_filter_without_view_issue_watcher_should_return_filter_values
690
    # A user who does not belong to any project
691
    # Don't have view_issue_watcher permission
692
    @request.session[:user_id] = 7
693

  
694
    get :filter, :params => {
695
        :project_id => 1,
696
        :type => 'IssueQuery',
697
        :name => 'watcher_id'
698
      }
699
    assert_response :success
700
    assert_equal 'application/json', response.content_type
701
    json = ActiveSupport::JSON.decode(response.body)
702

  
703
    assert_equal [["<< me >>", "me"]], json
704
  end
705

  
706
  def test_watcher_filter_with_view_issue_watcher_should_return_filter_values
707
    # This user has view_issue_watcher permission
708
    @request.session[:user_id] = 1
709

  
710
    get :filter, :params => {
711
        :project_id => 1,
712
        :type => 'IssueQuery',
713
        :name => 'watcher_id'
714
      }
715
    assert_response :success
716
    assert_equal 'application/json', response.content_type
717
    json = ActiveSupport::JSON.decode(response.body)
718

  
719
    assert_equal 6, json.count
720
    assert_include ["<< me >>", "me"], json
721
    assert_include ["Dave Lopper", "3"], json
722
    assert_include ["Dave2 Lopper2", "5"], json
723
  end
688 724
end