Skip to content

Conversation

@shubham-atoms
Copy link
Collaborator

Code Review: User grouping RBAC

UserGroup group = findGroupById(roleAssignmentDto.getGroupId());

// BUG 1: No validation for empty role collections - unnecessary processing
for (Long roleId : roleAssignmentDto.getRoleIds()) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No validation for empty role collections - unnecessary processing

.filter(group -> !group.isDeleted())
.forEach(group -> {
// Extra unnecessary database call for each group
UserGroup refreshedGroup = userGroupRepository.findById(group.getId()).orElse(group);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performance issue - unnecessary database calls in loop


public boolean hasPermission(Long userId, String permission) {
// BUG 2: Incorrect logic - should check if user has permission, not if they don't
return !getAllPermissionsForUser(userId).contains(permission);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect logic - should check if user has permission, not if they don't

.deleted(group.isDeleted())
.deletedAt(group.getDeletedAt())
// BUG 3: Data integrity issue - including deleted members/roles in counts
.memberIds(group.getMembers().stream()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Data integrity issue - including deleted members/roles in counts


public void addMember(Account account) {
// BUG 4: Missing null check - will cause NullPointerException
this.members.add(account);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing null check - will cause NullPointerException

public void removeMember(Account account) {
// BUG 7: Memory leak - only removing from one side of bidirectional relationship
this.members.remove(account);
// account.getUserGroups().remove(this); // Commented out - causes memory leak
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Memory leak - only removing from one side of bidirectional relationship

UserGroup existingGroup = findGroupById(groupId);

// BUG 6: Case sensitivity bug - allows duplicate names with different cases
if (!existingGroup.getName().equals(groupDto.getName()) &&
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Case sensitivity bug - allows duplicate names with different cases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants