Skip to content

Commit

Permalink
Exclude modifications for regional analysis lookup (#926)
Browse files Browse the repository at this point in the history
This change adds a new helper method to pass a `fields` object to `MongoMap#findByIdIfPermitted` and utilizes that to exclude modifications while looking up a regional analysis to generate a `scenarioJsonUrl`.

This will prevent errors from occurring if custom modifications are used in a worker version that do not exist in the server.
  • Loading branch information
trevorgerhardt authored Jan 26, 2024
1 parent 584aafa commit 32eb1dc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,11 @@ private RegionalAnalysis updateRegionalAnalysis (Request request, Response respo
* the given regional analysis.
*/
private JsonNode getScenarioJsonUrl (Request request, Response response) {
RegionalAnalysis regionalAnalysis = Persistence.regionalAnalyses
.findByIdIfPermitted(request.params("_id"), UserPermissions.from(request));
RegionalAnalysis regionalAnalysis = Persistence.regionalAnalyses.findByIdIfPermitted(
request.params("_id"),
DBProjection.exclude("request.scenario.modifications"),
UserPermissions.from(request)
);
// In the persisted objects, regionalAnalysis.scenarioId seems to be null. Get it from the embedded request.
final String networkId = regionalAnalysis.bundleId;
final String scenarioId = regionalAnalysis.request.scenarioId;
Expand Down
19 changes: 13 additions & 6 deletions src/main/java/com/conveyal/analysis/persistence/MongoMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@ public int size() {
return (int) wrappedCollection.getCount();
}

public V findByIdFromRequestIfPermitted(Request request) {
return findByIdIfPermitted(request.params("_id"), UserPermissions.from(request));
}

public V findByIdIfPermitted(String id, UserPermissions userPermissions) {
V result = wrappedCollection.findOneById(id);
/**
* `fields` is nullable.
*/
public V findByIdIfPermitted(String id, DBObject fields, UserPermissions userPermissions) {
V result = wrappedCollection.findOneById(id, fields);

if (result == null) {
throw AnalysisServerException.notFound(String.format(
Expand All @@ -61,6 +60,14 @@ public V findByIdIfPermitted(String id, UserPermissions userPermissions) {
}
}

public V findByIdIfPermitted(String id, UserPermissions userPermissions) {
return findByIdIfPermitted(id, null, userPermissions);
}

public V findByIdFromRequestIfPermitted(Request request) {
return findByIdIfPermitted(request.params("_id"), UserPermissions.from(request));
}

public V get(String key) {
return wrappedCollection.findOneById(key);
}
Expand Down

0 comments on commit 32eb1dc

Please sign in to comment.