Skip to content

Commit 2478fd1

Browse files
committed
Some changes answering the comments
1 parent 810e3dd commit 2478fd1

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

web/backend/src/Server.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,16 @@ app.post('/api/logout', (req, res) => {
187187
// returned by the casbin function getFilteredPolicy to a map that link
188188
// an object to the action authorized
189189
// 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>> {
192192
const m = new Map<String, Array<String>>();
193193
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);
196198
} else {
197-
m.set(list[i][1], [list[i][2]]);
199+
m.set(subject, [action]);
198200
}
199201
}
200202
console.log(m);
@@ -205,7 +207,6 @@ function setMapAuthorization(list: string[][]) {
205207
// the react. This endpoint serves to send to the client (actually to react)
206208
// the information of the current user.
207209
app.get('/api/personal_info', (req, res) => {
208-
const m = new Map<String, Array<String>>();
209210
enf.getFilteredPolicy(0, String(req.session.userid)).then((list) => {
210211
res.set('Access-Control-Allow-Origin', '*');
211212
if (req.session.userid) {
@@ -224,7 +225,7 @@ app.get('/api/personal_info', (req, res) => {
224225
firstname: '',
225226
role: '',
226227
islogged: false,
227-
authorization: Object.fromEntries(m),
228+
authorization: {},
228229
});
229230
}
230231
});

0 commit comments

Comments
 (0)