Skip to content

Commit

Permalink
fix: fix SCIPER verification and add it to adding policy functions
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalinDe committed May 1, 2024
1 parent ca99a06 commit 015e8e2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions web/backend/src/authManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ export function setMapAuthorization(list: string[][]): Map<String, Array<String>
// the range between 100000 and 999999, an error is thrown.
export function readSCIPER(s: string): number {
const n = parseInt(s, 10);
if (isNaN(n)) {

Check failure on line 102 in web/backend/src/authManager.ts

View workflow job for this annotation

GitHub Actions / Web backend Lint

Unexpected use of 'isNaN'. Use Number.isNaN instead https://github.com/airbnb/javascript#standard-library--isnan
throw new Error(`${s} is not a number`);
}
if (n < 100000 || n > 999999) {
throw new Error(`SCIPER is out of range. ${n} is not between 100000 and 999999`);
}
Expand Down
11 changes: 10 additions & 1 deletion web/backend/src/controllers/users.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import express from 'express';

import { addPolicy, addListPolicy, initEnforcer, isAuthorized, PERMISSIONS } from '../authManager';
import {
addPolicy,
addListPolicy,
initEnforcer,
isAuthorized,
PERMISSIONS,
readSCIPER,
} from '../authManager';

export const usersRouter = express.Router();

Expand Down Expand Up @@ -36,6 +43,7 @@ usersRouter.post('/add_role', (req, res, next) => {

if ('userId' in req.body) {
try {
readSCIPER(req.body.userId);
addPolicy(req.body.userId, req.body.subject, req.body.permission);
} catch (error) {
res.status(400).send(`Error while adding single user to roles: ${error}`);
Expand All @@ -45,6 +53,7 @@ usersRouter.post('/add_role', (req, res, next) => {
next();
} else if ('userIds' in req.body) {
try {
req.body.userIds.every(readSCIPER);
addListPolicy(req.body.userIds, req.body.subject, req.body.permission);
} catch (error) {
res.status(400).send(`Error while adding multiple users to roles: ${error}`);
Expand Down

0 comments on commit 015e8e2

Please sign in to comment.