ecrs-auth-core 1.0.36 → 1.0.37
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/dist/guards/module.guard.js +49 -27
- package/package.json +1 -1
|
@@ -1,36 +1,58 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __decorate =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
var __decorate =
|
|
3
|
+
(this && this.__decorate) ||
|
|
4
|
+
function (decorators, target, key, desc) {
|
|
5
|
+
var c = arguments.length,
|
|
6
|
+
r =
|
|
7
|
+
c < 3
|
|
8
|
+
? target
|
|
9
|
+
: desc === null
|
|
10
|
+
? (desc = Object.getOwnPropertyDescriptor(target, key))
|
|
11
|
+
: desc,
|
|
12
|
+
d;
|
|
13
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
14
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
15
|
+
else
|
|
16
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
17
|
+
if ((d = decorators[i]))
|
|
18
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
19
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
20
|
+
};
|
|
21
|
+
var __metadata =
|
|
22
|
+
(this && this.__metadata) ||
|
|
23
|
+
function (k, v) {
|
|
24
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
25
|
+
return Reflect.metadata(k, v);
|
|
26
|
+
};
|
|
27
|
+
var __param =
|
|
28
|
+
(this && this.__param) ||
|
|
29
|
+
function (paramIndex, decorator) {
|
|
30
|
+
return function (target, key) {
|
|
31
|
+
decorator(target, key, paramIndex);
|
|
32
|
+
};
|
|
33
|
+
};
|
|
14
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
35
|
exports.ModuleGuard = void 0;
|
|
16
36
|
const common_1 = require("@nestjs/common");
|
|
17
37
|
let ModuleGuard = class ModuleGuard {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
38
|
+
constructor(config) {
|
|
39
|
+
this.config = config;
|
|
40
|
+
}
|
|
41
|
+
canActivate(context) {
|
|
42
|
+
const request = context.switchToHttp().getRequest();
|
|
43
|
+
const user = request.user;
|
|
44
|
+
// SuperAdmin can bypass module checks
|
|
45
|
+
const isSuperAdmin = user.roleId === 1;
|
|
46
|
+
if (isSuperAdmin) return true;
|
|
47
|
+
return user.moduleId === this.config.moduleId;
|
|
48
|
+
}
|
|
30
49
|
};
|
|
31
50
|
exports.ModuleGuard = ModuleGuard;
|
|
32
|
-
exports.ModuleGuard = ModuleGuard = __decorate(
|
|
51
|
+
exports.ModuleGuard = ModuleGuard = __decorate(
|
|
52
|
+
[
|
|
33
53
|
(0, common_1.Injectable)(),
|
|
34
|
-
__param(0, (0, common_1.Inject)(
|
|
35
|
-
__metadata("design:paramtypes", [Object])
|
|
36
|
-
],
|
|
54
|
+
__param(0, (0, common_1.Inject)("MODULE_CONFIG")),
|
|
55
|
+
__metadata("design:paramtypes", [Object]),
|
|
56
|
+
],
|
|
57
|
+
ModuleGuard
|
|
58
|
+
);
|