MCPcopy Create free account
hub / github.com/APIParkLab/APIPark / checkAccess

Function checkAccess

frontend/packages/common/src/utils/permission.ts:4–26  ·  view source on GitHub ↗
(
  access,
  accessData
)

Source from the content-addressed store, hash-verified

2import { AccessDataType } from '@common/const/type'
3
4export const checkAccess: (access: AccessDataType, accessData: Map<string, string[]>) => boolean = (
5 access,
6 accessData
7) => {
8 if (!access) {
9 return true
10 }
11 const accLevel = access.split('.')[0]
12 if (['system', 'team'].indexOf(accLevel) === -1) {
13 console.warn('权限字段有误:', access)
14 return false
15 }
16 const neededBackendAccessArr = PERMISSION_DEFINITION[0]?.[access]?.granted?.anyOf[0].backend || []
17 let accessSet = new Set(accessData.get('system'))
18 if (accLevel === 'team') {
19 accessSet = new Set(Array.from(accessSet).concat(accessData?.get('team') || []))
20 }
21 if (!accessSet!.size) {
22 return false
23 }
24 const hasAccess = hasIntersection(neededBackendAccessArr, accessSet)
25 return hasAccess
26}
27
28const hasIntersection = (arr1: string[], set1: Set<string>) => {
29 const arr2 = Array.from(set1)

Callers 15

openModalFunction · 0.90
openModalFunction · 0.90
OnlineModelListFunction · 0.90
openConfigModalFunction · 0.90
isActionAllowedFunction · 0.90
isActionAllowedFunction · 0.90
restCardClickFunction · 0.90
aiCardClickFunction · 0.90
localModelCardClickFunction · 0.90
deployDeepSeekFunction · 0.90
openModalFunction · 0.90
TeamListFunction · 0.90

Calls 2

hasIntersectionFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected