@felloh-org/lambda-wrapper 1.1.47 → 1.1.50
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.
|
@@ -15,6 +15,8 @@ var _logger = _interopRequireDefault(require("../service/logger"));
|
|
|
15
15
|
|
|
16
16
|
var _request = _interopRequireDefault(require("../service/request"));
|
|
17
17
|
|
|
18
|
+
var _user = _interopRequireDefault(require("../service/user"));
|
|
19
|
+
|
|
18
20
|
var _warehouse = _interopRequireDefault(require("../service/warehouse"));
|
|
19
21
|
|
|
20
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -25,6 +27,7 @@ const DEFINITIONS = {
|
|
|
25
27
|
HTTP: 'HTTP',
|
|
26
28
|
LOGGER: 'LOGGER',
|
|
27
29
|
REQUEST: 'REQUEST',
|
|
30
|
+
USER: 'USER',
|
|
28
31
|
WAREHOUSE: 'WAREHOUSE'
|
|
29
32
|
};
|
|
30
33
|
exports.DEFINITIONS = DEFINITIONS;
|
|
@@ -34,7 +37,8 @@ const Dependencies = {
|
|
|
34
37
|
[DEFINITIONS.LOGGER]: _logger.default,
|
|
35
38
|
[DEFINITIONS.REQUEST]: _request.default,
|
|
36
39
|
[DEFINITIONS.WAREHOUSE]: _warehouse.default,
|
|
37
|
-
[DEFINITIONS.AUTHENTICATION]: _authentication.default
|
|
40
|
+
[DEFINITIONS.AUTHENTICATION]: _authentication.default,
|
|
41
|
+
[DEFINITIONS.USER]: _user.default
|
|
38
42
|
};
|
|
39
43
|
exports.Dependencies = Dependencies;
|
|
40
44
|
var _default = {
|
|
@@ -36,7 +36,7 @@ class AuthenticationService extends _dependencyAware.default {
|
|
|
36
36
|
this.initialised = true;
|
|
37
37
|
this.userRoleRepository = await that.connection.getRepository(_userRole.default);
|
|
38
38
|
this.organisationRepository = await that.connection.getRepository(_organisation.default);
|
|
39
|
-
this.user =
|
|
39
|
+
this.user = await di.get(_dependencies.DEFINITIONS.USER).getUser();
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
42
|
}
|
|
@@ -51,7 +51,7 @@ class AuthenticationService extends _dependencyAware.default {
|
|
|
51
51
|
await this.initialise();
|
|
52
52
|
const response = [];
|
|
53
53
|
|
|
54
|
-
for
|
|
54
|
+
for (const organisation of user.organisations) {
|
|
55
55
|
const orgs = await this.organisationRepository.findDescendants(organisation, {
|
|
56
56
|
relations: ['parent']
|
|
57
57
|
});
|
|
@@ -70,15 +70,27 @@ class AuthenticationService extends _dependencyAware.default {
|
|
|
70
70
|
*/
|
|
71
71
|
|
|
72
72
|
|
|
73
|
-
async fetchUserRoles(userID) {
|
|
73
|
+
async fetchUserRoles(userID = null) {
|
|
74
74
|
await this.initialise();
|
|
75
75
|
const roles = await this.userRoleRepository.createQueryBuilder('user_roles').leftJoinAndSelect('user_roles.role', 'role').where('user_id = :userID', {
|
|
76
|
-
userID
|
|
76
|
+
userID: userID !== null ? userID : this.user.id
|
|
77
77
|
}).getMany();
|
|
78
78
|
return roles.map(role => role.role.machine_name);
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
|
-
* Check user
|
|
81
|
+
* Check to see if user has a role
|
|
82
|
+
* @param role
|
|
83
|
+
* @param userID
|
|
84
|
+
* @returns {Promise<boolean>}
|
|
85
|
+
*/
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
async hasRole(role, userID = null) {
|
|
89
|
+
const roles = await this.fetchUserRoles(userID);
|
|
90
|
+
return roles.indexOf(role) !== -1;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Check a users role and organisation access
|
|
82
94
|
* @param organisationID
|
|
83
95
|
* @param roles
|
|
84
96
|
* @returns {Promise<boolean>}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _dependencies = require("../config/dependencies");
|
|
9
|
+
|
|
10
|
+
var _dependencyAware = _interopRequireDefault(require("../dependency-injection/dependency-aware"));
|
|
11
|
+
|
|
12
|
+
var _user = _interopRequireDefault(require("../entity/user/user"));
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
// eslint-disable-next-line import/no-named-as-default,import/no-named-as-default-member
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* User Service class
|
|
20
|
+
*/
|
|
21
|
+
class User extends _dependencyAware.default {
|
|
22
|
+
constructor(di) {
|
|
23
|
+
super(di);
|
|
24
|
+
this.initialised = false;
|
|
25
|
+
const that = this;
|
|
26
|
+
|
|
27
|
+
this.initialise = async () => {
|
|
28
|
+
if (that.initialised === false) {
|
|
29
|
+
const warehouse = di.get(_dependencies.DEFINITIONS.WAREHOUSE);
|
|
30
|
+
that.connection = await warehouse.connect();
|
|
31
|
+
this.initialised = true;
|
|
32
|
+
this.userRepository = await that.connection.getRepository(_user.default);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Fetch
|
|
38
|
+
* @returns {Promise<*>}
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
async getUser() {
|
|
43
|
+
await this.initialise();
|
|
44
|
+
|
|
45
|
+
if (typeof process.env.IS_OFFLINE !== 'undefined') {
|
|
46
|
+
const sub = this.di.getEvent().requestContext.authorizer.claims.sub;
|
|
47
|
+
return this.userRepository.findOne({
|
|
48
|
+
cognito_sub: sub
|
|
49
|
+
}, {
|
|
50
|
+
relations: ['organisations']
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return JSON.parse(this.di.getEvent().requestContext.authorizer.user);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
exports.default = User;
|