Skip to content

Commit 3d4f4b3

Browse files
authored
chore(rbac): make requester optional (#2245)
Signed-off-by: Jose I. Paris <[email protected]>
1 parent b30655f commit 3d4f4b3

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

app/controlplane/pkg/biz/group.go

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -617,31 +617,33 @@ func (uc *GroupUseCase) RemoveMemberFromGroup(ctx context.Context, orgID uuid.UU
617617
return NewErrNotFound("group")
618618
}
619619

620-
// Check if the requester is part of the organization
621-
requesterMembership, err := uc.membershipRepo.FindByOrgAndUser(ctx, orgID, opts.RequesterID)
622-
if err != nil && !IsNotFound(err) {
623-
return NewErrValidationStr("failed to check existing membership")
624-
}
620+
if opts.RequesterID != uuid.Nil {
621+
// Check if the requester is part of the organization
622+
requesterMembership, err := uc.membershipRepo.FindByOrgAndUser(ctx, orgID, opts.RequesterID)
623+
if err != nil && !IsNotFound(err) {
624+
return NewErrValidationStr("failed to check existing membership")
625+
}
625626

626-
if requesterMembership == nil {
627-
return NewErrValidationStr("requester is not a member of the organization")
628-
}
627+
if requesterMembership == nil {
628+
return NewErrValidationStr("requester is not a member of the organization")
629+
}
629630

630-
// Check if the requester has sufficient permissions
631-
// Allow if the requester is an org owner or admin
632-
isAdminOrOwner := requesterMembership.Role == authz.RoleOwner || requesterMembership.Role == authz.RoleAdmin
631+
// Check if the requester has sufficient permissions
632+
// Allow if the requester is an org owner or admin
633+
isAdminOrOwner := requesterMembership.Role == authz.RoleOwner || requesterMembership.Role == authz.RoleAdmin
633634

634-
// If not an admin/owner, check if the requester is a maintainer of this group
635-
if !isAdminOrOwner {
636-
// Check if the requester is a maintainer of this group
637-
requesterGroupMembership, err := uc.membershipRepo.FindByUserAndResourceID(ctx, opts.RequesterID, resolvedGroupID)
638-
if err != nil && !IsNotFound(err) {
639-
return fmt.Errorf("failed to check requester's group membership: %w", err)
640-
}
635+
// If not an admin/owner, check if the requester is a maintainer of this group
636+
if !isAdminOrOwner {
637+
// Check if the requester is a maintainer of this group
638+
requesterGroupMembership, err := uc.membershipRepo.FindByUserAndResourceID(ctx, opts.RequesterID, resolvedGroupID)
639+
if err != nil && !IsNotFound(err) {
640+
return fmt.Errorf("failed to check requester's group membership: %w", err)
641+
}
641642

642-
// If not a maintainer of this group, deny access
643-
if requesterGroupMembership == nil || requesterGroupMembership.Role != authz.RoleGroupMaintainer {
644-
return NewErrValidationStr("requester does not have permission to add members to this group")
643+
// If not a maintainer of this group, deny access
644+
if requesterGroupMembership == nil || requesterGroupMembership.Role != authz.RoleGroupMaintainer {
645+
return NewErrValidationStr("requester does not have permission to add members to this group")
646+
}
645647
}
646648
}
647649

0 commit comments

Comments
 (0)