summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2023-04-13 15:21:43 +0000
committerGo MAEDA <maeda@farend.jp>2023-04-13 15:21:43 +0000
commita48700d58b3d6ad466e56b8b64d5563c36134f33 (patch)
tree258a4742bb5a2190a6301e5124daa16c512c0d36
parent2d7d01e633a30362e665370a081e3e3bad241432 (diff)
downloadredmine-a48700d58b3d6ad466e56b8b64d5563c36134f33.tar.gz
redmine-a48700d58b3d6ad466e56b8b64d5563c36134f33.zip
Cannot add a user to a group if the group is a member without roles in a certain project (#38443).
Patch by Go MAEDA. git-svn-id: https://svn.redmine.org/redmine/trunk@22180 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/models/group.rb2
-rw-r--r--test/unit/group_test.rb12
2 files changed, 14 insertions, 0 deletions
diff --git a/app/models/group.rb b/app/models/group.rb
index 92a378e6e..1cfc6b56c 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -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)
diff --git a/test/unit/group_test.rb b/test/unit/group_test.rb
index 92685e21c..9d7d037ab 100644
--- a/test/unit/group_test.rb
+++ b/test/unit/group_test.rb
@@ -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