Group and project members API

原文:https://docs.gitlab.com/ee/api/members.html

Group and project members API

Valid access levels

访问级别在Gitlab::Access模块中定义. 当前,这些级别被认可:

  • 无法访问( 0
  • 宾客( 10
  • 记者( 20
  • 显影剂( 30
  • 养护者( 40
  • 所有者( 50 )-仅对组有效

注意:由于存在问题 ,个人名称空间中的项目将不会显示所有者( 50 )所有者的权限.

List all members of a group or project

获取可通过身份验证的用户查看的组或项目成员的列表. 仅返回直接成员,而不返回通过祖先组继承的成员.

此函数使用分页参数pageper_page来限制用户列表.

  1. GET /groups/:id/members
  2. GET /projects/:id/members
Attribute Type Required Description
id integer/string yes 经过身份验证的用户拥有的项目或组的 ID 或URL 编码路径
query string no 查询字符串以搜索成员
user_ids 整数数组 no 根据给定的用户 ID 过滤结果
  1. curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/:id/members"
  2. curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/:id/members"

响应示例:

  1. [ { "id": 1, "username": "raymond_smith", "name": "Raymond Smith", "state": "active", "avatar_url": "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon", "web_url": "http://192.168.1.8:3000/root", "expires_at": "2012-10-22T14:13:35Z", "access_level": 30, "group_saml_identity": null }, { "id": 2, "username": "john_doe", "name": "John Doe", "state": "active", "avatar_url": "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon", "web_url": "http://192.168.1.8:3000/root", "expires_at": "2012-10-22T14:13:35Z", "access_level": 30, "email": "john@example.com", "group_saml_identity": { "extern_uid":"ABC-1234567890", "provider": "group_saml", "saml_provider_id": 10 } } ]

List all members of a group or project including inherited members

获取可通过身份验证的用户查看的组或项目成员的列表,包括通过祖先组继承的成员. 当用户是项目/组和一个或多个祖先组的成员时,仅以项目access_level (如果存在)或用户所属项目组中第一个组的用户的access_level返回一次祖先链.

此函数使用分页参数pageper_page来限制用户列表.

  1. GET /groups/:id/members/all
  2. GET /projects/:id/members/all
Attribute Type Required Description
id integer/string yes 经过身份验证的用户拥有的项目或组的 ID 或URL 编码路径
query string no 查询字符串以搜索成员
user_ids 整数数组 no 根据给定的用户 ID 过滤结果
  1. curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/:id/members/all"
  2. curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/:id/members/all"

响应示例:

  1. [ { "id": 1, "username": "raymond_smith", "name": "Raymond Smith", "state": "active", "avatar_url": "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon", "web_url": "http://192.168.1.8:3000/root", "expires_at": "2012-10-22T14:13:35Z", "access_level": 30, "group_saml_identity": null }, { "id": 2, "username": "john_doe", "name": "John Doe", "state": "active", "avatar_url": "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon", "web_url": "http://192.168.1.8:3000/root", "expires_at": "2012-10-22T14:13:35Z", "access_level": 30 "email": "john@example.com", "group_saml_identity": { "extern_uid":"ABC-1234567890", "provider": "group_saml", "saml_provider_id": 10 } }, { "id": 3, "username": "foo_bar", "name": "Foo bar", "state": "active", "avatar_url": "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon", "web_url": "http://192.168.1.8:3000/root", "expires_at": "2012-11-22T14:13:35Z", "access_level": 30, "group_saml_identity": null } ]

Get a member of a group or project

获取组或项目的成员. 仅返回直接成员,而不返回通过祖先组继承的成员.

  1. GET /groups/:id/members/:user_id
  2. GET /projects/:id/members/:user_id
Attribute Type Required Description
id integer/string yes 经过身份验证的用户拥有的项目或组的 ID 或URL 编码路径
user_id integer yes 成员的用户标识
  1. curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/:id/members/:user_id"
  2. curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/:id/members/:user_id"

响应示例:

  1. { "id": 1, "username": "raymond_smith", "name": "Raymond Smith", "state": "active", "avatar_url": "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon", "web_url": "http://192.168.1.8:3000/root", "access_level": 30, "expires_at": null, "group_saml_identity": null }

Get a member of a group or project, including inherited members

在 GitLab 12.4 中引入 .

获取组或项目的成员,包括通过祖先组继承的成员. 有关详细信息,请参见相应的端点以列出所有继承的成员 .

  1. GET /groups/:id/members/all/:user_id
  2. GET /projects/:id/members/all/:user_id
Attribute Type Required Description
id integer/string yes 经过身份验证的用户拥有的项目或组的 ID 或URL 编码路径
user_id integer yes 成员的用户标识
  1. curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/:id/members/all/:user_id"
  2. curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/:id/members/all/:user_id"

响应示例:

  1. { "id": 1, "username": "raymond_smith", "name": "Raymond Smith", "state": "active", "avatar_url": "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon", "web_url": "http://192.168.1.8:3000/root", "access_level": 30, "expires_at": null, "group_saml_identity": null }

Add a member to a group or project

将成员添加到组或项目.

  1. POST /groups/:id/members
  2. POST /projects/:id/members
Attribute Type Required Description
id integer/string yes 经过身份验证的用户拥有的项目或组的 ID 或URL 编码路径
user_id integer yes 新成员的用户标识
access_level integer yes 有效的访问级别
expires_at string no 日期格式为 YEAR-MONTH-DAY 的日期字符串
  1. curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" --data "user_id=1&access_level=30" "https://gitlab.example.com/api/v4/groups/:id/members"
  2. curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" --data "user_id=1&access_level=30" "https://gitlab.example.com/api/v4/projects/:id/members"

响应示例:

  1. { "id": 1, "username": "raymond_smith", "name": "Raymond Smith", "state": "active", "avatar_url": "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon", "web_url": "http://192.168.1.8:3000/root", "expires_at": "2012-10-22T14:13:35Z", "access_level": 30, "group_saml_identity": null }

Edit a member of a group or project

更新组或项目的成员.

  1. PUT /groups/:id/members/:user_id
  2. PUT /projects/:id/members/:user_id
Attribute Type Required Description
id integer/string yes 经过身份验证的用户拥有的项目或组的 ID 或URL 编码路径
user_id integer yes 成员的用户标识
access_level integer yes 有效的访问级别
expires_at string no 日期格式为 YEAR-MONTH-DAY 的日期字符串
  1. curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/:id/members/:user_id?access_level=40"
  2. curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/:id/members/:user_id?access_level=40"

响应示例:

  1. { "id": 1, "username": "raymond_smith", "name": "Raymond Smith", "state": "active", "avatar_url": "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon", "web_url": "http://192.168.1.8:3000/root", "expires_at": "2012-10-22T14:13:35Z", "access_level": 40, "group_saml_identity": null }

Set override flag for a member of a group

在 GitLab 13.0 中引入 .

默认情况下,LDAP 组成员的访问级别设置为 LDAP 通过组同步指定的值. 您可以通过调用此端点来允许访问级别替代.

  1. POST /groups/:id/members/:user_id/override
Attribute Type Required Description
id integer/string yes 认证用户拥有的组的 ID 或URL 编码路径
user_id integer yes 成员的用户标识
  1. curl --request PUT --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/groups/:id/members/:user_id/override"

响应示例:

  1. { "id": 1, "username": "raymond_smith", "name": "Raymond Smith", "state": "active", "avatar_url": "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon", "web_url": "http://192.168.1.8:3000/root", "expires_at": "2012-10-22T14:13:35Z", "access_level": 40, "override": true }

Remove override for a member of a group

在 GitLab 13.0 中引入 .

将替代标志设置为 false,并允许 LDAP 组同步将访问级别重置为 LDAP 指定的值.

  1. DELETE /groups/:id/members/:user_id/override
Attribute Type Required Description
id integer/string yes 认证用户拥有的组的 ID 或URL 编码路径
user_id integer yes 成员的用户标识
  1. curl --request PUT --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/groups/:id/members/:user_id/override"

响应示例:

  1. { "id": 1, "username": "raymond_smith", "name": "Raymond Smith", "state": "active", "avatar_url": "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon", "web_url": "http://192.168.1.8:3000/root", "expires_at": "2012-10-22T14:13:35Z", "access_level": 40, "override": false }

Remove a member from a group or project

从组或项目中删除用户.

  1. DELETE /groups/:id/members/:user_id
  2. DELETE /projects/:id/members/:user_id
Attribute Type Required Description
id integer/string yes 经过身份验证的用户拥有的项目或组的 ID 或URL 编码路径
user_id integer yes 成员的用户标识
unassign_issuables boolean false 标志,指示是否应从给定的组或项目内取消分配任何问题或合并请求的已删除成员
  1. curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/:id/members/:user_id"
  2. curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/:id/members/:user_id"

Give a group access to a project

See share project with group