From 90e423d51e1585218ad73d971c72fabdf173f501 Mon Sep 17 00:00:00 2001 From: Christopher Beck Date: Sun, 29 May 2022 09:14:58 +0100 Subject: [PATCH] Protected org name --- api/src/mongo/models/Org.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/api/src/mongo/models/Org.ts b/api/src/mongo/models/Org.ts index bea37288..29ee9bf5 100644 --- a/api/src/mongo/models/Org.ts +++ b/api/src/mongo/models/Org.ts @@ -3,8 +3,11 @@ import Field from '../decorators/Field'; import TimeZones from '../../core/TimeZones'; import { ObjectId } from 'mongodb'; import User from './User'; +import DatabaseError from '../../errors/DatabaseError'; export default class Org extends Model { + protected readonly RESERVED_ORG_NAME = 'Scale8'; + public getOrgEntityId(): ObjectId { return this.id; } @@ -51,6 +54,9 @@ export default class Org extends Model { if (orgOwnerUser !== undefined) { this._org_owner_user_id = orgOwnerUser.id; } + if (name === this.RESERVED_ORG_NAME && !orgOwnerUser.isAdmin) { + throw new DatabaseError('Protected org name used'); + } this._name = name; this._tz = tz; this._manual_invoicing = manualInvoicing; @@ -65,7 +71,11 @@ export default class Org extends Model { } set name(value: string) { - this._name = value; + if (value === this.RESERVED_ORG_NAME) { + throw new DatabaseError('Protected org name used'); + } else { + this._name = value; + } } get tz(): string {