Skip to content
This repository was archived by the owner on Feb 24, 2023. It is now read-only.

Commit 7f9dd4c

Browse files
authored
Merge pull request #96 from scale8/protected-org-name
Protected org name
2 parents 4af09de + 90e423d commit 7f9dd4c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

api/src/mongo/models/Org.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ import Field from '../decorators/Field';
33
import TimeZones from '../../core/TimeZones';
44
import { ObjectId } from 'mongodb';
55
import User from './User';
6+
import DatabaseError from '../../errors/DatabaseError';
67

78
export default class Org extends Model {
9+
protected readonly RESERVED_ORG_NAME = 'Scale8';
10+
811
public getOrgEntityId(): ObjectId {
912
return this.id;
1013
}
@@ -51,6 +54,9 @@ export default class Org extends Model {
5154
if (orgOwnerUser !== undefined) {
5255
this._org_owner_user_id = orgOwnerUser.id;
5356
}
57+
if (name === this.RESERVED_ORG_NAME && !orgOwnerUser.isAdmin) {
58+
throw new DatabaseError('Protected org name used');
59+
}
5460
this._name = name;
5561
this._tz = tz;
5662
this._manual_invoicing = manualInvoicing;
@@ -65,7 +71,11 @@ export default class Org extends Model {
6571
}
6672

6773
set name(value: string) {
68-
this._name = value;
74+
if (value === this.RESERVED_ORG_NAME) {
75+
throw new DatabaseError('Protected org name used');
76+
} else {
77+
this._name = value;
78+
}
6979
}
7080

7181
get tz(): string {

0 commit comments

Comments
 (0)