diff --git a/lib/cartodb/controllers/named_maps_admin.js b/lib/cartodb/controllers/named_maps_admin.js index 0f54ddf3..8fcaaac0 100644 --- a/lib/cartodb/controllers/named_maps_admin.js +++ b/lib/cartodb/controllers/named_maps_admin.js @@ -198,6 +198,26 @@ NamedMapsAdminController.prototype.list = function(req, res, next) { ); }; +NamedMapsAdminController.prototype.authorizedByAPIKey = function (action) { + return function authorizedByAPIKeyMiddleware (req, res, next) { + const { user } = res.locals; + + this.authApi.authorizedByAPIKey(user, req, (err, authenticated) => { + if (err) { + return next(err); + } + + if (!authenticated) { + const error = new Error(`Only authenticated user can ${action} templated maps`); + error.http_status = 403; + return next(error); + } + + next(); + }); + }.bind(this); +}; + function finishFn(controller, req, res, description, status, next) { return function finish(err, body){ if (err) {