|
1 | 1 | /* eslint-disable sonarjs/no-duplicate-string */ |
| 2 | +import type { TableAction, AppAction, AutomationAction } from '@teable/core'; |
2 | 3 | import { HttpErrorCode } from '@teable/core'; |
3 | 4 | import { BaseNodeResourceType } from '@teable/openapi'; |
4 | 5 | import { CustomHttpException } from '../../custom.exception'; |
| 6 | +import type { IBaseNodePermissionContext } from './types'; |
5 | 7 | import { BaseNodeAction } from './types'; |
6 | 8 |
|
7 | 9 | const map: Record<BaseNodeResourceType, Record<BaseNodeAction, string>> = { |
@@ -40,28 +42,29 @@ const map: Record<BaseNodeResourceType, Record<BaseNodeAction, string>> = { |
40 | 42 | export const checkBaseNodePermission = ( |
41 | 43 | node: { resourceType: BaseNodeResourceType; resourceId: string }, |
42 | 44 | action: BaseNodeAction, |
43 | | - permissionContext: { |
44 | | - tablePermissionMap?: Record<string, string[]>; |
45 | | - permissionSet: Set<string>; |
46 | | - } |
| 45 | + permissionContext: IBaseNodePermissionContext |
47 | 46 | ): boolean => { |
48 | 47 | const { resourceType } = node; |
49 | 48 | const { resourceId } = node; |
50 | | - const { tablePermissionMap, permissionSet } = permissionContext; |
| 49 | + const { tablePermissionMap, permissionSet, appPermissionMap, workflowPermissionMap } = |
| 50 | + permissionContext; |
51 | 51 | const checkAction = map[resourceType][action]; |
52 | 52 | if (resourceType === BaseNodeResourceType.Table && tablePermissionMap) { |
53 | | - return tablePermissionMap[resourceId]?.includes(checkAction) ?? false; |
| 53 | + return tablePermissionMap[resourceId]?.includes(checkAction as TableAction) ?? false; |
| 54 | + } |
| 55 | + if (resourceType === BaseNodeResourceType.App && appPermissionMap) { |
| 56 | + return appPermissionMap[resourceId]?.includes(checkAction as AppAction) ?? false; |
| 57 | + } |
| 58 | + if (resourceType === BaseNodeResourceType.Workflow && workflowPermissionMap) { |
| 59 | + return workflowPermissionMap[resourceId]?.includes(checkAction as AutomationAction) ?? false; |
54 | 60 | } |
55 | 61 | return permissionSet.has(checkAction); |
56 | 62 | }; |
57 | 63 |
|
58 | 64 | export const checkBaseNodePermissionCreate = ( |
59 | 65 | node: { resourceType: BaseNodeResourceType; resourceId: string }, |
60 | 66 | baseNodePermissions: BaseNodeAction[], |
61 | | - permissionContext: { |
62 | | - tablePermissionMap?: Record<string, string[]>; |
63 | | - permissionSet: Set<string>; |
64 | | - } |
| 67 | + permissionContext: IBaseNodePermissionContext |
65 | 68 | ): boolean => { |
66 | 69 | const checkCreate = baseNodePermissions.includes(BaseNodeAction.Create); |
67 | 70 | if (!checkCreate) { |
|
0 commit comments