@@ -187,14 +187,16 @@ app.post('/api/logout', (req, res) => {
187
187
// returned by the casbin function getFilteredPolicy to a map that link
188
188
// an object to the action authorized
189
189
// list[0] contains the policies so list[i][0] is the sciper
190
- // list[i][1] is the object and list[i][2] is the action
191
- function setMapAuthorization ( list : string [ ] [ ] ) {
190
+ // list[i][1] is the subject and list[i][2] is the action
191
+ function setMapAuthorization ( list : string [ ] [ ] ) : Map < String , Array < String > > {
192
192
const m = new Map < String , Array < String > > ( ) ;
193
193
for ( let i = 0 ; i < list . length ; i += 1 ) {
194
- if ( m . has ( list [ i ] [ 1 ] ) ) {
195
- m . get ( list [ i ] [ 1 ] ) ?. push ( list [ i ] [ 2 ] ) ;
194
+ const subject = list [ i ] [ 1 ] ;
195
+ const action = list [ i ] [ 2 ] ;
196
+ if ( m . has ( subject ) ) {
197
+ m . get ( subject ) ?. push ( action ) ;
196
198
} else {
197
- m . set ( list [ i ] [ 1 ] , [ list [ i ] [ 2 ] ] ) ;
199
+ m . set ( subject , [ action ] ) ;
198
200
}
199
201
}
200
202
console . log ( m ) ;
@@ -205,7 +207,6 @@ function setMapAuthorization(list: string[][]) {
205
207
// the react. This endpoint serves to send to the client (actually to react)
206
208
// the information of the current user.
207
209
app . get ( '/api/personal_info' , ( req , res ) => {
208
- const m = new Map < String , Array < String > > ( ) ;
209
210
enf . getFilteredPolicy ( 0 , String ( req . session . userid ) ) . then ( ( list ) => {
210
211
res . set ( 'Access-Control-Allow-Origin' , '*' ) ;
211
212
if ( req . session . userid ) {
@@ -224,7 +225,7 @@ app.get('/api/personal_info', (req, res) => {
224
225
firstname : '' ,
225
226
role : '' ,
226
227
islogged : false ,
227
- authorization : Object . fromEntries ( m ) ,
228
+ authorization : { } ,
228
229
} ) ;
229
230
}
230
231
} ) ;
0 commit comments