Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ui/src/permission/core/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export class Permission {

/** 判定时使用的最终 key,对应后端 `AggregatePermission._match_permission`。 */
toPermissionKey(): string {
return this.resourceId ? this.getResourcePermissionKey() : this.group
return this.resourceId||this.workspaceId ? this.getResourcePermissionKey() : this.group
}

/** 基于上下文派生出带 workspace / resource 的权限副本。 */
Expand Down Expand Up @@ -361,6 +361,7 @@ export class AggregatePermission {

private checkPermission(permission: Permission, userPermissions: Map<string, bigint>): boolean {
const key = permission.toPermissionKey()
console.log(key)
const raw = userPermissions.get(key)
if (raw == null) return false
return (raw & permission.bit()) !== 0n
Expand Down
5 changes: 2 additions & 3 deletions ui/src/permission/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export const hasPermission = (permission: PermissionInput | PermissionInput[], c
export const buildBasePermission = (permission: Permission, workspaceId: string | undefined = getWorkspaceId()): AggregatePermission =>
AggregatePermission.builder()
.addPermission(permission.newWorkspacePermission(workspaceId))
.addRole(RoleConstants.ADMIN)
.addRole(new Role(RoleConstants.WORKSPACE_MANAGE.name, workspaceId))
.compare(Compare.OR)
.build()
Expand All @@ -80,8 +79,8 @@ export const buildBaseResourcePermission = (permission: Permission, resourceId:
.build()
/**
* 判断当前系统环境
* @param edition
* @returns
* @param edition
* @returns
*/
export const hasEdition=(edition:Edition)=>{
const { auth } = useStore()
Expand Down
5 changes: 4 additions & 1 deletion ui/src/permission/policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
* 复杂/特殊按钮可绕过这里,直接用 core 的 hasPermission + 常量自行组合。
*/

import { getWorkspaceId } from '@/utils/resource-context'
import { hasPermission, buildBasePermission, buildBaseResourcePermission, RoleConstants, Compare } from './core'
import type { Permission } from './core/common'


/** 工作空间级:命中权限位 / 系统管理员 / 该空间管理员 即可。workspaceId 内部取当前路由。 */
export const can = (p: Permission): boolean => hasPermission(buildBasePermission(p))
export const can = (p: Permission): boolean => {
return hasPermission(buildBasePermission(p,getWorkspaceId()))
}

/** 工作空间资源级:命中该资源权限位 / 系统管理员 / 该空间管理员 即可。 */
export const canRes = (p: Permission, id: string): boolean => hasPermission(buildBaseResourcePermission(p, id))
Expand Down
Loading