跳转至

修改企业成员权限

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

用户调用此接口,修改指定企业中某个成员的访问权限(角色)。

访问令牌支持说明

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

是否允许匿名访问

此接口不允许匿名访问

请求参数

参数名 位置 类型 必填 说明
enterprise path string 是 企业 id(也兼容企业、组织或个人的地址 path)
username path string 是 用户名(username/login)
access_token query string 是 用户授权码

Request Body:

请求体支持 application/json(字段采用 snake_case)与 application/x-www-form-urlencoded / multipart/form-data 表单两种方式传递。

{
  "$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 是 是 成员是否处于有效状态(根据成员有效期与当前时间比较得出)
organization object 否 是 企业(组织)信息
organization_url string 否 是 企业(组织)URL
remark string 是 是 备注,当前返回 null
role string 是 是 成员角色名称(如 member / admin)
url string 是 否 成员在当前企业下的 URL
user object 是 否 成员用户信息

organization 对象

字段 类型 必返 可为空 说明
organization.id integer 否 是 企业(组织)ID
organization.login string 否 是 企业(组织)登录名
organization.name string 否 是 企业(组织)名称
organization.url string 否 是 企业(组织)URL
organization.avatar_url string 否 是 企业(组织)头像 URL
organization.repos_url string 否 是 企业(组织)仓库列表 URL
organization.events_url string 否 是 企业(组织)动态 URL
organization.members_url string 否 是 企业(组织)成员列表 URL
organization.description string 否 是 企业(组织)描述
organization.follow_count integer 否 是 关注者数量

user 对象

字段 类型 必返 可为空 说明
user.id integer 是 否 用户 ID
user.login string 是 否 用户名(username/login)
user.name string 否 是 用户昵称
user.avatar_url string 否 是 用户头像 URL
user.url string 是 否 用户 URL
user.html_url string 是 否 用户主页 URL
user.remark string 是 是 备注,当前返回 null

失败响应

400 参数错误

{
  "error": "bad_request",
  "message": "role:'xxx' invalid"
}

当传入的 role 取值不在 viewer / tester / developer / maintainer / admin / customized 中时,返回参数错误。

404 用户不存在

{
  "error": "not_path",
  "message": "user 'xxx' not found"
}

当指定的 username 对应的用户不存在时,返回该错误。

401 未认证

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

HTTP 响应状态码

状态码 说明
200 成功(OK)
400 参数错误(Bad Request)
401 需要认证(Requires authentication)
404 资源不存在(Not Found)

请求示例

参数说明

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

cURL

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

JavaScript

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

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/v8/enterprises/<enterprise>/members/<username>",
    params={"access_token": "<token>"},
    json={
        "role": "maintainer",
        "role_id": "",
    },
    timeout=10,
)
resp.raise_for_status()

print(resp.json())

响应示例

状态码: 200

{
  "active": true,
  "role": "admin",
  "url": "https://api.atomgit.com/api/v8/enterprises/litestabc/members/malongge5",
  "user": {
    "id": 953,
    "login": "malongge5",
    "name": "马龙哥",
    "avatar_url": "https://api.atomgit.com/avatar.png",
    "url": "https://api.atomgit.com/api/v5/malongge5",
    "html_url": "https://api.atomgit.com/malongge5"
  }
}

错误码

错误码 说明
401 未认证或凭证无效(缺少/无效的访问凭证)
400 参数错误或请求无法解析
404 请求路径不存在或用户不存在
405 请求方法不支持
429 请求过于频繁,触发限流
500 系统内部错误

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