mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 01:55:59 +00:00
permissins (per instance)
This commit is contained in:
16
packages/tools/src/testPermission.ts
Normal file
16
packages/tools/src/testPermission.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import _escapeRegExp from 'lodash/escapeRegExp';
|
||||
import _isString from 'lodash/isString';
|
||||
|
||||
export function compilePermissions(permissions: string[] | string) {
|
||||
if (!permissions) return null;
|
||||
if (_isString(permissions)) permissions = permissions.split(',');
|
||||
return permissions.map((x) => new RegExp('^' + _escapeRegExp(x).replace(/\\\*/g, '.*') + '$'));
|
||||
}
|
||||
|
||||
export function testPermission(tested: string, permissions: RegExp[]) {
|
||||
if (!permissions) return true;
|
||||
for (const permission of permissions) {
|
||||
if (tested.match(permission)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user