Project

General

Profile

Feature #15201 » 15201_include_locked_members_in_assignee_users_v2.patch

Marius BĂLTEANU, 2017-10-08 19:00

View differences:

app/models/principal.rb
89 89
      where("1=0")
90 90
    else
91 91
      ids = projects.map(&:id)
92
      active.where("#{Principal.table_name}.id IN (SELECT DISTINCT user_id FROM #{Member.table_name} WHERE project_id IN (?))", ids)
92
      # include active and locked users
93
      where(:status => [STATUS_LOCKED, STATUS_ACTIVE]).
94
      where("#{Principal.table_name}.id IN (SELECT DISTINCT user_id FROM #{Member.table_name} WHERE project_id IN (?))", ids)
93 95
    end
94 96
  }
95 97
  # Principals that are not members of projects
app/models/query.rb
511 511
    @principal ||= begin
512 512
      principals = []
513 513
      if project
514
        principals += project.principals.visible
514
        principals += Principal.member_of(project).visible
515 515
        unless project.leaf?
516 516
          principals += Principal.member_of(project.descendants.visible).visible
517 517
        end
......
532 532
  def author_values
533 533
    author_values = []
534 534
    author_values << ["<< #{l(:label_me)} >>", "me"] if User.current.logged?
535
    author_values += users.collect{|s| [s.name, s.id.to_s] }
535
    author_values += users.sort_by(&:status).collect{|s| [s.name, s.id.to_s, l("status_#{User::LABEL_BY_STATUS[s.status]}")] }
536 536
    author_values
537 537
  end
538 538

  
539 539
  def assigned_to_values
540 540
    assigned_to_values = []
541 541
    assigned_to_values << ["<< #{l(:label_me)} >>", "me"] if User.current.logged?
542
    assigned_to_values += (Setting.issue_group_assignment? ? principals : users).collect{|s| [s.name, s.id.to_s] }
542
    assigned_to_values += (Setting.issue_group_assignment? ? principals : users).sort_by(&:status).collect{|s| [s.name, s.id.to_s, l("status_#{User::LABEL_BY_STATUS[s.status]}")] }
543 543
    assigned_to_values
544 544
  end
545 545

  
app/models/user.rb
514 514
    name
515 515
  end
516 516

  
517
  CSS_CLASS_BY_STATUS = {
517
  LABEL_BY_STATUS = {
518 518
    STATUS_ANONYMOUS  => 'anon',
519 519
    STATUS_ACTIVE     => 'active',
520 520
    STATUS_REGISTERED => 'registered',
......
522 522
  }
523 523

  
524 524
  def css_classes
525
    "user #{CSS_CLASS_BY_STATUS[status]}"
525
    "user #{LABEL_BY_STATUS[status]}"
526 526
  end
527 527

  
528 528
  # Returns the current day according to user's time zone
test/functional/queries_controller_test.rb
592 592
    json = ActiveSupport::JSON.decode(response.body)
593 593
    assert_include ["OnlineStore - Systemwide visible version", "7", "open"], json
594 594
  end
595

  
596
  def test_assignee_filter_should_return_active_and_locked_users_grouped_by_status
597
    @request.session[:user_id] = 1
598
    get :filter, :params => {
599
        :project_id => 1,
600
        :type => 'IssueQuery',
601
        :name => 'assigned_to_id'
602
      }
603
    assert_response :success
604
    assert_equal 'application/json', response.content_type
605
    json = ActiveSupport::JSON.decode(response.body)
606

  
607
    assert_equal 6, json.count
608
    # "me" value should not be grouped
609
    assert_include ["<< me >>", "me"], json
610
    assert_include ["Dave Lopper", "3", "active"], json
611
    assert_include ["Dave2 Lopper2", "5", "locked"], json
612
  end
613

  
614
  def test_author_filter_should_return_active_and_locked_users_grouped_by_status
615
    @request.session[:user_id] = 1
616
    get :filter, :params => {
617
        :project_id => 1,
618
        :type => 'IssueQuery',
619
        :name => 'author_id'
620
      }
621
    assert_response :success
622
    assert_equal 'application/json', response.content_type
623
    json = ActiveSupport::JSON.decode(response.body)
624

  
625
    assert_equal 6, json.count
626
    # "me" value should not be grouped
627
    assert_include ["<< me >>", "me"], json
628
    assert_include ["Dave Lopper", "3", "active"], json
629
    assert_include ["Dave2 Lopper2", "5", "locked"], json
630
  end
631

  
632
  def test_user_filter_should_return_active_and_locked_users_grouped_by_status
633
    @request.session[:user_id] = 1
634
    get :filter, :params => {
635
        :project_id => 1,
636
        :type => 'TimeEntryQuery',
637
        :name => 'user_id'
638
      }
639
    assert_response :success
640
    assert_equal 'application/json', response.content_type
641
    json = ActiveSupport::JSON.decode(response.body)
642

  
643
    assert_equal 6, json.count
644
    # "me" value should not be grouped
645
    assert_include ["<< me >>", "me"], json
646
    assert_include ["Dave Lopper", "3", "active"], json
647
    assert_include ["Dave2 Lopper2", "5", "locked"], json
648
  end
595 649
end
test/unit/principal_test.rb
52 52
    assert_equal expected.map(&:id).sort, Principal.visible(user).pluck(:id).sort
53 53
  end
54 54

  
55
  def test_member_of_scope_should_return_the_union_of_all_members
55
  def test_member_of_scope_should_return_the_union_of_all_active_and_locked_members
56 56
    projects = Project.find([1])
57
    assert_equal [3, 2], Principal.member_of(projects).sort.map(&:id)
57
    assert_equal [3, 5, 2], Principal.member_of(projects).sort.map(&:id)
58 58
    projects = Project.find([1, 2])
59
    assert_equal [3, 2, 8, 11], Principal.member_of(projects).sort.map(&:id)
59
    assert_equal [3, 5, 2, 8, 11], Principal.member_of(projects).sort.map(&:id)
60 60
  end
61 61

  
62 62
  def test_member_of_scope_should_be_empty_for_no_projects
(4-4/6)