identity-admin 1.26.10 → 1.26.11
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.
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Model } from
|
|
1
|
+
import { Model } from 'mongoose';
|
|
2
2
|
export declare class PermissionFetcher {
|
|
3
3
|
private permissionGroupId?;
|
|
4
4
|
private Permission;
|
|
5
|
-
|
|
5
|
+
private userPermissionGroupId?;
|
|
6
|
+
constructor(Permission: Model<any, any>, permissionGroupId?: string, userPermissionGroupId?: string);
|
|
6
7
|
fetch(): Promise<import("./types").IPermissions[]>;
|
|
7
8
|
}
|
|
@@ -16,39 +16,56 @@ exports.PermissionFetcher = void 0;
|
|
|
16
16
|
const mongoose_1 = __importDefault(require("mongoose"));
|
|
17
17
|
const PermissionMapper_1 = require("./PermissionMapper");
|
|
18
18
|
class PermissionFetcher {
|
|
19
|
-
constructor(Permission, permissionGroupId) {
|
|
19
|
+
constructor(Permission, permissionGroupId, userPermissionGroupId) {
|
|
20
20
|
this.permissionGroupId = permissionGroupId;
|
|
21
21
|
this.Permission = Permission;
|
|
22
|
+
this.userPermissionGroupId = userPermissionGroupId;
|
|
22
23
|
}
|
|
23
24
|
fetch() {
|
|
24
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
25
26
|
const ObjectId = mongoose_1.default.Types.ObjectId;
|
|
26
|
-
const pipeline = [
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
27
|
+
const pipeline = [];
|
|
28
|
+
if (this.userPermissionGroupId) {
|
|
29
|
+
pipeline.push({
|
|
30
|
+
$lookup: {
|
|
31
|
+
from: 'adminpermissions',
|
|
32
|
+
localField: '_id',
|
|
33
|
+
foreignField: 'permissionId',
|
|
34
|
+
as: 'adminPermissionDetails',
|
|
35
|
+
pipeline: [
|
|
36
|
+
{
|
|
37
|
+
$match: {
|
|
38
|
+
permissionGroupId: new ObjectId(this.userPermissionGroupId),
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
],
|
|
36
42
|
},
|
|
43
|
+
}, {
|
|
44
|
+
$unwind: '$adminPermissionDetails',
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
// Sorting and grouping stages
|
|
48
|
+
pipeline.push({
|
|
49
|
+
$sort: {
|
|
50
|
+
modelName: 1,
|
|
37
51
|
},
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
$sort: { order: 1 },
|
|
52
|
+
}, {
|
|
53
|
+
$group: {
|
|
54
|
+
_id: '$modelName',
|
|
55
|
+
documents: { $push: '$$ROOT' },
|
|
43
56
|
},
|
|
44
|
-
|
|
57
|
+
}, {
|
|
58
|
+
$unwind: '$documents',
|
|
59
|
+
}, {
|
|
60
|
+
$sort: { 'documents.order': 1 },
|
|
61
|
+
});
|
|
45
62
|
if (this.permissionGroupId) {
|
|
46
63
|
pipeline.push({
|
|
47
64
|
$lookup: {
|
|
48
|
-
from:
|
|
49
|
-
localField:
|
|
50
|
-
foreignField:
|
|
51
|
-
as:
|
|
65
|
+
from: 'adminpermissions',
|
|
66
|
+
localField: 'documents._id',
|
|
67
|
+
foreignField: 'permissionId',
|
|
68
|
+
as: 'checkedPermissions',
|
|
52
69
|
pipeline: [
|
|
53
70
|
{
|
|
54
71
|
$match: {
|
|
@@ -61,9 +78,9 @@ class PermissionFetcher {
|
|
|
61
78
|
}
|
|
62
79
|
pipeline.push({
|
|
63
80
|
$group: {
|
|
64
|
-
_id:
|
|
65
|
-
documents: { $push:
|
|
66
|
-
checkedPermissions: { $push:
|
|
81
|
+
_id: '$_id',
|
|
82
|
+
documents: { $push: '$documents' },
|
|
83
|
+
checkedPermissions: { $push: '$checkedPermissions' },
|
|
67
84
|
},
|
|
68
85
|
}, {
|
|
69
86
|
$sort: { _id: 1 },
|