gitlab: get all projects/groups of a member

Viewed 2344

I'm trying to find inactive members in my GitLab-CE instance via the Gitlab API (v4).

One of the criteria for "(in)activity" is, whether a given user is member of any project or group.

While this information seems to be readily available via the webinterface (Groups and projects tab on the user's overview page in the admin area), I cannot find that information via the API.

The only way i currently found is, to iterate over all projects (resp. groups) and check whether the user is member thereof.

This strikes me as very slow (as there are probably zillions of projects), so I'm looking for a more direct way to query the system for all projects where user is member-of.

1 Answers

As in doc(https://docs.gitlab.com/ce/api/members.html), you can use:

GET /groups/:id/members
GET /projects/:id/members

to get only members added directly in a group/project

or:

GET /groups/:id/members/all
GET /projects/:id/members/all

to get all members (even those inherit from groups above)

---EDIT regards to @Nico question ---

In order to know if a user is a member of a project the solution tested by @umläute is to iterate over project members then all subgroup untill it reaches the user:

Given \fu\bar\project_p
With project_p.id = 1
        bar.id = 10
        fu.id = 100
Is user 'Nico' a member of project_p ?
    GET /projects/1/members returns ('Paul') / No
    GET /groups/10/members returns ('Marc', 'Jean') / No
    GET /groups/100/members returns ('Nico') / Yes

Instead Gitlab provide an other API :

GET /projects/1/members/all returns ('Paul', 'Marc', 'Jean', 'Nico') / Yes
Related