From a21648ab4ae15bd21daed0989fad115c4d866838 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Mart=C3=ADn?= Date: Fri, 29 Sep 2017 12:32:46 +0200 Subject: [PATCH] res.locals in layergroup controller --- lib/cartodb/backends/analysis-status.js | 4 +--- lib/cartodb/backends/dataview.js | 8 ++----- lib/cartodb/controllers/layergroup.js | 28 ++++++++++++------------- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/lib/cartodb/backends/analysis-status.js b/lib/cartodb/backends/analysis-status.js index 97f851d2..71ee6fc8 100644 --- a/lib/cartodb/backends/analysis-status.js +++ b/lib/cartodb/backends/analysis-status.js @@ -6,9 +6,7 @@ function AnalysisStatusBackend() { module.exports = AnalysisStatusBackend; -AnalysisStatusBackend.prototype.getNodeStatus = function (params, callback) { - var nodeId = params.nodeId; - +AnalysisStatusBackend.prototype.getNodeStatus = function (nodeId, params, callback) { var statusQuery = [ 'SELECT node_id, status, updated_at, last_error_message as error_message', 'FROM cdb_analysis_catalog where node_id = \'' + nodeId + '\'' diff --git a/lib/cartodb/backends/dataview.js b/lib/cartodb/backends/dataview.js index 29dcd903..8a9c0a85 100644 --- a/lib/cartodb/backends/dataview.js +++ b/lib/cartodb/backends/dataview.js @@ -22,9 +22,7 @@ function DataviewBackend(analysisBackend) { module.exports = DataviewBackend; -DataviewBackend.prototype.getDataview = function (mapConfigProvider, user, params, callback) { - - var dataviewName = params.dataviewName; +DataviewBackend.prototype.getDataview = function (mapConfigProvider, user, dataviewName, params, callback) { step( function getMapConfig() { mapConfigProvider.getMapConfig(this); @@ -113,9 +111,7 @@ function getOverrideParams(params, ownFilter) { return overrideParams; } -DataviewBackend.prototype.search = function (mapConfigProvider, user, params, callback) { - var dataviewName = params.dataviewName; - +DataviewBackend.prototype.search = function (mapConfigProvider, user, dataviewName, params, callback) { step( function getMapConfig() { mapConfigProvider.getMapConfig(this); diff --git a/lib/cartodb/controllers/layergroup.js b/lib/cartodb/controllers/layergroup.js index 2172f6c3..700564fc 100644 --- a/lib/cartodb/controllers/layergroup.js +++ b/lib/cartodb/controllers/layergroup.js @@ -151,7 +151,7 @@ LayergroupController.prototype.analysisNodeStatus = function(req, res, next) { step( function retrieveNodeStatus() { - self.analysisStatusBackend.getNodeStatus(req.params, this); + self.analysisStatusBackend.getNodeStatus(req.params.nodeId, res.locals, this); }, function finish(err, nodeStatus, stats) { req.profiler.add(stats || {}); @@ -175,9 +175,9 @@ LayergroupController.prototype.dataview = function(req, res, next) { step( function retrieveDataview() { var mapConfigProvider = new MapStoreMapConfigProvider( - self.mapStore, req.context.user, self.userLimitsApi, req.params + self.mapStore, req.context.user, self.userLimitsApi, res.locals ); - self.dataviewBackend.getDataview(mapConfigProvider, req.context.user, req.params, this); + self.dataviewBackend.getDataview(mapConfigProvider, req.context.user, req.params.dataviewName, res.locals, this); }, function finish(err, dataview, stats) { req.profiler.add(stats || {}); @@ -198,9 +198,9 @@ LayergroupController.prototype.dataviewSearch = function(req, res, next) { step( function searchDataview() { var mapConfigProvider = new MapStoreMapConfigProvider( - self.mapStore, req.context.user, self.userLimitsApi, req.params + self.mapStore, req.context.user, self.userLimitsApi, res.locals ); - self.dataviewBackend.search(mapConfigProvider, req.context.user, req.params, this); + self.dataviewBackend.search(mapConfigProvider, req.context.user, req.params.dataviewName, res.locals, this); }, function finish(err, searchResult, stats) { req.profiler.add(stats || {}); @@ -224,9 +224,9 @@ LayergroupController.prototype.attributes = function(req, res, next) { step( function retrieveFeatureAttributes() { var mapConfigProvider = new MapStoreMapConfigProvider( - self.mapStore, req.context.user, self.userLimitsApi, req.params + self.mapStore, req.context.user, self.userLimitsApi, res.locals ); - self.attributesBackend.getFeatureAttributes(mapConfigProvider, req.params, false, this); + self.attributesBackend.getFeatureAttributes(mapConfigProvider, res.locals, false, this); }, function finish(err, tile, stats) { req.profiler.add(stats || {}); @@ -260,7 +260,7 @@ LayergroupController.prototype.tileOrLayer = function (req, res, next) { step( function mapController$getTileOrGrid() { self.tileBackend.getTile( - new MapStoreMapConfigProvider(self.mapStore, req.context.user, self.userLimitsApi, req.params), + new MapStoreMapConfigProvider(self.mapStore, req.context.user, self.userLimitsApi, res.locals), req.params, this ); }, @@ -341,11 +341,11 @@ LayergroupController.prototype.staticMap = function(req, res, width, height, zoo function getImage() { if (center) { self.previewBackend.getImage( - new MapStoreMapConfigProvider(self.mapStore, req.context.user, self.userLimitsApi, req.params), + new MapStoreMapConfigProvider(self.mapStore, req.context.user, self.userLimitsApi, res.locals), format, width, height, zoom, center, this); } else { self.previewBackend.getImage( - new MapStoreMapConfigProvider(self.mapStore, req.context.user, self.userLimitsApi, req.params), + new MapStoreMapConfigProvider(self.mapStore, req.context.user, self.userLimitsApi, res.locals), format, width, height, zoom /* bounds */, this); } }, @@ -373,18 +373,18 @@ LayergroupController.prototype.sendResponse = function(req, res, body, status, h // Set Last-Modified header var lastUpdated; - if (req.params.cache_buster) { + if (res.locals.cache_buster) { // Assuming cache_buster is a timestamp - lastUpdated = new Date(parseInt(req.params.cache_buster)); + lastUpdated = new Date(parseInt(res.locals.cache_buster)); } else { lastUpdated = new Date(); } res.set('Last-Modified', lastUpdated.toUTCString()); - var dbName = req.params.dbname; + var dbName = res.locals.dbname; step( function getAffectedTables() { - self.getAffectedTables(req.context.user, dbName, req.params.token, this); + self.getAffectedTables(req.context.user, dbName, res.locals.token, this); }, function sendResponse(err, affectedTables) { req.profiler.done('affectedTables');