diff --git a/ExpressAPI/src/config/Config.ts b/ExpressAPI/src/config/Config.ts index 980b12f686a3f6d5b62053e1763a0e7c266f2216..8969008c9980168af765554c7ed0f356621ef0bd 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 65e5b37221a5108bb8884fec26deee4fa4bcac32..78cb68ce4f157082294c09119f013033e25cee16 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;