SpaceRole
最后更新:2026年6月22日
SpaceRole 是授予 Space 成员的一组权限。它在单个资源中规定了对 Content Type、Content、Media 可以执行哪些操作(读取、创建、编辑、删除、发布),以及是否可以访问 Space 设置。将权限范围收窄(例如仅限某个 Content Type、仅限自己创建的内容)的过滤器也在 SpaceRole 内部设定。
创建出来的 SpaceRole 本身不会应用于任何人。要将它授予成员,需将该 SpaceRole 的 Refer 放入 Space Membership 的 roles 中。一个成员可以同时拥有多个 SpaceRole。此外,DeliveryAccessToken 也会绑定到一个 least-privilege(最小权限)SpaceRole,由它决定该令牌可以交付的范围。
资源结构
下面是 SpaceRole “商品只读” 的单条查询响应。除了 sys(系统属性)之外,它还拥有用于规定权限的正文属性 contentType、content、media、settings。
{
"sys": {
"id": "3trmXRM3RqbgSnifyg7ObyNrQQbHbm",
"type": "SpaceRole",
"space": { "sys": { "id": "HnQ32YiH", "type": "Refer", "targetType": "Space" } },
"createdBy": { "sys": { "id": "3p4tcFbQRwz503VXdtHXNI5dZH5TVB", "type": "Refer", "targetType": "User" } },
"createdAt": "2026-06-16T09:53:16.617Z",
"updatedBy": { "sys": { "id": "3p4tcFbQRwz503VXdtHXNI5dZH5TVB", "type": "Refer", "targetType": "User" } },
"updatedAt": "2026-06-16T09:53:16.617Z",
"isLocked": false,
"version": 1
},
"name": "商品只读",
"contentType": { "All": { "Allow": [] } },
"content": {
"Read": {
"Allow": [
{ "contentType": { "sys": { "id": "3trmXRLdJF4GBlAjtcuoZ7Pnxj8dlA", "type": "Refer", "targetType": "ContentType" } } }
]
}
},
"media": { "All": { "Allow": [] } },
"settings": []
}主要键:
contentType:对 Content Type 本身(schema)的权限映射。按操作分别规定读取、创建、修改、删除、发布 Content Type 的权限。content:对 Content(内容数据)的权限映射。上面的示例展示了只允许读取某个特定 Content Type 的 Content 的情形。media:对 Media(文件、图片)的权限映射。settings:规定 Space 设置访问权限的字符串数组。完全访问为["SETTING_ALL"],不授予任何设置访问权限则为[]。isLocked:为true时,表示这是 Weegloo 默认提供的角色(例如 Administrator),因此无法修改或删除。
系统属性 (sys)
每个 SpaceRole 都将公共系统属性放在 sys 对象中。space、createdBy、updatedBy 以 Refer 形式({ "sys": { "id", "type": "Refer", "targetType" } })出现。
| 属性 | 类型 | 说明 |
|---|---|---|
id | string | 资源的唯一标识符。 |
type | string | 资源种类。SpaceRole 始终为 "SpaceRole"。 |
space | Refer<Space> | 此 SpaceRole 所属的 Space。 |
createdBy | Refer<User> | 创建者用户。 |
createdAt | string (date-time) | 创建时间。 |
updatedBy | Refer<User> | 最后修改者用户。 |
updatedAt | string (date-time) | 最后修改时间。 |
isLocked | boolean | 为 true 时表示是默认提供的角色,无法修改或删除。自行创建的角色为 false。 |
version | integer (≥1) | 资源版本。每次修改递增 1。 |
SpaceRole 是没有发布概念的设置类资源。因此与 Content、Media 不同,其 sys 中没有 publish、archive、status,只有 version。每次修改 SpaceRole 时 version 都会递增。
权限映射:contentType、content、media
contentType、content、media 各自都是以操作为键的映射。操作为 Read(读取)、Create(创建)、Edit(编辑)、Delete(删除)、Publish(发布),另外还有一次性指代所有操作的 All。每个操作的值是一个包含 Allow(允许)和 Deny(拒绝)规则数组的对象。
"content": {
"Read": { "Allow": [ /* 规则 */ ], "Deny": [ /* 规则 */ ] },
"Edit": { "Allow": [ /* 规则 */ ] }
}每个规则(rule)对象都带有用于收窄权限范围的可选过滤器。
contentType:将该规则适用的对象限定为某个特定的 Content Type。放入指向 Content Type 的Refer。createdBy:仅限定为某个特定用户创建的资源。在sys.id中填入某个用户 id 则仅限其创建的内容;填入保留值:self则限定为“仅当前调用者创建的内容”。tag:仅限定为带有某个特定 Tag 的资源。
空的 Allow 数组 [] 表示对该种类的全部资源允许该操作。由于过滤器为空,没有可过滤的内容,因此该操作对所有资源开放。
示例 1:Administrator(全部权限,默认提供)
Administrator 角色对 contentType、content、media 都在 All 操作上给出空的 Allow 以允许全部,并在 settings 中给出 ["SETTING_ALL"] 以访问 Space 设置的全部内容。该角色由 Weegloo 默认提供,因此 sys.isLocked 为 true,无法修改或删除。
{
"sys": {
"id": "3trmXRLdJF4GBlAjtcuoWfVubsasp4",
"type": "SpaceRole",
"space": { "sys": { "id": "HnQ32YiH", "type": "Refer", "targetType": "Space" } },
"createdBy": { "sys": { "id": "_", "type": "Refer", "targetType": "User" } },
"createdAt": "2026-06-14T14:56:04.737Z",
"updatedBy": { "sys": { "id": "_", "type": "Refer", "targetType": "User" } },
"updatedAt": "2026-06-14T14:56:04.737Z",
"isLocked": true,
"version": 1
},
"name": "Administrator",
"description": "Members of this role have full access to everything in this space.",
"contentType": { "All": { "Allow": [] } },
"content": { "All": { "Allow": [] } },
"media": { "All": { "Allow": [] } },
"settings": ["SETTING_ALL"]
}示例 2:只读(仅限某个 Content Type)
这是自行创建的 least-privilege 角色的示例。仅在 content 的 Read 操作上设置规则,并通过该规则的 contentType 过滤器限定为某一个 Content Type。Content Type 本身和 Media 都以空的 Allow 在 All 上开放,但对内容数据只能读取这一个种类。由于 settings 为 [],因此无法访问 Space 设置。将这样的角色绑定到 DeliveryAccessToken,交付令牌就只会读取该范围。该角色的 JSON 与上面资源结构中的 “商品只读” 相同。
settings(Space 设置访问)
settings 不是权限映射,而是字符串数组。它存放对 Space 设置的访问权限:完全访问为 ["SETTING_ALL"],不授予任何访问权限则设为 []。
操作列表(
Read、Create、Edit、Delete、Publish、All)与过滤器键(contentType、createdBy、tag)以及:self的含义,均以weegloo-space-role权限规则定义为准。
API
以下所有端点的基准 URL 均为 https://cma.weegloo.com/v1,并需要在 Authorization 头中携带用于认证 CMA 的 Bearer 令牌。修改角色(PUT、PATCH)时,为实现乐观并发控制,必须一并发送 X-Weegloo-Version 头(当前资源的 sys.version)。创建和删除没有该头。sys.isLocked 为 true 的默认提供角色无法修改或删除。
相关文档
- Space Membership:将 SpaceRole 绑定到成员的
roles。 - Delivery Access Token:绑定到 least-privilege SpaceRole 的交付令牌。
- Content Type:权限规则所指向的 Content Type。
