Skip to content

refactor(permission): modularize permission store and migrate to spec… - #17

Merged
zhullyb merged 1 commit into
mainfrom
permission-update
Mar 3, 2026
Merged

zhullyb merged 1 commit into
mainfrom
permission-update

Conversation

@zhullyb

@zhullyb zhullyb commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

…-based checks

变更概述
本 PR 重构了前端权限模块,统一了权限模型与校验方式,并补充了可读性注释,便于后续维护和扩展。

主要改动

  1. 将权限 store 模块化,按职责拆分为 store、types、utils 三部分,并统一通过 @/stores/permission 作为入口导入。
  2. 权限判断改为规格字符串模式:resource:action[:target],替代原先分散参数式调用。
  3. 权限数据在拉取后统一拍平为规则集合(rule list),前端所有权限校验都基于同一套规则执行。
  4. 新增并明确作用域规则:global、agent_uuid、kv_namespace,并按资源类型做作用域兼容限制。
  5. KV 目标支持 * 通配匹配,提升 KV 类权限表达能力。
  6. 为 store 核心方法和 utils 关键函数补充了中文注释与使用示例,降低理解成本。
  7. 同步更新页面侧调用(如 App、ServerDetail、DeleteTokenCard)到新的权限接口与导入方式。

当前权限设计

  1. 从后端 token_get 获取 token_limit 后,前端会拍平为统一规则。
  2. 每条规则包含 scope、resource、action、target(可选)。
  3. hasPermission(spec, scope) 用于“指定 scope”判断。
  4. hasAnyScopePermission(spec) 用于“任意 scope”能力判断(常用于 UI 显隐)。
  5. root 用户默认拥有全部权限。

…-based checks

- move the permission store into src/stores/permission/index.ts and split supporting logic into dedicated types.ts and utils.ts modules
- replace the previous resource/action/options permission API with a spec-based format (resource:action[:target]) plus explicit scope input
- add scope compatibility handling for agent_uuid and kv_namespace, including wildcard matching for KV targets
- document permission store methods and permission utility functions with usage-focused comments and examples
- update imports and call sites in App.vue, ServerDetailView.vue, and DeleteTokenCard.vue, and remove the legacy src/stores/usePermissionStore.ts entry
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying nodeget-board with  Cloudflare Pages  Cloudflare Pages

Latest commit: b47d65f
Status: ✅  Deploy successful!
Preview URL: https://2db5ae8d.nodeget-board.pages.dev
Branch Preview URL: https://permission-update.nodeget-board.pages.dev

View logs

@zhullyb
zhullyb merged commit 1f0f1d2 into main Mar 3, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant