Project

General

Profile

Defect #25867 » 25867.patch

Go MAEDA, 2022-12-08 09:50

View differences:

app/models/issue.rb
257 257
  def reload(*args)
258 258
    @workflow_rule_by_attribute = nil
259 259
    @assignable_versions = nil
260
    @assignable_users = nil
260 261
    @relations = nil
261 262
    @spent_hours = nil
262 263
    @total_spent_hours = nil
......
979 980
  def assignable_users
980 981
    return [] if project.nil?
981 982

  
982
    users = project.assignable_users(tracker).to_a
983
    users << author if author && author.active?
984
    if assigned_to_id_was.present? && assignee = Principal.find_by_id(assigned_to_id_was)
985
      users << assignee
986
    end
987
    users.uniq.sort
983
    user_ids = []
984
    user_ids << author_id if author&.active?
985
    user_ids << assigned_to_id_was if assigned_to_id_was.present?
986
    project_users = project.assignable_users(tracker)
987
    user_ids.concat project_users.reorder(nil).ids
988
    @assignable_users = user_ids.empty? ? [] : Principal.where(:id => user_ids).sorted.to_a
988 989
  end
989 990

  
990 991
  # Versions that the issue can be assigned to
test/unit/issue_test.rb
2595 2595
    assert_kind_of User, Issue.find(1).assignable_users.first
2596 2596
  end
2597 2597

  
2598
  test "#assignable_users should be sorted" do
2599
    %w(a č u ř c í ý š З д ч и).each do |firstname|
2600
      Member.create!(:project_id => 1, :principal => User.generate!(:firstname => firstname), :role_ids => [1])
2601
    end
2602
    issue = Issue.new(:project => Project.find(1))
2603
    assignable_users = Issue.find(1).assignable_users
2604
    assert_equal User.where(:id => assignable_users).sorted.pluck(:firstname), assignable_users.map(&:firstname)
2605
  end
2606

  
2598 2607
  test "#assignable_users should include the issue author" do
2599 2608
    non_project_member = User.generate!
2600 2609
    issue = Issue.generate!(:author => non_project_member)
(3-3/3)