From cf2b73e4732ad3e068399f6f50cc074dd75c1e42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Fri, 29 Dec 2017 15:19:52 +0100 Subject: [PATCH] Move to up intermediate middlewares --- lib/cartodb/controllers/named_maps_admin.js | 64 ++++++++++----------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/lib/cartodb/controllers/named_maps_admin.js b/lib/cartodb/controllers/named_maps_admin.js index 2efac8cc..4d866b9b 100644 --- a/lib/cartodb/controllers/named_maps_admin.js +++ b/lib/cartodb/controllers/named_maps_admin.js @@ -65,6 +65,38 @@ NamedMapsAdminController.prototype.register = function (app) { ); }; +NamedMapsAdminController.prototype.authorizedByAPIKey = function (action, label) { + 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; + error.label = label; + return next(error); + } + + next(); + }); + }.bind(this); +}; + +NamedMapsAdminController.prototype.checkContentType = function (action, label) { + return function checkContentTypeMiddleware (req, res, next) { + if (!req.is('application/json')) { + const error = new Error(`template ${action} data must be of type application/json`); + error.label = label; + return next(error); + } + next(); + }; +}; + NamedMapsAdminController.prototype.create = function(req, res, next) { const cdbuser = res.locals.user; const cfg = req.body; @@ -159,35 +191,3 @@ NamedMapsAdminController.prototype.list = function(req, res, next) { res[method]({ template_ids: tpl_ids }); }); }; - -NamedMapsAdminController.prototype.authorizedByAPIKey = function (action, label) { - 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; - error.label = label; - return next(error); - } - - next(); - }); - }.bind(this); -}; - -NamedMapsAdminController.prototype.checkContentType = function (action, label) { - return function checkContentTypeMiddleware (req, res, next) { - if (!req.is('application/json')) { - const error = new Error(`template ${action} data must be of type application/json`); - error.label = label; - return next(error); - } - next(); - }; -};