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