diff --git a/packages/backend/src/helpers/check-templates-enabled.js b/packages/backend/src/helpers/check-templates-enabled.js new file mode 100644 index 00000000..e6647541 --- /dev/null +++ b/packages/backend/src/helpers/check-templates-enabled.js @@ -0,0 +1,12 @@ +import Config from '../models/config.js'; +import NotAuthorizedError from '../errors/not-authorized.js'; + +export const checkTemplatesEnabled = async (request, response, next) => { + const config = await Config.get(); + + if (!config.enableTemplates) { + throw new NotAuthorizedError(); + } + + next(); +}; diff --git a/packages/backend/src/routes/api/v1/templates.ee.js b/packages/backend/src/routes/api/v1/templates.ee.js index 1dcae4a0..ccee826f 100644 --- a/packages/backend/src/routes/api/v1/templates.ee.js +++ b/packages/backend/src/routes/api/v1/templates.ee.js @@ -2,6 +2,7 @@ import { Router } from 'express'; import { authenticateUser } from '../../../helpers/authentication.js'; import { authorizeUser } from '../../../helpers/authorization.js'; import { checkIsEnterprise } from '../../../helpers/check-is-enterprise.js'; +import { checkTemplatesEnabled } from '../../../helpers/check-templates-enabled.js'; import getTemplatesAction from '../../../controllers/api/v1/templates/get-templates.ee.js'; @@ -12,6 +13,7 @@ router.get( authenticateUser, authorizeUser, checkIsEnterprise, + checkTemplatesEnabled, getTemplatesAction );