@soratani-code/samtools 1.3.2 → 1.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/permission.d.ts +11 -0
- package/lib/permission.js +40 -0
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -40,5 +40,6 @@ exports.log = __importStar(require("./log"));
|
|
|
40
40
|
exports.color = __importStar(require("./color"));
|
|
41
41
|
exports.query = __importStar(require("./query"));
|
|
42
42
|
exports.transform = __importStar(require("./transform"));
|
|
43
|
+
__exportStar(require("./permission"), exports);
|
|
43
44
|
var graph_1 = require("./graph");
|
|
44
45
|
Object.defineProperty(exports, "Graph", { enumerable: true, get: function () { return __importDefault(graph_1).default; } });
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type UserPermission = Record<string, number[]>;
|
|
2
|
+
type Auth = {
|
|
3
|
+
resource: string | RegExp;
|
|
4
|
+
actions?: number[];
|
|
5
|
+
};
|
|
6
|
+
export interface AuthParams {
|
|
7
|
+
requiredPermissions?: Array<Auth>;
|
|
8
|
+
oneOfPerm?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function permission(params: AuthParams, userPermission: UserPermission): boolean;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.permission = void 0;
|
|
4
|
+
const judge = (actions, perm) => {
|
|
5
|
+
if (!perm || !perm.length) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
return actions.every((action) => perm.includes(action));
|
|
9
|
+
};
|
|
10
|
+
const auth = (params, userPermission) => {
|
|
11
|
+
const { resource, actions = [] } = params;
|
|
12
|
+
if (resource instanceof RegExp) {
|
|
13
|
+
const permKeys = Object.keys(userPermission);
|
|
14
|
+
const matchPermissions = permKeys.filter((item) => item.match(resource));
|
|
15
|
+
if (!matchPermissions.length) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return matchPermissions.every((key) => {
|
|
19
|
+
const perm = userPermission[key];
|
|
20
|
+
return judge(actions, perm);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
const perm = userPermission[resource];
|
|
24
|
+
return judge(actions, perm);
|
|
25
|
+
};
|
|
26
|
+
function permission(params, userPermission) {
|
|
27
|
+
const { requiredPermissions, oneOfPerm } = params;
|
|
28
|
+
if (Array.isArray(requiredPermissions) && requiredPermissions.length) {
|
|
29
|
+
let count = 0;
|
|
30
|
+
for (const rp of requiredPermissions) {
|
|
31
|
+
if (auth(rp, userPermission)) {
|
|
32
|
+
count++;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return oneOfPerm ? count > 0 : count === requiredPermissions.length;
|
|
36
|
+
}
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
exports.permission = permission;
|
|
40
|
+
;
|