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

Commit

Permalink
Merge pull request #96 from scale8/protected-org-name
Browse files Browse the repository at this point in the history
Protected org name
  • Loading branch information
a-barzanti authored May 29, 2022
2 parents 4af09de + 90e423d commit 7f9dd4c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion api/src/mongo/models/Org.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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 {
Expand Down

0 comments on commit 7f9dd4c

Please sign in to comment.