Project

General

Profile

Actions

Defect #38443

closed

Cannot add a user to a group if the group is a member without roles in a certain project

Added by Go MAEDA about 1 year ago. Updated about 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Groups
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected version:

Description

An exception will be raised if you attempt to add a user to a group if the group is a member without any roles in a certain project. The attempt will fail with the following error.

Completed 422 Unprocessable Entity in 36ms (ActiveRecord: 14.5ms | Allocations: 14551)

ActiveRecord::RecordInvalid (Validation failed: Role cannot be empty):

app/models/group.rb:90:in `block in user_added'
app/models/group.rb:81:in `user_added'
app/controllers/groups_controller.rb:118:in `add_users'
lib/redmine/sudo_mode.rb:61:in `sudo_mode

You can reproduce the error with the following steps:

1. Add a group as a project member with any role
2. Edit the member and clear checkboxes for all roles and save
3. Go to Administration > Groups
4. Add a user to the group. You cannot add a group. The above error will be logged


Files

38443.patch (1.17 KB) 38443.patch Go MAEDA, 2023-04-12 16:27

Related issues

Related to Redmine - Defect #37166: Roles of a project member should not be made emptyClosedGo MAEDA

Actions
Actions #1

Updated by Go MAEDA about 1 year ago

  • Related to Defect #37166: Roles of a project member should not be made empty added
Actions #2

Updated by Go MAEDA about 1 year ago

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)
Actions #3

Updated by Go MAEDA about 1 year ago

A patch to fix the issue.

Actions #4

Updated by Go MAEDA about 1 year ago

  • Target version set to 5.0.6

Setting the target version to 5.0.6.

Actions #5

Updated by Go MAEDA about 1 year ago

  • Status changed from New to Resolved

Committed the patch in r22180.

Actions #6

Updated by Go MAEDA about 1 year ago

  • Status changed from Resolved to Closed
  • Assignee set to Go MAEDA
  • Resolution set to Fixed
Actions

Also available in: Atom PDF