Project

General

Profile

Defect #35606 » fix-35606.patch

Mizuki ISHIKAWA, 2021-07-27 04:52

View differences:

app/models/project.rb
550 550

  
551 551
  # Returns a hash of project users/groups grouped by role
552 552
  def principals_by_role
553
    memberships.includes(:principal, :roles).inject({}) do |h, m|
553
    memberships.active.includes(:principal, :roles).inject({}) do |h, m|
554 554
      m.roles.each do |r|
555 555
        h[r] ||= []
556 556
        h[r] << m.principal
test/unit/project_test.rb
475 475
    assert principals_by_role[role].include?(group)
476 476
  end
477 477

  
478
  def test_principals_by_role_should_only_return_active_users
479
    group = Group.find(10)
480
    Member.create!(:principal => group, :project_id => 1, :role_ids => [1])
481

  
482
    principals_by_role = Project.find(1).principals_by_role
483
    locked_user = User.find(5)
484
    assert Project.find(1).memberships.map(&:principal).include?(locked_user)
485
    assert_not principals_by_role.values.flatten.include?(locked_user)
486
  end
487

  
478 488
  def test_rolled_up_trackers
479 489
    parent = Project.find(1)
480 490
    parent.trackers = Tracker.find([1, 2])
(3-3/3)