webiny-admin-permissions
它能做什么
这项技能在你的 AI 为 Webiny 管理界面添加权限控制时提供指导。适合需要限制用户在管理面板中可见或可操作内容的开发者。
适用场景
- ✓当你需要为 Webiny 管理功能添加权限设置的时候。
- ✓当你希望根据 schema 生成权限表单,而不是手写的时候。
- ✓当管理界面的某部分需要根据用户权限显示或隐藏的时候。
技能链接
https://github.com/webiny/webiny-js/blob/next/skills/user-skills/admin/admin-permissions/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请在 Webiny 管理端为我的产品板块添加权限控制,编辑和导入分别设置不同的规则。”
每周 5 个新技能,1 分钟读完。
工作原理
技能说明如何定义权限 schema,它会生成权限表单。它还涵盖可注入的权限检查,以及用于显示或隐藏界面部分的组件。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Admin Permissions
Overview
Permissions follow three layers: domain (schema), features (DI artifacts + registration), and presentation (hooks, components, UI config). The framework auto-generates the permission UI from a schema and provides injectable permission checking via the DI container.
Layer 1: Domain — Permission Schema
Define the schema in src/domain/permissionsSchema.ts:
import { createPermissionSchema } from "webiny/admin/security";
export const SM_PERMISSIONS_SCHEMA = createPermissionSchema({
prefix: "sm",
fullAccess: true,
entities: [
{
id: "product",
title: "Products",
permission: "sm.product",
scopes: ["full", "own"],
actions: [
{ name: "rwd" },
{ name: "pw" },
{ name: "import", label: "Import products" },
{ name: "export", label: "Export products" }
]
},
{
id: "category",
title: "Categories",
permission: "sm.category",
scopes: ["full"],
actions: [{ name: "rwd" }]
},
{
id: "settings",
title: "Settings",
permission: "sm.settings",
scopes: ["full"]
}
]
});
Schema Reference
| Field | Type | Required | Description |
|---|---|---|---|
prefix |
string |
Yes | Permission prefix (e.g., "sm") |
fullAccess |
true | object |
Yes | true for standard full access. Pass an object with custom boolean flags for full-access extras (e.g., { canForceUnlock: true }). |
readOnlyAccess |
boolean |
No | Whether to show a "Read-only access" option |
entities |
EntityDefinition[] |
No | Entity definitions. Omit for binary full/no access. |
Entity Definition
| Field | Type | Required | Description |
|---|---|---|---|
id |
string |
Yes | Unique identifier for form field naming |
title |
string |
No | Display title. Falls back to id. |
permission |
string |
Yes | Permission name emitted (e.g., "sm.product") |
scopes |
("full" | "own")[] |
Yes | Available access scopes |
actions |
ActionDefinition[] |
No | Actions on this entity |
dependsOn |
{ entity: string; requires: string } |
No | Dependency on another entity |
Actions
{ name: "rwd" }— Read/Write/Delete select dropdown. Auto-set to"rwd"when scope is"own".{ name: "pw" }— Publish/Unpublish checkbox group.{ name: "custom", label: "Label" }— Custom boolean flag.
Entity Dependencies
Child entities can depend on a parent. If the parent lacks the required action, the child is pruned from output. "own" scope cascades to dependents.
{
id: "review",
permission: "sm.review",
scopes: ["full", "own"],
actions: [{ name: "rwd" }],
dependsOn: { entity: "product", requires: "r" }
}
Simple Apps (No Entities)
Omit entities for binary full/no access:
export const MA_PERMISSIONS_SCHEMA = createPermissionSchema({
prefix: "ma",
fullAccess: true
});
Layer 2: Features — DI Artifacts + Registration
Abstraction (src/features/permissions/abstractions.ts)
import { createPermissionsAbstraction } from "webiny/admin/security";
import type { Permissions } from "webiny/admin/security";
import { SM_PERMISSIONS_SCHEMA } from "~/domain/permissionsSchema.js";
export const SmPermissions = createPermissionsAbstraction(SM_PERMISSIONS_SCHEMA);
export namespac
常见问题
权限 schema 有什么作用?
它定义实体、它们的操作和范围,管理端表单由它生成。
代码中如何检查权限?
技能描述了可注入的权限检查,以及供组件使用的带类型 hook。
它也涵盖服务端吗?
技能重点在管理界面及该层的权限检查。
详情
作者的原始描述
Admin-side permission UI registration and DI-backed permission checking. Use this skill when adding permission controls to the admin UI — schema-based auto-generated forms, injectable permissions via createPermissionsAbstraction/ createPermissionsFeature, typed hooks (createUsePermissions), the HasPermission component (createHasPermission), and the Security.Permissions component props. Covers both simple apps and complex multi-entity permission schemas.
repo: webiny/webiny-js
热度
- GitHub 星标
- 8.1k
- 排名
- #12575
- 许可证
- —
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
prd-to-plan
8.1k帮你的智能体把产品需求文档转化为分阶段的计划,由许多小的端到端切片组成,并保存为 Markdown 文件。
webiny-admin-architect
8.1k教你的智能体如何为 Webiny 平台构建管理界面,使用其业务逻辑层和呈现器模式。
webiny-form-model
8.1k教你的智能体使用声明式字段构建器、布局、校验和条件规则,在 Webiny 中构建表单。
webiny-new-entry-wizard
8.1k教你的智能体为 Webiny CMS 的新条目添加自定义设置向导,先收集几个字段,再预填条目表单。