MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / ListMembers

Method ListMembers

app/controlplane/pkg/data/group.go:128–181  ·  view source on GitHub ↗

ListMembers retrieves the members of a group, optionally filtering by maintainers.

(ctx context.Context, orgID uuid.UUID, groupID uuid.UUID, opts *biz.ListMembersOpts, paginationOpts *pagination.OffsetPaginationOpts)

Source from the content-addressed store, hash-verified

126
127// ListMembers retrieves the members of a group, optionally filtering by maintainers.
128func (g GroupRepo) ListMembers(ctx context.Context, orgID uuid.UUID, groupID uuid.UUID, opts *biz.ListMembersOpts, paginationOpts *pagination.OffsetPaginationOpts) ([]*biz.GroupMembership, int, error) {
129 ctx, span := otelx.Start(ctx, groupRepoTracer, "GroupRepo.ListMembers")
130 defer span.End()
131
132 if paginationOpts == nil {
133 paginationOpts = pagination.NewDefaultOffsetPaginationOpts()
134 }
135
136 // Check the group exists in the organization
137 _, err := g.data.DB.Group.Query().
138 Where(group.ID(groupID), group.OrganizationIDEQ(orgID), group.DeletedAtIsNil()).
139 Only(ctx)
140 if err != nil {
141 if ent.IsNotFound(err) {
142 return nil, 0, biz.NewErrNotFound("group")
143 }
144 return nil, 0, err
145 }
146
147 // Build the query to list members of the group
148 query := g.data.DB.GroupMembership.Query().
149 Where(groupmembership.GroupID(groupID), groupmembership.DeletedAtIsNil())
150
151 if opts != nil && opts.Maintainers != nil {
152 query.Where(groupmembership.MaintainerEQ(*opts.Maintainers))
153 }
154
155 if opts != nil && opts.MemberEmail != nil {
156 query.Where(groupmembership.HasUserWith(user.EmailContains(*opts.MemberEmail)))
157 }
158
159 // Get the count of all filtered rows without the limit and offset
160 count, err := query.Count(ctx)
161 if err != nil {
162 return nil, 0, err
163 }
164
165 members, err := query.
166 Order(ent.Desc(workflow.FieldCreatedAt)).
167 WithUser().
168 Limit(paginationOpts.Limit()).
169 Offset(paginationOpts.Offset()).
170 All(ctx)
171 if err != nil {
172 return nil, 0, err
173 }
174
175 bizMembers := make([]*biz.GroupMembership, 0, len(members))
176 for _, member := range members {
177 bizMembers = append(bizMembers, entGroupMembershipToBiz(member))
178 }
179
180 return bizMembers, count, nil
181}
182
183// ListPendingInvitationsByGroup retrieves pending invitations for a specific group in an organization.
184func (g GroupRepo) ListPendingInvitationsByGroup(ctx context.Context, orgID uuid.UUID, groupID uuid.UUID, paginationOpts *pagination.OffsetPaginationOpts) ([]*biz.OrgInvitation, int, error) {

Callers

nothing calls this directly

Implementers 1

GroupRepoapp/controlplane/pkg/data/group.go

Calls 15

StartFunction · 0.92
IDFunction · 0.92
OrganizationIDEQFunction · 0.92
DeletedAtIsNilFunction · 0.92
IsNotFoundFunction · 0.92
NewErrNotFoundFunction · 0.92
GroupIDFunction · 0.92
DeletedAtIsNilFunction · 0.92
MaintainerEQFunction · 0.92
HasUserWithFunction · 0.92
EmailContainsFunction · 0.92

Tested by

no test coverage detected