ServiceUserRole
最后更新:2026年7月3日
ServiceUserRole 是分配给在产品中注册的 end-user,即 ServiceUser 的权限集合。它在一个资源中描述对 Content Type、Content、Media 可以执行哪些操作(读取、创建、编辑、删除、发布),以及把范围收窄为仅某些 Content Type、仅自己创建的内容等的过滤条件。该权限作用于 ServiceUser 调用的 ACMA/ACDA。
它与 SpaceRole 的定位不同。SpaceRole 是 Weegloo User(内容工作室用户)的权限集合,作用于 CMA/CDA;ServiceUserRole 是在产品中注册的 ServiceUser 的权限集合,作用于 ACMA/ACDA。创建出来的 ServiceUserRole 本身不会应用到任何人身上。需要把它指定到 ServiceLogin 的默认角色(defaultRole),或者绑定到 ServiceUser 的 roleOverride 才会生效。
资源结构
下面是 ServiceUserRole "买家" 的单个查询响应。它包含 sys(系统属性),以及用于定义权限的本体属性 contentType、content、media。
{
"sys": {
"id": "3trmXRLXeZN2RTHvVj3hFDN5546vbp",
"type": "ServiceUserRole",
"space": { "sys": { "id": "HnQ32YiH", "type": "Refer", "targetType": "Space" } },
"createdBy": { "sys": { "id": "3p4tcFbQRwz503VXdtHXNI5dZH5TVB", "type": "Refer", "targetType": "User" } },
"createdAt": "2026-06-18T12:40:36.944Z",
"updatedBy": { "sys": { "id": "3p4tcFbQRwz503VXdtHXNI5dZH5TVB", "type": "Refer", "targetType": "User" } },
"updatedAt": "2026-06-18T12:40:36.944Z",
"version": 1
},
"name": "买家",
"description": "可读取已发布商品的会员",
"contentType": { "All": { "Allow": [] } },
"content": {
"Read": {
"Allow": [
{ "contentType": { "sys": { "id": "3trmXRLdJF4GBlAjtcuoZ7Pnxj8dlA", "type": "Refer", "targetType": "ContentType" } } }
]
}
},
"media": { "All": { "Allow": [] } }
}主要键:
contentType:针对 Content Type 本身(schema)的权限映射。按操作分别定义读取、创建、修改、删除、发布 Content Type 的权限。content:针对 Content(内容数据)的权限映射。上面的示例只允许读取特定 Content Type 的 Content。media:针对 Media(文件、图片)的权限映射。
与 SpaceRole 不同,ServiceUserRole 没有承载 Space 设置访问权限的 settings,因为 ServiceUser 不处理 Space 设置。此外也没有表示是否为内置项的 sys.isLocked。
系统属性 (sys)
所有 ServiceUserRole 都把公共系统属性放在 sys 对象中。space、createdBy、updatedBy 以 Refer 形态({ "sys": { "id", "type": "Refer", "targetType" } })出现。
| 属性 | 类型 | 说明 |
|---|---|---|
id | string | 资源唯一标识符。 |
type | string | 资源种类。ServiceUserRole 始终为 "ServiceUserRole"。 |
space | Refer<Space> | 此 ServiceUserRole 所属的 Space。 |
createdBy | Refer<User> | 创建者。 |
createdAt | string (date-time) | 创建时间。 |
updatedBy | Refer<User> | 最后修改者。 |
updatedAt | string (date-time) | 最后修改时间。 |
version | integer (≥1) | 资源版本。每次修改时加 1。 |
ServiceUserRole 是没有发布概念的设置类资源。因此与 Content、Media 不同,sys 中没有 publish、archive、status,只有 version。version 在每次修改 ServiceUserRole 时递增。与 SpaceRole 不同,它也没有 sys.isLocked。
权限映射:contentType、content、media
contentType、content、media 各自都是以操作为键的映射。操作有 Read(读取)、Create(创建)、Edit(编辑)、Delete(删除)、Publish(发布),以及一次性指代全部操作的 All。每个操作的值是一个包含 Allow(允许)和 Deny(拒绝)规则数组的对象。该权限映射结构与 SpaceRole 相同。
"content": {
"Read": { "Allow": [ /* 规则 */ ], "Deny": [ /* 规则 */ ] },
"Edit": { "Allow": [ /* 规则 */ ] }
}每个规则(rule)对象都带有用于收窄权限范围的可选过滤条件。
contentType:把该规则适用的对象限定为某一个 Content Type。填入指向 Content Type 的Refer。createdBy:限定为仅由特定用户创建的资源。在sys.id填入特定 id 表示仅限该用户创建的内容,填入保留值:self则限定为"仅当前调用的 ServiceUser 所创建的内容"。tag:限定为仅带有特定 Tag 的资源。
空的 Allow 数组 [] 表示对该种类的全部资源允许该操作。由于过滤条件为空、没有可过滤的内容,因此该操作对所有资源开放。
与 SpaceRole 不同,ServiceUserRole 没有 settings。权限映射只有 contentType、content、media 三种。操作列表、过滤键以及 :self 的含义等权限映射的编写方法,请一并参考使用相同结构的 SpaceRole 说明。使用 :self 把范围收窄为仅能编辑本人创建的 Content 的示例,见下方的 修改块。
操作列表(
Read、Create、Edit、Delete、Publish、All)、过滤键(contentType、createdBy、tag)以及:self的含义,均以weegloo-space-role权限规则定义为准。ServiceUserRole 的:self解析为仅限当前 ServiceUser 所创建的内容。
API
下面所有端点的基准 URL 都是 https://cma.weegloo.com/v1,并且需要在 Authorization 头中提供用于向 CMA 认证的 Bearer 令牌。修改角色(PUT、PATCH)时,为实现乐观并发控制,必须一并发送 X-Weegloo-Version 头(当前资源的 sys.version)。创建和删除不需要该头。
相关文档
- ServiceUser:领取此角色的注册会员(
roleOverride)。 - ServiceLogin:通过默认角色(
defaultRole)指定 ServiceUserRole。 - SpaceRole:面向 Weegloo User 的权限集合(相同的权限映射结构)。
