Rename AuthAppi by AuthBackend
This commit is contained in:
@@ -4,13 +4,13 @@ const rateLimit = require('../middlewares/rate-limit');
|
||||
const { RATE_LIMIT_ENDPOINTS_GROUPS } = rateLimit;
|
||||
|
||||
/**
|
||||
* @param {AuthApi} authApi
|
||||
* @param {AuthBackend} authBackend
|
||||
* @param {PgConnection} pgConnection
|
||||
* @param {TemplateMaps} templateMaps
|
||||
* @constructor
|
||||
*/
|
||||
function AdminTemplateController(authApi, templateMaps, userLimitsApi) {
|
||||
this.authApi = authApi;
|
||||
function AdminTemplateController(authBackend, templateMaps, userLimitsApi) {
|
||||
this.authBackend = authBackend;
|
||||
this.templateMaps = templateMaps;
|
||||
this.userLimitsApi = userLimitsApi;
|
||||
}
|
||||
@@ -23,7 +23,7 @@ AdminTemplateController.prototype.register = function (templateRouter) {
|
||||
templateRouter.post(
|
||||
`/`,
|
||||
credentials(),
|
||||
authorizedByAPIKey({ authApi: this.authApi, action: 'create', label: 'POST TEMPLATE' }),
|
||||
authorizedByAPIKey({ authBackend: this.authBackend, action: 'create', label: 'POST TEMPLATE' }),
|
||||
rateLimit(this.userLimitsApi, RATE_LIMIT_ENDPOINTS_GROUPS.NAMED_CREATE),
|
||||
checkContentType({ action: 'POST', label: 'POST TEMPLATE' }),
|
||||
createTemplate({ templateMaps: this.templateMaps })
|
||||
@@ -32,7 +32,7 @@ AdminTemplateController.prototype.register = function (templateRouter) {
|
||||
templateRouter.put(
|
||||
`/:template_id`,
|
||||
credentials(),
|
||||
authorizedByAPIKey({ authApi: this.authApi, action: 'update', label: 'PUT TEMPLATE' }),
|
||||
authorizedByAPIKey({ authBackend: this.authBackend, action: 'update', label: 'PUT TEMPLATE' }),
|
||||
rateLimit(this.userLimitsApi, RATE_LIMIT_ENDPOINTS_GROUPS.NAMED_UPDATE),
|
||||
checkContentType({ action: 'PUT', label: 'PUT TEMPLATE' }),
|
||||
updateTemplate({ templateMaps: this.templateMaps })
|
||||
@@ -41,7 +41,7 @@ AdminTemplateController.prototype.register = function (templateRouter) {
|
||||
templateRouter.get(
|
||||
`/:template_id`,
|
||||
credentials(),
|
||||
authorizedByAPIKey({ authApi: this.authApi, action: 'get', label: 'GET TEMPLATE' }),
|
||||
authorizedByAPIKey({ authBackend: this.authBackend, action: 'get', label: 'GET TEMPLATE' }),
|
||||
rateLimit(this.userLimitsApi, RATE_LIMIT_ENDPOINTS_GROUPS.NAMED_GET),
|
||||
retrieveTemplate({ templateMaps: this.templateMaps })
|
||||
);
|
||||
@@ -49,7 +49,7 @@ AdminTemplateController.prototype.register = function (templateRouter) {
|
||||
templateRouter.delete(
|
||||
`/:template_id`,
|
||||
credentials(),
|
||||
authorizedByAPIKey({ authApi: this.authApi, action: 'delete', label: 'DELETE TEMPLATE' }),
|
||||
authorizedByAPIKey({ authBackend: this.authBackend, action: 'delete', label: 'DELETE TEMPLATE' }),
|
||||
rateLimit(this.userLimitsApi, RATE_LIMIT_ENDPOINTS_GROUPS.NAMED_DELETE),
|
||||
destroyTemplate({ templateMaps: this.templateMaps })
|
||||
);
|
||||
@@ -57,7 +57,7 @@ AdminTemplateController.prototype.register = function (templateRouter) {
|
||||
templateRouter.get(
|
||||
`/`,
|
||||
credentials(),
|
||||
authorizedByAPIKey({ authApi: this.authApi, action: 'list', label: 'GET TEMPLATE LIST' }),
|
||||
authorizedByAPIKey({ authBackend: this.authBackend, action: 'list', label: 'GET TEMPLATE LIST' }),
|
||||
rateLimit(this.userLimitsApi, RATE_LIMIT_ENDPOINTS_GROUPS.NAMED_LIST),
|
||||
listTemplates({ templateMaps: this.templateMaps })
|
||||
);
|
||||
@@ -75,11 +75,11 @@ function checkContentType ({ action, label }) {
|
||||
};
|
||||
}
|
||||
|
||||
function authorizedByAPIKey ({ authApi, action, label }) {
|
||||
function authorizedByAPIKey ({ authBackend, action, label }) {
|
||||
return function authorizedByAPIKeyMiddleware (req, res, next) {
|
||||
const { user } = res.locals;
|
||||
|
||||
authApi.authorizedByAPIKey(user, res, (err, authenticated) => {
|
||||
authBackend.authorizedByAPIKey(user, res, (err, authenticated) => {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user