-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpermissions.js
More file actions
30 lines (25 loc) · 820 Bytes
/
permissions.js
File metadata and controls
30 lines (25 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const AccessControl = require("accesscontrol").AccessControl;
const Role = require("./models/roles");
//ACCESS CONTROL DEFINITIONS
//creating a promise in order to make it eaiser to call this from anywhere.
let ac;
module.exports = {
reload: () => {
return new Promise(async (resolve, reject) => {
try {
const roles = await Role.find();
let roleObject = {};
roles.forEach((role) => {
roleObject[role.name] = role._doc.permissions;
});
ac = new AccessControl(roleObject);
resolve(ac);
} catch (error) {
reject(error);
}
});
},
ac: () => {
return ac;
},
};