Merge pull request #847 from CartoDB/fix-res-locals-named-maps

Do not pass the entire res.locals to named maps provider cache
This commit is contained in:
Daniel 2018-01-15 19:02:01 +01:00 committed by GitHub
commit 128ab53c55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,6 +16,17 @@ function numMapper(n) {
return +n;
}
function getRequestParams(locals) {
const params = Object.assign({}, locals);
delete params.template;
delete params.affectedTablesAndLastUpdate;
delete params.namedMapProvider;
delete params.allowedQueryParams;
return params;
}
function NamedMapsController(prepareContext, namedMapProviderCache, tileBackend, previewBackend,
surrogateKeysCache, tablesExtentApi, metadataBackend) {
this.namedMapProviderCache = namedMapProviderCache;
@ -74,8 +85,9 @@ NamedMapsController.prototype.getNamedMapProvider = function (label) {
const { user } = res.locals;
const { config, auth_token } = req.query;
const { template_id } = req.params;
const params = getRequestParams(res.locals);
this.namedMapProviderCache.get(user, template_id, config, auth_token, res.locals, (err, namedMapProvider) => {
this.namedMapProviderCache.get(user, template_id, config, auth_token, params, (err, namedMapProvider) => {
if (err) {
err.label = label;
return next(err);
@ -146,11 +158,13 @@ NamedMapsController.prototype.prepareLayerFilterFromPreviewLayers = function (la
return next();
}
const params = getRequestParams(res.locals);
// overwrites 'all' default filter
res.locals.layer = layerVisibilityFilter.join(',');
params.layer = layerVisibilityFilter.join(',');
// recreates the provider
this.namedMapProviderCache.get(user, template_id, config, auth_token, res.locals, (err, provider) => {
this.namedMapProviderCache.get(user, template_id, config, auth_token, params, (err, provider) => {
if (err) {
err.label = label;
return next(err);