]> source.dussan.org Git - redmine.git/commitdiff
Merged r22180 from trunk to 5.0-stable (#38443).
authorGo MAEDA <maeda@farend.jp>
Thu, 13 Apr 2023 22:59:31 +0000 (22:59 +0000)
committerGo MAEDA <maeda@farend.jp>
Thu, 13 Apr 2023 22:59:31 +0000 (22:59 +0000)
git-svn-id: https://svn.redmine.org/redmine/branches/5.0-stable@22181 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/group.rb
test/unit/group_test.rb

index 92a378e6e125a984f862875141ee958d71a563e0..1cfc6b56c82228187ca88abbccadf825391a01dd 100644 (file)
@@ -80,6 +80,8 @@ class Group < Principal
   def user_added(user)
     members.preload(:member_roles).each do |member|
       next if member.project_id.nil?
+      # skip if the group is a member without roles in the project
+      next if member.member_roles.empty?
 
       user_member =
         Member.find_or_initialize_by(:project_id => member.project_id, :user_id => user.id)
index 0ae78e73a32a2234801d6fbcd240bda621ea39ba..d89a226340bc66c00ab9ab4ca98201b4438b61e5 100644 (file)
@@ -177,4 +177,16 @@ class GroupTest < ActiveSupport::TestCase
 
     assert_equal %w(A B), Group.sorted.to_a.map(&:name)
   end
+
+  def test_user_added_should_not_fail_when_group_role_is_empty
+    group = Group.find(11)
+    project = Project.first
+    user = User.find(9)
+
+    m = Member.create!(:principal => group, :project => project, :role_ids => [1])
+    MemberRole.where(:member_id => m.id).delete_all
+
+    assert_nothing_raised {group.users << user}
+    assert group.users.include?(user)
+  end
 end