From 81a65c5227009c556fb4bf1c95f235269bd64577 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Minelli?= <michael@minelli.me> Date: Fri, 16 Jun 2023 20:30:28 +0200 Subject: [PATCH] User => Add teaching permissions test --- ExpressAPI/src/config/Config.ts | 8 ++++++++ ExpressAPI/src/models/User.ts | 17 +++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/ExpressAPI/src/config/Config.ts b/ExpressAPI/src/config/Config.ts index 980b12f..8969008 100644 --- a/ExpressAPI/src/config/Config.ts +++ b/ExpressAPI/src/config/Config.ts @@ -12,6 +12,10 @@ class Config { public readonly jwtSecretKey: string; public readonly sessionTimeout: number; + public permissions: { + teachingStaff: Array<string>; + }; + public readonly userPasswordLength: number; public readonly userPasswordSaltRounds: number; @@ -32,6 +36,10 @@ class Config { this.jwtSecretKey = process.env.JWT_SECRET_KEY; this.sessionTimeout = Number(process.env.SESSION_TIMEOUT); + this.permissions = { + teachingStaff: JSON.parse(process.env.ROLES_WITH_TEACHING_STAFF_PERMISSIONS) + }; + this.userPasswordLength = Number(process.env.USER_PASSWORD_LENGTH); this.userPasswordSaltRounds = Number(process.env.USER_PASSWORD_SALT_ROUNDS); } diff --git a/ExpressAPI/src/models/User.ts b/ExpressAPI/src/models/User.ts index 65e5b37..78cb68c 100644 --- a/ExpressAPI/src/models/User.ts +++ b/ExpressAPI/src/models/User.ts @@ -24,12 +24,13 @@ class User extends Model { public async toJsonObject(lightVersion: boolean): Promise<Object> { const result = { - 'id' : this.userID, - 'firstName': this.userFirstName, - 'lastName' : this.userLastName, - 'mail' : this.userMail, - 'role' : this.userRole, - 'deleted' : this.userDeleted + 'id' : this.userID, + 'firstName' : this.userFirstName, + 'lastName' : this.userLastName, + 'mail' : this.userMail, + 'role' : this.userRole, + 'isTeachingStaff': this.isTeachingStaff, + 'deleted' : this.userDeleted }; return result; @@ -39,6 +40,10 @@ class User extends Model { return this.userLastName.toUpperCase() + ' ' + this.userFirstName; } + get isTeachingStaff(): boolean { + return Config.permissions.teachingStaff.includes(this.userRole); + } + public importFromJsonObject(jsonObject: any) { this.userID = jsonObject.id; this.userFirstName = jsonObject.firstName; -- GitLab