Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude modifications for regional analysis lookup #926

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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