Named layers adapter with getMapConfig signature
This commit is contained in:
parent
70750d2c43
commit
efcb73e0d1
@ -15,7 +15,7 @@ function NamedMapProviderCache(templateMaps, pgConnection, metadataBackend, anal
|
||||
this.metadataBackend = metadataBackend;
|
||||
this.userLimitsApi = userLimitsApi;
|
||||
|
||||
this.namedLayersAdapter = new MapConfigNamedLayersAdapter(templateMaps);
|
||||
this.namedLayersAdapter = new MapConfigNamedLayersAdapter(templateMaps, pgConnection);
|
||||
this.analysisMapConfigAdapter = new AnalysisMapConfigAdapter(analysisBackend);
|
||||
this.overviewsAdapter = overviewsAdapter;
|
||||
this.turboCartoAdapter = turboCartoAdapter;
|
||||
|
@ -51,7 +51,7 @@ function MapController(authApi, pgConnection, templateMaps, mapBackend, metadata
|
||||
this.turboCartoAdapter = turboCartoAdapter;
|
||||
|
||||
this.analysisMapConfigAdapter = new AnalysisMapConfigAdapter(analysisBackend);
|
||||
this.namedLayersAdapter = new MapConfigNamedLayersAdapter(templateMaps);
|
||||
this.namedLayersAdapter = new MapConfigNamedLayersAdapter(templateMaps, pgConnection);
|
||||
this.overviewsAdapter = overviewsAdapter;
|
||||
this.sqlWrapMapConfigAdapter = new SqlWrapMapConfigAdapter();
|
||||
}
|
||||
@ -169,7 +169,7 @@ MapController.prototype.create = function(req, res, prepareConfigFn) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
analysesResults = _analysesResults;
|
||||
self.namedLayersAdapter.getMapConfig(req.context.user, requestMapConfig, self.pgConnection,
|
||||
self.namedLayersAdapter.getMapConfig(user, requestMapConfig, req.params, context,
|
||||
function(err, requestMapConfig, datasource) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
|
@ -2,13 +2,14 @@ var queue = require('queue-async');
|
||||
var _ = require('underscore');
|
||||
var Datasource = require('windshaft').model.Datasource;
|
||||
|
||||
function MapConfigNamedLayersAdapter(templateMaps) {
|
||||
function MapConfigNamedLayersAdapter(templateMaps, pgConnection) {
|
||||
this.templateMaps = templateMaps;
|
||||
this.pgConnection = pgConnection;
|
||||
}
|
||||
|
||||
module.exports = MapConfigNamedLayersAdapter;
|
||||
|
||||
MapConfigNamedLayersAdapter.prototype.getMapConfig = function(username, requestMapConfig, dbMetadata, callback) {
|
||||
MapConfigNamedLayersAdapter.prototype.getMapConfig = function (user, requestMapConfig, params, context, callback) {
|
||||
var self = this;
|
||||
|
||||
var layers = requestMapConfig.layers;
|
||||
@ -30,9 +31,9 @@ MapConfigNamedLayersAdapter.prototype.getMapConfig = function(username, requestM
|
||||
var templateConfigParams = layer.options.config || {};
|
||||
var templateAuthTokens = layer.options.auth_tokens;
|
||||
|
||||
self.templateMaps.getTemplate(username, templateName, function(err, template) {
|
||||
self.templateMaps.getTemplate(user, templateName, function(err, template) {
|
||||
if (err || !template) {
|
||||
return done(new Error("Template '" + templateName + "' of user '" + username + "' not found"));
|
||||
return done(new Error("Template '" + templateName + "' of user '" + user + "' not found"));
|
||||
}
|
||||
|
||||
if (self.templateMaps.isAuthorized(template, templateAuthTokens)) {
|
||||
@ -108,7 +109,7 @@ MapConfigNamedLayersAdapter.prototype.getMapConfig = function(username, requestM
|
||||
|
||||
if (_.some(layers, isNamedTypeLayer)) {
|
||||
// Lazy load dbAuth
|
||||
dbMetadata.setDBAuth(username, dbAuth, function(err) {
|
||||
this.pgConnection.setDBAuth(user, dbAuth, function(err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ NamedMapMapConfigProvider.prototype.getMapConfig = function(callback) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
self.analysesResults = analysesResults || [];
|
||||
self.namedLayersAdapter.getMapConfig(self.owner, _mapConfig, self.pgConnection,
|
||||
self.namedLayersAdapter.getMapConfig(self.owner, _mapConfig, rendererParams, context,
|
||||
function(err, _mapConfig, datasource) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
|
@ -14,7 +14,7 @@ var templateMaps = new TemplateMaps(redisPool, {
|
||||
max_user_templates: global.environment.maxUserTemplates
|
||||
});
|
||||
|
||||
var mapConfigNamedLayersAdapter = new MapConfigNamedLayersAdapter(templateMaps);
|
||||
var mapConfigNamedLayersAdapter = new MapConfigNamedLayersAdapter(templateMaps, pgConnection);
|
||||
|
||||
var wadusSql = 'select 1 wadusLayer, null::geometry the_geom_webmercator';
|
||||
var wadusLayer = {
|
||||
@ -294,7 +294,9 @@ describe('named_layers datasources', function() {
|
||||
|
||||
testScenarios.forEach(function(testScenario) {
|
||||
it('should return a list of layers ' + testScenario.desc, function(done) {
|
||||
mapConfigNamedLayersAdapter.getMapConfig(username, testScenario.config, pgConnection,
|
||||
var params = {};
|
||||
var context = {};
|
||||
mapConfigNamedLayersAdapter.getMapConfig(username, testScenario.config, params, context,
|
||||
function(err, mapConfig, datasource) {
|
||||
testScenario.test(err, mapConfig.layers, datasource, done);
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ describe('mapconfig-named-layers-adapter', function() {
|
||||
max_user_templates: global.environment.maxUserTemplates
|
||||
});
|
||||
|
||||
var mapConfigNamedLayersAdapter = new MapConfigNamedLayersAdapter(templateMaps);
|
||||
var mapConfigNamedLayersAdapter = new MapConfigNamedLayersAdapter(templateMaps, pgConnection);
|
||||
|
||||
var wadusLayer = {
|
||||
type: 'cartodb',
|
||||
@ -134,6 +134,8 @@ describe('mapconfig-named-layers-adapter', function() {
|
||||
};
|
||||
}
|
||||
|
||||
var params = {};
|
||||
var context = {};
|
||||
|
||||
beforeEach(function(done) {
|
||||
templateMaps.addTemplate(username, template, done);
|
||||
@ -147,7 +149,7 @@ describe('mapconfig-named-layers-adapter', function() {
|
||||
var missingNamedMapLayerConfig = makeNamedMapLayerConfig({
|
||||
config: {}
|
||||
});
|
||||
mapConfigNamedLayersAdapter.getMapConfig(username, missingNamedMapLayerConfig, pgConnection,
|
||||
mapConfigNamedLayersAdapter.getMapConfig(username, missingNamedMapLayerConfig, params, context,
|
||||
function(err, mapConfig, datasource) {
|
||||
assert.ok(err);
|
||||
assert.ok(!mapConfig);
|
||||
@ -164,7 +166,7 @@ describe('mapconfig-named-layers-adapter', function() {
|
||||
var nonExistentNamedMapLayerConfig = makeNamedMapLayerConfig({
|
||||
name: missingTemplateName
|
||||
});
|
||||
mapConfigNamedLayersAdapter.getMapConfig(username, nonExistentNamedMapLayerConfig, pgConnection,
|
||||
mapConfigNamedLayersAdapter.getMapConfig(username, nonExistentNamedMapLayerConfig, params, context,
|
||||
function(err, mapConfig, datasource) {
|
||||
assert.ok(err);
|
||||
assert.ok(!mapConfig);
|
||||
@ -187,7 +189,7 @@ describe('mapconfig-named-layers-adapter', function() {
|
||||
var nonAuthTokensNamedMapLayerConfig = makeNamedMapLayerConfig({
|
||||
name: tokenAuthTemplateName
|
||||
});
|
||||
mapConfigNamedLayersAdapter.getMapConfig(username, nonAuthTokensNamedMapLayerConfig, pgConnection,
|
||||
mapConfigNamedLayersAdapter.getMapConfig(username, nonAuthTokensNamedMapLayerConfig, params, context,
|
||||
function(err, mapConfig, datasource) {
|
||||
assert.ok(err);
|
||||
assert.ok(!mapConfig);
|
||||
@ -209,7 +211,7 @@ describe('mapconfig-named-layers-adapter', function() {
|
||||
var nestedNamedMapLayerConfig = makeNamedMapLayerConfig({
|
||||
name: nestedNamedMapTemplateName
|
||||
});
|
||||
mapConfigNamedLayersAdapter.getMapConfig(username, nestedNamedMapLayerConfig, pgConnection,
|
||||
mapConfigNamedLayersAdapter.getMapConfig(username, nestedNamedMapLayerConfig, params, context,
|
||||
function(err, mapConfig, datasource) {
|
||||
assert.ok(err);
|
||||
assert.ok(!mapConfig);
|
||||
@ -226,7 +228,7 @@ describe('mapconfig-named-layers-adapter', function() {
|
||||
var validNamedMapMapLayerConfig = makeNamedMapLayerConfig({
|
||||
name: templateName
|
||||
});
|
||||
mapConfigNamedLayersAdapter.getMapConfig(username, validNamedMapMapLayerConfig, pgConnection,
|
||||
mapConfigNamedLayersAdapter.getMapConfig(username, validNamedMapMapLayerConfig, params, context,
|
||||
function(err, mapConfig, datasource) {
|
||||
assert.ok(!err);
|
||||
var layers = mapConfig.layers;
|
||||
@ -249,7 +251,7 @@ describe('mapconfig-named-layers-adapter', function() {
|
||||
name: tokenAuthTemplateName,
|
||||
auth_tokens: ['valid1']
|
||||
});
|
||||
mapConfigNamedLayersAdapter.getMapConfig(username, validAuthTokensNamedMapLayerConfig, pgConnection,
|
||||
mapConfigNamedLayersAdapter.getMapConfig(username, validAuthTokensNamedMapLayerConfig, params, context,
|
||||
function(err, mapConfig, datasource) {
|
||||
assert.ok(!err);
|
||||
var layers = mapConfig.layers;
|
||||
@ -272,7 +274,7 @@ describe('mapconfig-named-layers-adapter', function() {
|
||||
name: multipleLayersTemplateName,
|
||||
auth_tokens: ['valid2']
|
||||
});
|
||||
mapConfigNamedLayersAdapter.getMapConfig(username, multipleLayersNamedMapLayerConfig, pgConnection,
|
||||
mapConfigNamedLayersAdapter.getMapConfig(username, multipleLayersNamedMapLayerConfig, params, context,
|
||||
function(err, mapConfig, datasource) {
|
||||
assert.ok(!err);
|
||||
var layers = mapConfig.layers;
|
||||
@ -309,7 +311,7 @@ describe('mapconfig-named-layers-adapter', function() {
|
||||
},
|
||||
auth_tokens: ['valid2']
|
||||
});
|
||||
mapConfigNamedLayersAdapter.getMapConfig(username, multipleLayersNamedMapLayerConfig, pgConnection,
|
||||
mapConfigNamedLayersAdapter.getMapConfig(username, multipleLayersNamedMapLayerConfig, params, context,
|
||||
function(err, mapConfig, datasource) {
|
||||
assert.ok(!err);
|
||||
var layers = mapConfig.layers;
|
||||
|
Loading…
Reference in New Issue
Block a user