( access, accessData )
| 2 | import { AccessDataType } from '@common/const/type' |
| 3 | |
| 4 | export 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 | |
| 28 | const hasIntersection = (arr1: string[], set1: Set<string>) => { |
| 29 | const arr2 = Array.from(set1) |
no test coverage detected