Skip to content

Commit

Permalink
Return more useful error message when finding a domain name contains
Browse files Browse the repository at this point in the history
    non-allowed characters.
Some non-functional formatting and code cleanup.
  • Loading branch information
Misterblue committed Nov 6, 2020
1 parent 1a137f8 commit 4654f30
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/Entities/AccountAvailability.ts
Expand Up @@ -22,13 +22,13 @@ export class AccountAvailability {
public static CONNECTIONS: string = 'connections'; // available to connections
public static ALL: string = 'all'; // available to all

// See if the passed role code is a known role token
static KnownAvailability(pAvailabilit: string): boolean {
// See if the passed availability code is a known availability token
static KnownAvailability(pAvailability: string): boolean {
return [ AccountAvailability.NONE,
AccountAvailability.FRIENDS,
AccountAvailability.CONNECTIONS,
AccountAvailability.ALL
].includes(pAvailabilit);
].includes(pAvailability);
};

};
Expand Down
6 changes: 0 additions & 6 deletions src/Entities/AccountEntity.ts
Expand Up @@ -69,12 +69,6 @@ export class AccountEntity implements Entity {
public timeOfLastHeartbeat: Date; // when we last heard from this user
};

// Helper function that checks to make sure 'availability' is the right value.
// Returns 'true' if availability is legal
export function checkAvailability(pAvailability: string): boolean {
return ['none', 'all', 'friends', 'connections'].includes(pAvailability.toLowerCase());
};

// Get the value of a domain field with the fieldname.
// Checks to make sure the getter has permission to get the values.
// Returns the value. Could be 'undefined' whether the requestor doesn't have permissions or that's
Expand Down
2 changes: 1 addition & 1 deletion src/route-tools/Permissions.ts
Expand Up @@ -15,7 +15,7 @@
'use strict';

import { Entity } from '@Entities/Entity';
import { AccountEntity, checkAvailability } from '@Entities/AccountEntity';
import { AccountEntity } from '@Entities/AccountEntity';
import { DomainEntity } from '@Entities/DomainEntity';
import { AuthToken } from '@Entities/AuthToken';
import { Tokens, TokenScope } from '@Entities/Tokens';
Expand Down
2 changes: 1 addition & 1 deletion src/route-tools/Util.ts
Expand Up @@ -17,7 +17,7 @@
import { Request } from 'express';

import { Accounts } from '@Entities/Accounts';
import { checkAvailability, AccountEntity, setAccountField } from '@Entities/AccountEntity';
import { AccountEntity, setAccountField } from '@Entities/AccountEntity';

import { Domains } from '@Entities/Domains';
import { DomainEntity } from '@Entities/DomainEntity';
Expand Down
4 changes: 2 additions & 2 deletions src/routes/api/v1/domains.ts
Expand Up @@ -64,7 +64,7 @@ const procPostDomains: RequestHandler = async (req: Request, resp: Response, nex
if (req.body && req.body.domain && req.body.domain.label) {
const newDomainName = req.body.domain.label;
if (IsNotNullOrEmpty(newDomainName)) {
if (await domainFields.name.validate(domainFields.name, 'name', newDomainName)) {
if (await domainFields.name.validate(domainFields.name, req.vAuthAccount, newDomainName)) {
const generatedAPIkey: string = GenUUID();

const newDomain = Domains.createDomain();
Expand Down Expand Up @@ -105,7 +105,7 @@ const procPostDomains: RequestHandler = async (req: Request, resp: Response, nex
req.vRestResp.addAdditionalField('domain', domainInfo);
}
else {
req.vRestResp.respondFailure('name contains not allowed characters');
req.vRestResp.respondFailure('domain name can only contain the characters a-zA-Z0-9+-_.');
};
}
else {
Expand Down

0 comments on commit 4654f30

Please sign in to comment.