Skip to content

Commit 41220e7

Browse files
committed
adapt geo-extracts to entity UUIDs, and "uuid:"-prefixed entity UUIDs
1 parent 867c292 commit 41220e7

File tree

4 files changed

+8
-14
lines changed

4 files changed

+8
-14
lines changed

lib/model/query/geo-extracts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ const getSubmissionFeatureCollectionGeoJson = (formPK, IDs, fieldPaths, submitte
186186

187187
const getEntityFeatureCollectionGeoJson = (datasetPK, IDs, creatorIds, TSTZRange, conflictStates, deleted, limit, search) => ({ db }) => {
188188

189-
const idFilter = arrayHasElements(IDs) ? sql`AND e.uuid = ANY(${sql.array(IDs, 'text')})` : sql``; // TODO: this should be a uuid[] array once/if the entities."uuid" column is converted from varchar(255) to uuid
189+
const idFilter = arrayHasElements(IDs) ? sql`AND e.uuid = ANY(${sql.array(IDs, 'uuid')})` : sql``;
190190
const creatorFilter = arrayHasElements(creatorIds) ? sql`AND e."creatorId" = ANY(${sql.array(creatorIds, 'int4')})` : sql``;
191191
const TSTZRangeFilter = arrayHasElements(TSTZRange) ? sql`AND e."createdAt" <@ tstzrange(${TSTZRange[0]}, ${TSTZRange[1]}, ${TSTZRange[2]})` : sql``;
192192
const conflictStatusFilter = arrayHasElements(conflictStates) ? sql`AND ${stateFilterToQueryFragments(['e', 'conflict'], conflictStates, 'conflictType')}` : sql``;

lib/resources/entities.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const { Entity } = require('../model/frames');
1313
const Problem = require('../util/problem');
1414
const { diffEntityData, extractBulkSource, getWithConflictDetails } = require('../data/entity');
1515
const { QueryOptions } = require('../util/db');
16-
const { Constants } = require('../constants');
16+
const { normalizeUuid } = require('../data/entity');
1717

1818
module.exports = (service, endpoint) => {
1919

@@ -92,22 +92,16 @@ module.exports = (service, endpoint) => {
9292
service.get('/projects/:projectId/datasets/:name/entities/:uuid/geojson', endpoint.plain(async ({ Datasets, Entities, GeoExtracts }, { params, auth }) => {
9393

9494
// Saves a query and gives informative feedback if we do this straight away
95-
if (!Constants.UUIDRegex.test(params.uuid)) {
96-
throw Problem.user.unexpectedValue({
97-
field: 'URL UUID path component',
98-
value: params.uuid,
99-
reason: `is not interpretable as a UUID: ${params.uuid}`,
100-
});
101-
}
95+
const entityUuid = normalizeUuid(params.uuid);
10296

10397
const dataset = await Datasets.get(params.projectId, params.name, true).then(getOrNotFound);
10498
await auth.canOrReject('entity.read', dataset);
10599

106100
// We need to get the entity itself to see if it exists (and if not, return a 404).
107101
// That's because when getting the geodata, we can't distinguish between the entity not having any geodata (or having invalid geodata)
108102
// and the entity itself not existing.
109-
await Entities.getById(dataset.id, params.uuid).then(getOrNotFound);
110-
return GeoExtracts.getEntityFeatureCollectionGeoJson(dataset.id, [params.uuid]).then(json);
103+
await Entities.getById(dataset.id, entityUuid).then(getOrNotFound);
104+
return GeoExtracts.getEntityFeatureCollectionGeoJson(dataset.id, [entityUuid]).then(json);
111105
}));
112106

113107

lib/resources/geo-extracts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ module.exports = (service, endpoint) => {
6363

6464
return GeoExtracts.getEntityFeatureCollectionGeoJson(
6565
foundDataset.id,
66-
Sanitize.queryParamToUuidArray(query.entityUUID, 'entityUUID'),
66+
Sanitize.queryParamToUuidArray(query.entityUUID, 'entityUUID', true),
6767
Sanitize.queryParamToIntArray(query.creatorId, 'creatorId'),
6868
Sanitize.getTSTZRangeFromQueryParams(query),
6969
Sanitize.getEntityConflictStates(query.conflict, 'conflict'),

lib/util/param-sanitize.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ class Sanitize {
5757
}
5858

5959

60-
static queryParamToUuidArray(queryParam, queryParamName) {
60+
static queryParamToUuidArray(queryParam, queryParamName, stripUuidColonPrefix=false) {
6161
return this.queryParamToArray(queryParam).map(el => {
62-
const trimmed = el.trim();
62+
const trimmed = stripUuidColonPrefix ? el.trim().replace(/^uuid:/, '') : el.trim();
6363
if (!Constants.UUIDRegex.test(trimmed)) {
6464
throw Problem.user.unexpectedValue({
6565
field: `query parameter '${queryParamName}'`,

0 commit comments

Comments
 (0)