webiny-api-permissions
Skill này làm gì
Skill này hướng dẫn AI của bạn khi thêm quy tắc quyền vào mã backend trên Webiny. Dành cho lập trình viên cần kiểm soát ai được đọc, thay đổi hoặc xóa bản ghi.
Khi nào nên dùng
- ✓Khi một use case backend phải kiểm tra người dùng có được đọc, sửa, xóa hoặc xuất bản không.
- ✓Khi bản ghi nên bị giới hạn cho chủ sở hữu.
- ✓Khi bạn cần viết test cho các kịch bản quyền.
Liên kết skill
https://github.com/webiny/webiny-js/blob/next/skills/user-skills/api/permissions/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Chỉ cho phép người dùng sửa sản phẩm của chính họ trong Webiny API, và kiểm tra quyền trong use case cập nhật.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Skill giải thích cách định nghĩa một schema quyền cho mỗi khu vực, rồi inject một kiểm tra quyền có kiểu vào các use case. Các phương thức kiểm tra thay thế việc tra cứu quyền thủ công của người dùng.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
API Permissions
Overview
Permissions follow two layers: domain (schema) and features (DI abstractions + feature registration). Each package declares a permission schema and gets a typed Permissions abstraction injectable into use cases via DI. Methods like canRead, canEdit, canDelete, canPublish, onlyOwnRecords replace manual identityContext.getPermission() calls.
Layer 1: Domain — Permission Schema
Define the schema in src/domain/permissionsSchema.ts:
import { createPermissionSchema } from "webiny/api/security";
export const SM_PERMISSIONS_SCHEMA = createPermissionSchema({
prefix: "sm",
fullAccess: true,
entities: [
{
id: "product",
permission: "sm.product",
scopes: ["full", "own"],
actions: [{ name: "rwd" }, { name: "pw" }]
},
{
id: "settings",
permission: "sm.settings",
scopes: ["full"]
}
]
});
The schema MUST use as const inference (handled by createPermissionSchema) for TypeScript to narrow entity IDs in method signatures.
Schema Fields
| Field | Description |
|---|---|
prefix |
Namespaces the DI abstraction: ${prefix}:Permissions |
fullAccess |
true for standard full access. Pass an object with custom boolean flags for full-access extras (e.g., { canForceUnlock: true }). |
entities[].id |
Entity identifier used in method calls: canRead("product") |
entities[].permission |
Permission name matched against identity permissions |
entities[].scopes |
["full"] or ["full", "own"] — determines if own-scope supported |
entities[].actions |
Action definitions — built-in: "rwd", "pw"; custom: boolean flags |
Scopes
"full"— User can access all records (default when noownflag on permission object)"own"— User can only access records wherecreatedBy.id === identity.id
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/api/security";
import type { Permissions } from "webiny/api/security";
import { SM_PERMISSIONS_SCHEMA } from "~/domain/permissionsSchema.js";
export const SmPermissions = createPermissionsAbstraction(SM_PERMISSIONS_SCHEMA);
export namespace SmPermissions {
export type Interface = Permissions<typeof SM_PERMISSIONS_SCHEMA>;
}
Feature (src/features/permissions/feature.ts)
import { createPermissionsFeature } from "webiny/api/security";
import { SM_PERMISSIONS_SCHEMA } from "~/domain/permissionsSchema.js";
import { SmPermissions } from "./abstractions.js";
export const SmPermissionsFeature = createPermissionsFeature(SM_PERMISSIONS_SCHEMA, SmPermissions);
Registration
Register the feature in your context plugin:
import { SmPermissionsFeature } from "~/features/permissions/feature.js";
// In createContext:
SmPermissionsFeature.register(container);
File Structure
src/
├── domain/
│ └── permissionsSchema.ts # createPermissionSchema()
├── features/
│ └── permissions/
│ ├── abstractions.ts # createPermissionsAbstraction() + namespace type
│ └── feature.ts # createPermissionsFeature()
└── index.ts # SmPermissionsFeature.register(container)
Permission Methods
All methods follow a 3-tier bypass:
identityContext.hasFullAccess()→name: "*"permission (super admin)hasFullSchemaAccess()→ wildcard permission (e.g."sm.*")- Entity-level permission check
Method Referen
Câu hỏi thường gặp
Schema quyền định nghĩa gì?
Các entity, tên quyền, phạm vi và hành động, như toàn quyền hoặc phạm vi của chính mình.
Quy tắc cho bản ghi của chính mình được xử lý thế nào?
Skill bao phủ phạm vi bản ghi của chính mình qua một phương thức chỉ kiểm tra bản ghi thuộc sở hữu.
Quyền có thể được kiểm thử không?
Có. Skill bao gồm hướng dẫn kiểm thử các kịch bản quyền.
Chi tiết
Mô tả gốc của tác giả
Schema-based permission system for API features. Use this skill when implementing authorization in use cases, defining permission schemas with createPermissionSchema, creating injectable permissions via createPermissionsAbstraction/createPermissionsFeature, checking read/write/delete/publish permissions, handling own-record scoping, or testing permission scenarios. Covers the full pattern from schema definition to use case integration to test matrices.
repo: webiny/webiny-js
Độ phổ biến
- Sao GitHub
- 8.1k
- Vị trí xếp hạng
- #12589
- Giấy phép
- —
- Cập nhật
- 2/11/2026
Bình luận
- …
Thêm skill từ kho mã này
prd-to-plan
8.1kGiúp agent của bạn biến tài liệu yêu cầu sản phẩm thành kế hoạch theo giai đoạn gồm các lát cắt đầu-cuối nhỏ, lưu thành file Markdown.
webiny-admin-architect
8.1kDạy agent của bạn cách xây dựng màn hình quản trị cho nền tảng Webiny, dùng các tầng logic nghiệp vụ và mẫu presenter.
webiny-admin-permissions
8.1kDạy agent của bạn thêm kiểm soát quyền vào màn hình quản trị Webiny, gồm form quyền tự sinh và kiểm tra ẩn hoặc hiện.
webiny-form-model
8.1kDạy agent của bạn xây dựng form trong Webiny bằng trình tạo trường khai báo, bố cục, kiểm tra hợp lệ và quy tắc có điều kiện.
Skill tương tự
reverse-engineer-anything
422kGiúp agent của bạn xem bên trong các app và package đã phát hành để giải thích tính năng, so sánh phiên bản hoặc hướng dẫn dựng lại bằng công cụ REA.
1password
394kGiúp agent của bạn cài đặt CLI của 1Password, đăng nhập, và đọc hoặc đưa thông tin bí mật vào mà không in giá trị ra cuộc trò chuyện.
healthcheck
394kGiúp agent của bạn rà soát bảo mật máy tính hoặc máy chủ đang chạy OpenClaw, như SSH, tường lửa, cập nhật và sao lưu, rồi đề xuất cách sửa an toàn.