From b82767c60d6bd4f082a75969a99533ea141878ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Mon, 15 Jan 2018 17:08:54 +0100 Subject: [PATCH 1/2] Pass a copy of res.locals w/o new data boud to named-map-provider-cache --- lib/cartodb/controllers/named_maps.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/cartodb/controllers/named_maps.js b/lib/cartodb/controllers/named_maps.js index f668d638..9f848495 100644 --- a/lib/cartodb/controllers/named_maps.js +++ b/lib/cartodb/controllers/named_maps.js @@ -74,8 +74,9 @@ NamedMapsController.prototype.getNamedMapProvider = function (label) { const { user } = res.locals; const { config, auth_token } = req.query; const { template_id } = req.params; + const params = Object.assign({}, 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 +147,17 @@ NamedMapsController.prototype.prepareLayerFilterFromPreviewLayers = function (la return next(); } + const params = Object.assign({}, res.locals); + + delete params.template; + delete params.affectedTablesAndLastUpdate; + delete params.namedMapProvider; + // 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); From ce4050e3e34e43d75ad4f99614b106677c518e6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Mon, 15 Jan 2018 18:09:54 +0100 Subject: [PATCH 2/2] Extrac method to get only user params --- lib/cartodb/controllers/named_maps.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/cartodb/controllers/named_maps.js b/lib/cartodb/controllers/named_maps.js index 9f848495..f3aff5bd 100644 --- a/lib/cartodb/controllers/named_maps.js +++ b/lib/cartodb/controllers/named_maps.js @@ -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,7 +85,7 @@ NamedMapsController.prototype.getNamedMapProvider = function (label) { const { user } = res.locals; const { config, auth_token } = req.query; const { template_id } = req.params; - const params = Object.assign({}, res.locals); + const params = getRequestParams(res.locals); this.namedMapProviderCache.get(user, template_id, config, auth_token, params, (err, namedMapProvider) => { if (err) { @@ -147,11 +158,7 @@ NamedMapsController.prototype.prepareLayerFilterFromPreviewLayers = function (la return next(); } - const params = Object.assign({}, res.locals); - - delete params.template; - delete params.affectedTablesAndLastUpdate; - delete params.namedMapProvider; + const params = getRequestParams(res.locals); // overwrites 'all' default filter params.layer = layerVisibilityFilter.join(',');