@@ -3,89 +3,96 @@ import Role from '../models/role.model';
33
44class AccessControlLoader {
55
6- constructor ( private accessControl : AccessControl = new AccessControl ( ) ) {
7- this . init ( ) ;
8- }
9-
10- public getAccessControl = ( ) : AccessControl => {
11- return this . accessControl ;
12- }
13-
14- public init = async ( ) : Promise < void > => {
15- // const roles = await Role.find().populate({path: 'permissions', select: ['resource', 'action', 'attributes']} ).select('role');
16- // await this.asyncForEach(roles, async (role: any) => {
17- // this.accessControl.grant(role.role);
18- // await this.asyncForEach(role.permissions, async (permission: any) => {
19- // console.log('in permissions', permission);
20- // });
21- // });
22-
23- let grantList = [
24- // roles
25- { role : 'owner' , resource : 'role' , action : 'create:any' , attributes : '*, !views' } ,
26- { role : 'owner' , resource : 'role' , action : 'read:any' , attributes : '*' } ,
27- { role : 'owner' , resource : 'role' , action : 'update:any' , attributes : '*, !views' } ,
28- { role : 'owner' , resource : 'role' , action : 'delete:any' , attributes : '*' } ,
29-
30- { role : 'admin' , resource : 'user' , action : 'update:any' , attributes : '*' } ,
31- { role : 'admin' , resource : 'user' , action : 'read:any' , attributes : '*' } ,
32-
33- { role : 'auditor' , resource : 'user' , action : 'read:any' , attributes : '*' } ,
34- { role : 'auditor' , resource : 'user' , action : 'update:any' , attributes : '*' } ,
35-
36- // prescriptions
37- { role : 'professional' , resource : 'prescription' , action : 'create:any' , attributes : '*, !views' } ,
38- { role : 'professional' , resource : 'prescription' , action : 'read:own' , attributes : '*' } ,
39- { role : 'professional' , resource : 'prescription' , action : 'read:any' , attributes : '*' } ,
40- { role : 'professional' , resource : 'prescription' , action : 'update:own' , attributes : '*' } ,
41- { role : 'professional' , resource : 'prescription' , action : 'delete:any' , attributes : '*' } ,
42-
43- { role : 'pharmacist' , resource : 'prescription' , action : 'read:any' , attributes : '*' } ,
44- { role : 'pharmacist' , resource : 'prescription' , action : 'update:any' , attributes : '*, !views' } ,
45-
46- { role : 'owner' , resource : 'prescription' , action : 'delete:any' , attributes : '*' } ,
47-
48- { role : 'auditor' , resource : 'prescription' , action : 'read:any' , attributes : '*' } ,
49-
50- // prescriptions public
51- { role : 'professional-public' , resource : 'prescriptionPublic' , action : 'create:any' , attributes : '*, !views' } ,
52- { role : 'professional-public' , resource : 'prescriptionPublic' , action : 'read:own' , attributes : '*' } ,
53- { role : 'professional-public' , resource : 'prescriptionPublic' , action : 'read:any' , attributes : '*' } ,
54- { role : 'professional-public' , resource : 'prescriptionPublic' , action : 'update:own' , attributes : '*' } ,
55- { role : 'professional-public' , resource : 'prescriptionPublic' , action : 'delete:any' , attributes : '*' } ,
56-
57- { role : 'pharmacist-public' , resource : 'prescriptionPublic' , action : 'read:any' , attributes : '*' } ,
58- { role : 'pharmacist-public' , resource : 'prescriptionPublic' , action : 'update:any' , attributes : '*' } ,
59-
60- { role : 'owner' , resource : 'prescriptionPublic' , action : 'delete:any' , attributes : '*' } ,
61-
62- { role : 'auditor' , resource : 'prescriptionPublic' , action : 'read:any' , attributes : '*' } ,
63-
64- // patients
65- { role : 'professional' , resource : 'patient' , action : 'create:any' , attributes : '*, !views' } ,
66- { role : 'professional' , resource : 'patient' , action : 'read:own' , attributes : '*' } ,
67- { role : 'pharmacist' , resource : 'patient' , action : 'read:any' , attributes : '*' } ,
68- { role : 'admin' , resource : 'patient' , action : 'update:any' , attributes : '*' } ,
69-
70- { role : 'owner' , resource : 'patient' , action : 'delete:any' , attributes : '*' } ,
71-
72- // supplies
73- { role : 'professional' , resource : 'supplies' , action : 'read:any' , attributes : '*' } ,
74- { role : 'pharmacist' , resource : 'supplies' , action : 'read:any' , attributes : '*' } ,
75- { role : 'admin' , resource : 'supplies' , action : 'create:any' , attributes : '*' } ,
76- { role : 'admin' , resource : 'supplies' , action : 'update:any' , attributes : '*' } ,
77- { role : 'andes' , resource : 'andesPrescription' , action : 'create:any' , attributes : '*' }
78- ] ;
79- this . accessControl . setGrants ( grantList ) ;
80- console . log ( 'grants initialized' ) ;
81- }
82-
83-
84- public asyncForEach = async ( array : any [ ] , callback : Function ) => {
85- for ( let index = 0 ; index < array . length ; index ++ ) {
86- await callback ( array [ index ] , index , array ) ;
6+ constructor ( private accessControl : AccessControl = new AccessControl ( ) ) {
7+ this . init ( ) ;
878 }
88- }
9+
10+ public getAccessControl = ( ) : AccessControl => {
11+ return this . accessControl ;
12+ } ;
13+
14+ public init = async ( ) : Promise < void > => {
15+ // const roles = await Role.find().populate({path: 'permissions', select: ['resource', 'action', 'attributes']} ).select('role');
16+ // await this.asyncForEach(roles, async (role: any) => {
17+ // this.accessControl.grant(role.role);
18+ // await this.asyncForEach(role.permissions, async (permission: any) => {
19+ // console.log('in permissions', permission);
20+ // });
21+ // });
22+
23+ let grantList = [
24+ // roles
25+ { role : 'owner' , resource : 'role' , action : 'create:any' , attributes : '*, !views' } ,
26+ { role : 'owner' , resource : 'role' , action : 'read:any' , attributes : '*' } ,
27+ { role : 'owner' , resource : 'role' , action : 'update:any' , attributes : '*, !views' } ,
28+ { role : 'owner' , resource : 'role' , action : 'delete:any' , attributes : '*' } ,
29+
30+ // users
31+ { role : 'admin' , resource : 'user' , action : 'update:any' , attributes : '*' } ,
32+ { role : 'admin' , resource : 'user' , action : 'read:any' , attributes : '*' } ,
33+
34+ { role : 'auditor' , resource : 'user' , action : 'read:any' , attributes : '*' } ,
35+ { role : 'auditor' , resource : 'user' , action : 'update:any' , attributes : '*' } ,
36+
37+ { role : 'professional' , resource : 'user' , action : 'update:any' , attributes : '*' } ,
38+ { role : 'professional' , resource : 'user' , action : 'read:any' , attributes : '*' } ,
39+
40+ { role : 'professional-public' , resource : 'user' , action : 'update:any' , attributes : '*' } ,
41+ { role : 'professional-public' , resource : 'user' , action : 'read:any' , attributes : '*' } ,
42+
43+ // prescriptions
44+ { role : 'professional' , resource : 'prescription' , action : 'create:any' , attributes : '*, !views' } ,
45+ { role : 'professional' , resource : 'prescription' , action : 'read:own' , attributes : '*' } ,
46+ { role : 'professional' , resource : 'prescription' , action : 'read:any' , attributes : '*' } ,
47+ { role : 'professional' , resource : 'prescription' , action : 'update:own' , attributes : '*' } ,
48+ { role : 'professional' , resource : 'prescription' , action : 'delete:any' , attributes : '*' } ,
49+
50+ { role : 'pharmacist' , resource : 'prescription' , action : 'read:any' , attributes : '*' } ,
51+ { role : 'pharmacist' , resource : 'prescription' , action : 'update:any' , attributes : '*, !views' } ,
52+
53+ { role : 'owner' , resource : 'prescription' , action : 'delete:any' , attributes : '*' } ,
54+
55+ { role : 'auditor' , resource : 'prescription' , action : 'read:any' , attributes : '*' } ,
56+
57+ // prescriptions public
58+ { role : 'professional-public' , resource : 'prescriptionPublic' , action : 'create:any' , attributes : '*, !views' } ,
59+ { role : 'professional-public' , resource : 'prescriptionPublic' , action : 'read:own' , attributes : '*' } ,
60+ { role : 'professional-public' , resource : 'prescriptionPublic' , action : 'read:any' , attributes : '*' } ,
61+ { role : 'professional-public' , resource : 'prescriptionPublic' , action : 'update:own' , attributes : '*' } ,
62+ { role : 'professional-public' , resource : 'prescriptionPublic' , action : 'delete:any' , attributes : '*' } ,
63+
64+ { role : 'pharmacist-public' , resource : 'prescriptionPublic' , action : 'read:any' , attributes : '*' } ,
65+ { role : 'pharmacist-public' , resource : 'prescriptionPublic' , action : 'update:any' , attributes : '*' } ,
66+
67+ { role : 'owner' , resource : 'prescriptionPublic' , action : 'delete:any' , attributes : '*' } ,
68+
69+ { role : 'auditor' , resource : 'prescriptionPublic' , action : 'read:any' , attributes : '*' } ,
70+
71+ // patients
72+ { role : 'professional' , resource : 'patient' , action : 'create:any' , attributes : '*, !views' } ,
73+ { role : 'professional' , resource : 'patient' , action : 'read:own' , attributes : '*' } ,
74+ { role : 'pharmacist' , resource : 'patient' , action : 'read:any' , attributes : '*' } ,
75+ { role : 'admin' , resource : 'patient' , action : 'update:any' , attributes : '*' } ,
76+
77+ { role : 'owner' , resource : 'patient' , action : 'delete:any' , attributes : '*' } ,
78+
79+ // supplies
80+ { role : 'professional' , resource : 'supplies' , action : 'read:any' , attributes : '*' } ,
81+ { role : 'pharmacist' , resource : 'supplies' , action : 'read:any' , attributes : '*' } ,
82+ { role : 'admin' , resource : 'supplies' , action : 'create:any' , attributes : '*' } ,
83+ { role : 'admin' , resource : 'supplies' , action : 'update:any' , attributes : '*' } ,
84+ { role : 'andes' , resource : 'andesPrescription' , action : 'create:any' , attributes : '*' }
85+ ] ;
86+ this . accessControl . setGrants ( grantList ) ;
87+ console . log ( 'grants initialized' ) ;
88+ } ;
89+
90+
91+ public asyncForEach = async ( array : any [ ] , callback : Function ) => {
92+ for ( let index = 0 ; index < array . length ; index ++ ) {
93+ await callback ( array [ index ] , index , array ) ;
94+ }
95+ } ;
8996
9097}
9198
0 commit comments