use GitLab group members REST API
Signed-off-by: Matteo Silvestri <matteosilv@gmail.com>
This commit is contained in:
@@ -2,6 +2,13 @@
|
||||
'@backstage/plugin-catalog-backend-module-gitlab': patch
|
||||
---
|
||||
|
||||
fix: use publicEmail in GitLab client
|
||||
fix: use REST API to get root group memberships for GitLab SaaS users listing
|
||||
|
||||
client was using commitEmail that is visible only for self-managed GitLab admins. publicEmail is visible, but only if the user explicitly enable the corresponding setting on GitLab.
|
||||
This API is the only one that shows `email` field for enterprise users and
|
||||
allows to filter out bot users not using a license using the `is_using_seat`
|
||||
field.
|
||||
|
||||
ref:
|
||||
|
||||
https://docs.gitlab.com/ee/user/enterprise_user/#get-users-email-addresses-through-the-api
|
||||
https://docs.gitlab.com/ee/api/members.html#limitations
|
||||
|
||||
@@ -91,6 +91,22 @@ export class GitLabClient {
|
||||
});
|
||||
}
|
||||
|
||||
async listSaaSUsers(
|
||||
groupPath: string,
|
||||
options?: CommonListOptions,
|
||||
): Promise<PagedResponse<GitLabUser>> {
|
||||
return this.pagedRequest(
|
||||
`/groups/${encodeURIComponent(groupPath)}/members`,
|
||||
{
|
||||
...options,
|
||||
show_seat_info: true,
|
||||
},
|
||||
).then(resp => {
|
||||
resp.items = resp.items.filter(user => user.is_using_seat);
|
||||
return resp;
|
||||
});
|
||||
}
|
||||
|
||||
async listGroups(
|
||||
options?: CommonListOptions,
|
||||
): Promise<PagedResponse<GitLabGroup>> {
|
||||
|
||||
+8
-6
@@ -190,12 +190,14 @@ export class GitlabOrgDiscoveryEntityProvider implements EntityProvider {
|
||||
});
|
||||
} else {
|
||||
groups = (await client.listDescendantGroups(this.config.group)).items;
|
||||
users = (
|
||||
await client.getGroupMembers(this.config.group.split('/')[0], [
|
||||
'DIRECT',
|
||||
'DESCENDANTS',
|
||||
])
|
||||
).items;
|
||||
const rootGroup = this.config.group.split('/')[0];
|
||||
users = paginated<GitLabUser>(
|
||||
options => client.listSaaSUsers(rootGroup, options),
|
||||
{
|
||||
page: 1,
|
||||
per_page: 100,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
const idMappedUser: { [userId: number]: GitLabUser } = {};
|
||||
|
||||
Reference in New Issue
Block a user