nocobase-app-plugin-authz-sharing-rules
它能做什么
这项技能为 NocoBase 3 业务操作配置共享规则。适合需要与他人共享特定记录以开展协作的管理员。
适用场景
- ✓当一个人需要与另一个人或部门共享特定记录时。
- ✓当某个部门需要访问另一个部门的记录,以完成特定任务时。
- ✓当你需要在生产环境中检查或管理共享规则时。
技能链接
https://github.com/nocobase/nocobase/blob/v3-develop/packages/plugins/app-plugin-authz-sharing-rules/skills/nocobase-app-plugin-authz-sharing-rules/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请帮我让财务团队在原有权限之外,还能查看这三个项目。”
每周 5 个新技能,1 分钟读完。
工作原理
AI 会创建共享规则,为所列的人员或部门添加选定的记录。该规则只对已拥有该操作的人员生效,并且不能选择全部记录。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Develop sharing rules
A sharing rule adds selected records, or a record access selection, for the subjects it lists, provided they already hold the action. Sharing does not grant the operation, fields, page access or related records, and it cannot select all records. Grants, default access and sharing combine first; restriction rules then narrow the result.
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-sharing-rules/README.md is the complete reference for the service, the HTTP routes and the exports; this Skill covers how to use them.
For sharing between departments, read the application development Skill's references/organization/permission-design.md first. A rule whose recipient is a department shares specific records with it; a viewer-relative department scope such as 本部门及下属部门 is computed for the viewer and cannot select another department's records. The guide's optional sharing section covers this plugin, and its core section says what remains with permission sets alone.
Development workflow
- Identify the real collaboration exception: who receives which records, for which actions, and why. Use explicit records for one handover; use a record access selection for a maintained region or team rule.
- Grant the recipients the business action through a permission set first. Register inherited subjects and their active membership resolver through the main authorization Skill.
- Inspect every data scope the operation requires. Quote submission needs the selected quote and its actual parent project. Add each action and data scope deliberately; view, edit and submit are different permissions.
- Save a complete rule through the HTTP routes or the service. Keep record ids tied to their data scope's collection and preserve the other entries on update.
- Verify the handover works, an unshared parent still blocks the workflow, restrictions still exclude confidential records, and sharing alone cannot activate a missing operation.
- Revoke the recipient or the team's permission set and verify the next request loses only that source. Independent direct-user sharing and direct assignments must survive.
For example, a quote handover shares quote edit and submit plus the parent project's submit scope with a delegated engineer. Use the real record ids, never sample ones.
Install
Register the default export of @nocobase/app-plugin-authz-sharing-rules/client in client/plugins.ts and of @nocobase/app-plugin-authz-sharing-rules/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 { sharingRules } from '@nocobase/app-plugin-authz-sharing-rules/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: [sharingRules()] }),
);
export default authorization;
During setup the factory registers the settings item authorization.sharing-rules (group authorization, actions read, create, update, delete) and its routes under /api/authorization/sharingRules, 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 org.team its own subject type, both defined as the main Skill describes.
import { selection } from '@nocobase/authorization/core';
import {
defineSharingRule,
type SharingRulesAuthorizationApi,
} from '@nocobase/authorization/sharing-rules';
import type { DatabaseConnection } from '@nocobase/db';
if (!('sharingRules' in authz))
throw new Error('Sharing rules is not configured');
const rules = (
authz as typeof authz & SharingRulesAuthorizationApi<DatabaseConnection>
).sharingRules;
await rules.create(
常见问题
共享会授予新的权限吗?
不会。共享只会为已拥有该操作的人添加记录。
我能一次共享所有记录吗?
不能。共享不能选择全部记录。
它与限制规则如何配合?
限制规则仍会在之后生效,并可能缩小结果范围。
详情
作者的原始描述
Design, implement and verify sharing rules for NocoBase 3 business operations, including named data scopes and production administration.
repo: nocobase/nocobase
热度
- GitHub 星标
- 25k
- 排名
- #10093
- 许可证
- —
- 更新时间
- 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 应用升级到较新的模板版本,引入模板的更改,同时保留你自己的工作。