跳转至

修改企业成员权限

PUT /api/v5/enterprises/{enterprise}/members/{username}

该接口用于修改指定企业成员在企业中的角色权限,通过设置浏览者、测试人、研发、维护者、管理员或自定义角色等角色来调整成员的权限,并返回更新后的成员激活状态、角色及用户信息。

访问令牌支持说明

  • AtomGit 用户访问令牌(AtomGit user access tokens)

是否允许匿名访问

此接口不允许匿名访问

请求参数

参数名 位置 类型 必填 说明
enterprise path string 是 仓库所属空间地址(企业、组织或个人的地址path)
username path string 是 用户名(username/login)
access_token query string 是 用户授权码

Request Body:

请求体为 JSON 对象,用于设置成员在企业中的角色。

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "role": {
      "description": "企业角色(viewer:浏览者、tester:测试人、developer:研发、maintainer:维护者、admin:管理员、customized:自定义角色)",
      "type": "string",
      "enum": ["viewer", "tester", "developer", "maintainer", "admin", "customized"]
    },
    "role_id": {
      "description": "角色ID,如果 role 传入了 customized 则需要传入角色 id",
      "type": "string"
    }
  },
  "required": ["role"]
}

响应参数

字段 类型 必返 可为空 说明
active boolean 是 — 成员是否激活
role string 是 — 成员在企业中的角色
url string 是 — 成员信息地址
user object 是 — 成员对应的用户信息

user 对象

字段 类型 必返 可为空 说明
user.id integer 是 — 用户ID
user.login string 是 — 用户名
user.url string 是 — 用户信息地址
user.html_url string 是 — 用户主页地址

失败响应

除成功响应外,调用方还需了解失败时的返回形态,以便编写错误处理。

400 参数错误

{
  "error": "invalid_request",
  "message": "参数 role 不能为空",
  "field": "role"
}

401 未认证

{
  "error": "unauthorized",
  "message": "缺少或无效的访问令牌"
}

403 无权限

{
  "error": "forbidden",
  "message": "当前令牌无权修改该企业成员权限"
}

404 不存在

{
  "error": "not_found",
  "message": "企业或成员不存在"
}

错误字段名以后端实际返回为准。

HTTP 响应状态码

状态码 说明
200 成功(OK)
400 参数错误(Bad Request)
401 需要认证(Requires authentication)
403 禁止访问(Forbidden)
404 请求路径不存在

请求示例

参数说明

<enterprise> 替换为企业路径(企业、组织或个人的地址 path); <username> 替换为用户名(username/login); <token> 替换为你的 AtomGit 用户访问令牌。

cURL

curl -X PUT 'https://api.atomgit.com/api/v5/enterprises/<enterprise>/members/<username>?access_token=<token>' -H 'Accept: application/json' -H 'Content-Type: application/json' -d '{"role":"developer"}'

JavaScript

// 原生 fetch (Node.js 18+ / 浏览器)
const response = await fetch("https://api.atomgit.com/api/v5/enterprises/<enterprise>/members/<username>?access_token=<token>", {
  method: "PUT",
  headers: {
    "Accept": "application/json",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    role: "developer",
  }),
});

if (!response.ok) {
  throw new Error(`请求失败: ${response.status}`);
}

const data = await response.json();
console.log(data);

Python

import requests

resp = requests.put(
    "https://api.atomgit.com/api/v5/enterprises/<enterprise>/members/<username>",
    params={"access_token": "<token>"},
    json={"role": "developer"},
    timeout=10,
)
resp.raise_for_status()

print(resp.json())

响应示例

状态码: 200

{
  "active": true,
  "role": "member",
  "url": "https://api.atomgit.com/api/v5/enterprises/litestabc/members/malongge5",
  "user": {
    "id": 953,
    "login": "malongge5",
    "url": "https://api.atomgit.com/api/v5/malongge5",
    "html_url": "https://api.atomgit.com/malongge5"
  }
}

错误码

错误码 说明
400 参数错误或请求无法解析
401 未认证或凭证无效(缺少/无效的访问凭证)
403 禁止访问(当前令牌无权限执行该操作)
404 请求路径不存在
429 请求过于频繁,触发限流
500 系统内部错误

本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 gitcode-dev/atomgit-api-doc