335.md 14.2 KB
Newer Older
Lab机器人's avatar
readme  
Lab机器人 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
# Group and project members API

> 原文:[https://docs.gitlab.com/ee/api/members.html](https://docs.gitlab.com/ee/api/members.html)

*   [Valid access levels](#valid-access-levels)
*   [List all members of a group or project](#list-all-members-of-a-group-or-project)
*   [List all members of a group or project including inherited members](#list-all-members-of-a-group-or-project-including-inherited-members)
*   [Get a member of a group or project](#get-a-member-of-a-group-or-project)
*   [Get a member of a group or project, including inherited members](#get-a-member-of-a-group-or-project-including-inherited-members)
*   [Add a member to a group or project](#add-a-member-to-a-group-or-project)
*   [Edit a member of a group or project](#edit-a-member-of-a-group-or-project)
    *   [Set override flag for a member of a group](#set-override-flag-for-a-member-of-a-group)
    *   [Remove override for a member of a group](#remove-override-for-a-member-of-a-group)
*   [Remove a member from a group or project](#remove-a-member-from-a-group-or-project)
*   [Give a group access to a project](#give-a-group-access-to-a-project)

# Group and project members API[](#group-and-project-members-api "Permalink")

## Valid access levels[](#valid-access-levels "Permalink")

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

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

**注意:**由于[存在问题](https://gitlab.com/gitlab-org/gitlab/-/issues/219299) ,个人名称空间中的项目将不会显示所有者( `50` )所有者的权限.

## List all members of a group or project[](#list-all-members-of-a-group-or-project "Permalink")

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

此函数使用分页参数`page``per_page`来限制用户列表.

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

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目或组](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `query` | string | no | 查询字符串以搜索成员 |
| `user_ids` | 整数数组 | no | 根据给定的用户 ID 过滤结果 |

```
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/:id/members"
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/:id/members" 
```

响应示例:

```
[  {  "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[](#list-all-members-of-a-group-or-project-including-inherited-members "Permalink")

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

此函数使用分页参数`page``per_page`来限制用户列表.

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

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目或组](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `query` | string | no | 查询字符串以搜索成员 |
| `user_ids` | 整数数组 | no | 根据给定的用户 ID 过滤结果 |

```
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/:id/members/all"
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/:id/members/all" 
```

响应示例:

```
[  {  "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[](#get-a-member-of-a-group-or-project "Permalink")

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

```
GET /groups/:id/members/:user_id
GET /projects/:id/members/:user_id 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目或组](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `user_id` | integer | yes | 成员的用户标识 |

```
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/:id/members/:user_id"
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/:id/members/:user_id" 
```

响应示例:

```
{  "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[](#get-a-member-of-a-group-or-project-including-inherited-members "Permalink")

在 GitLab 12.4 中[引入](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/17744) .

获取组或项目的成员,包括通过祖先组继承的成员. 有关详细信息,请参见相应的[端点以列出所有继承的成员](#list-all-members-of-a-group-or-project-including-inherited-members) .

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

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目或组](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `user_id` | integer | yes | 成员的用户标识 |

```
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/:id/members/all/:user_id"
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/:id/members/all/:user_id" 
```

响应示例:

```
{  "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[](#add-a-member-to-a-group-or-project "Permalink")

将成员添加到组或项目.

```
POST /groups/:id/members
POST /projects/:id/members 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目或组](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `user_id` | integer | yes | 新成员的用户标识 |
| `access_level` | integer | yes | 有效的访问级别 |
| `expires_at` | string | no | 日期格式为 YEAR-MONTH-DAY 的日期字符串 |

```
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"
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" 
```

响应示例:

```
{  "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[](#edit-a-member-of-a-group-or-project "Permalink")

更新组或项目的成员.

```
PUT /groups/:id/members/:user_id
PUT /projects/:id/members/:user_id 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目或组](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `user_id` | integer | yes | 成员的用户标识 |
| `access_level` | integer | yes | 有效的访问级别 |
| `expires_at` | string | no | 日期格式为 YEAR-MONTH-DAY 的日期字符串 |

```
curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/:id/members/:user_id?access_level=40"
curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/:id/members/:user_id?access_level=40" 
```

响应示例:

```
{  "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[](#set-override-flag-for-a-member-of-a-group "Permalink")

在 GitLab 13.0 中[引入](https://gitlab.com/gitlab-org/gitlab/-/issues/4875) .

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

```
POST /groups/:id/members/:user_id/override 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 认证用户拥有[的组](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `user_id` | integer | yes | 成员的用户标识 |

```
curl --request PUT --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/groups/:id/members/:user_id/override" 
```

响应示例:

```
{  "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[](#remove-override-for-a-member-of-a-group "Permalink")

在 GitLab 13.0 中[引入](https://gitlab.com/gitlab-org/gitlab/-/issues/4875) .

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

```
DELETE /groups/:id/members/:user_id/override 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 认证用户拥有[的组](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `user_id` | integer | yes | 成员的用户标识 |

```
curl --request PUT --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/groups/:id/members/:user_id/override" 
```

响应示例:

```
{  "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[](#remove-a-member-from-a-group-or-project "Permalink")

从组或项目中删除用户.

```
DELETE /groups/:id/members/:user_id
DELETE /projects/:id/members/:user_id 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目或组](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `user_id` | integer | yes | 成员的用户标识 |
| `unassign_issuables` | boolean | false | 标志,指示是否应从给定的组或项目内取消分配任何问题或合并请求的已删除成员 |

```
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/:id/members/:user_id"
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[](#give-a-group-access-to-a-project "Permalink")

See [share project with group](projects.html#share-project-with-group)