nocobase-app-plugin-authz-default-access
它能做什么
这项技能为 NocoBase 3 业务操作配置默认访问权限,提供共享的记录基线。适合管理记录可见性的管理员和开发者。
适用场景
- ✓当拥有某项操作的所有人,默认都应看到一组共同记录时。
- ✓当你希望部门默认可以读取记录,但不能编辑时。
- ✓当你需要在生产环境中检查或管理默认访问权限时。
技能链接
https://github.com/nocobase/nocobase/blob/v3-develop/packages/plugins/app-plugin-authz-default-access/skills/nocobase-app-plugin-authz-default-access/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请帮我设置让所有销售用户默认可以读取全部未关闭的线索,而编辑权限仍只限于负责人。”
每周 5 个新技能,1 分钟读完。
工作原理
AI 会为某一操作设置默认数据范围。它不会授予操作本身的权限,其他规则仍会缩小结果范围。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Develop default access
Default access adds a shared record baseline for every identity that already holds an action. It does not grant the action, page access or additional fields. A baseline combines with permission-set data scopes and sharing, and restriction rules still narrow the result, so choose it as an intentional minimum range rather than a fallback for identities without a scope of their own.
Read the installed nocobase-app-plugin-authorization Skill first for composite resources, data scopes, fields, server policy enforcement and inherited subjects. The package README at node_modules/@nocobase/app-plugin-authz-default-access/README.md is the complete reference for the service, the HTTP routes and the exports; this Skill covers how to use them.
For a department-scoped baseline, read the application development Skill's references/organization/permission-design.md first. Its core works with permission sets alone, and its optional default-access section explains why a global default suits a department scope only when everyone holding the action belongs to a department.
Development workflow
- Identify which records every holder of a particular operation should receive by default. A read baseline can be broad while edit remains preparer-only; do not copy read defaults into write operations.
- Confirm the composite, action and data scope exist and that the scope's grants target the intended collection. Reuse an applicable record access or define one through the main authorization Skill.
- Save one rule per resource under a stable
key; a second rule on the same resource is rejected, so extend the existing rule instead. A rule lists every action and data scope it widens; updating it replaces the whole rule, and deleting it removes the baseline, not the permission-set action. - Verify a holder receives the baseline, a person without the action remains denied, and restrictions still remove excluded rows. Also verify an explicit narrow data scope is not unexpectedly broadened by a permissive default.
For example, a quote view baseline can follow related-project ownership while editing follows the preparer, and a job's permission set can separately grant broad viewing that confidentiality restrictions narrow. A project's owner is not necessarily the author of every quote on that project.
Install
Register the default export of @nocobase/app-plugin-authz-default-access/client in client/plugins.ts and of @nocobase/app-plugin-authz-default-access/server in server/plugins.ts, beside the main authorization plugin, and run the application's migrations. Add the factory to the plugins of server/config/authorization.ts, merged with the application's other rule factories:
import { defaultAccess } from '@nocobase/app-plugin-authz-default-access/server';
import {
defineAppConfig,
type AppConfigFactory,
} from '@nocobase/app-server/config';
import type { AuthorizationConfig } from '@nocobase/app-plugin-authorization/server';
const authorization: AppConfigFactory<AuthorizationConfig> = defineAppConfig(
() => ({ plugins: [defaultAccess()] }),
);
export default authorization;
During setup the factory registers the settings item authorization.default-access (group authorization, actions read, create, update, delete) and its routes under /api/authorization/defaultAccess, which the running application documents at /api/swagger/docs under the Authorization tag. Without the factory in the configuration the plugin adds no API and no route.
Service API
Resolve authorizationToken from @nocobase/app-plugin-authorization/server in the owning provider or route factory. The rule API exists only when the factory is configured, so narrow the service before using it. quotes is the application's own composite and sales.prepared its own record access, both defined as the main Skill describes.
import { selection } from '@nocobase/authorization/core';
import {
defineDefaultAccessRule,
type DefaultAccessAuthorizationApi,
} from '@nocobase/authorization/default-access';
import type { DatabaseConnection } from '@nocobase/db';
if (!('defaultAccess' in authz))
throw new Error('Default access is not configured');
const rules = (
authz as typeof authz & DefaultAccessAuthorizationApi<DatabaseConnection>
).defaultAccess;
await rules.create(
defineDefaultAccessRule('quotes-baseline', quotes.reference())
.scope('edit', 'quotes', selection.recordAccess('s
常见问题
它会授予新的权限吗?
不会。它只为已经拥有该操作的人添加共享基线。
限制规则能覆盖它吗?
限制规则仍会缩小默认访问允许的记录范围。
它也涵盖字段吗?
不涵盖。它只涉及某一操作能访问的记录,而不涉及额外字段。
详情
作者的原始描述
Design, implement and verify default access for NocoBase 3 business operations, including named data scopes and production administration.
repo: nocobase/nocobase
热度
- GitHub 星标
- 25k
- 排名
- #10091
- 许可证
- —
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
nocobase-app-development
25k帮你的智能体为完整的 NocoBase 3 业务应用构建页面、路由、数据、权限和测试。
shadcn
25k帮你的智能体在 Web 项目中查找、添加、修复和美化 shadcn/ui 组件,并使用其官方文档和注册表。
nocobase-app-plugin-development
25k帮你的智能体在现有应用中创建和维护 NocoBase 3 插件,包括服务端、客户端、数据库和注册部分。
nocobase-app-upgrade
25k帮你的智能体把 NocoBase 应用升级到较新的模板版本,引入模板的更改,同时保留你自己的工作。