Skip to content

Commit

Permalink
Allow setting of Place 'address' field with full path address.
Browse files Browse the repository at this point in the history
  • Loading branch information
Misterblue committed Oct 26, 2021
1 parent afa01d0 commit 4dced54
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/Entities/PlaceFields.ts
Expand Up @@ -29,7 +29,7 @@ import { Perm } from '@Route-Tools/Perm';
import { checkAccessToEntity } from '@Route-Tools/Permissions';

import { FieldDefn, ValidateResponse } from '@Route-Tools/EntityFieldDefn';
import { isStringValidator, isSArraySet, isPathValidator, isDateValidator, isObjectValidator, isNumberValidator } from '@Route-Tools/Validators';
import { isStringValidator, isSArraySet, isPathValidator, isLongPathValidator, isDateValidator, isObjectValidator, isNumberValidator } from '@Route-Tools/Validators';
import { simpleGetter, simpleSetter, noSetter, sArraySetter, dateStringGetter, verifyAllSArraySetValues} from '@Route-Tools/Validators';

import { IsNullOrEmpty, IsNotNullOrEmpty } from '@Tools/Misc';
Expand Down Expand Up @@ -141,11 +141,11 @@ export const placeFields: { [key: string]: FieldDefn } = {
entity_field: 'path',
request_field_name: 'address',
get_permissions: [ Perm.ALL ],
set_permissions: [ Perm.NONE ],
validate: isPathValidator,
setter: noSetter,
set_permissions: [ Perm.DOMAINACCESS, Perm.MANAGER, Perm.ADMIN ],
validate: isLongPathValidator,
setter: simpleSetter,
getter: async (pField: FieldDefn, pEntity: Entity): Promise<any> => {
return Places.getAddressString(pEntity as PlaceEntity);
return await Places.getAddressString(pEntity as PlaceEntity);
}
},
'path': { // the address within the domain
Expand Down
16 changes: 13 additions & 3 deletions src/route-tools/Validators.ts
Expand Up @@ -53,10 +53,20 @@ export async function isPathValidator(pField: FieldDefn, pEntity: Entity, pValue
// if (/^[\w\.:+_-]*\/-?\d+(\.\d*)?,-?\d+(\.\d*)?,-?\d+(\.\d*)?\/-?\d+(\.\d*)?,-?\d+(\.\d*)?,-?\d+(\.\d*)?,-?\d+(\.\d*)?$/.test(pValue)) {
// Regexp to check format of "/float,float,float/float,float,float,float"
// This make a "path" just the position and rotation within a domain
if (/^\/-?\d+(\.\d*)?,-?\d+(\.\d*)?,-?\d+(\.\d*)?\/-?\d+(\.\d*)?,-?\d+(\.\d*)?,-?\d+(\.\d*)?,-?\d+(\.\d*)?$/.test(pValue)) {
return { valid: true };
if (typeof(pValue) === 'string') {
if (/^\/-?\d+(\.\d*)?,-?\d+(\.\d*)?,-?\d+(\.\d*)?\/-?\d+(\.\d*)?,-?\d+(\.\d*)?,-?\d+(\.\d*)?,-?\d+(\.\d*)?$/.test(pValue)) {
return { valid: true };
};
};
return { valid: false, reason: 'path must be a string of the form "/f,f,f/f,f,f,f' };
};
export async function isLongPathValidator(pField: FieldDefn, pEntity: Entity, pValue: any): Promise<ValidateResponse> {
if (typeof(pValue) === 'string') {
if (/^.*\/-?\d+(\.\d*)?,-?\d+(\.\d*)?,-?\d+(\.\d*)?\/-?\d+(\.\d*)?,-?\d+(\.\d*)?,-?\d+(\.\d*)?,-?\d+(\.\d*)?$/.test(pValue)) {
return { valid: true };
};
};
return { valid: false, reason: 'path must have the form "optional-network-addr/f,f,f/f,f,f,f' };
return { valid: false, reason: 'path must be a string of the form "optional-domain/f,f,f/f,f,f,f' };
};
export async function isDateValidator(pField: FieldDefn, pEntity: Entity, pValue: any): Promise<ValidateResponse> {
if (pValue instanceof Date) {
Expand Down

0 comments on commit 4dced54

Please sign in to comment.