Merge pull request #1706 from automatisch/rest-config-api
feat: Implement automatisch config API endpoint
This commit is contained in:
@@ -0,0 +1,24 @@
|
|||||||
|
import appConfig from '../../../../config/app.js';
|
||||||
|
import Config from '../../../../models/config.js';
|
||||||
|
import { renderObject } from '../../../../helpers/renderer.js';
|
||||||
|
|
||||||
|
export default async (request, response) => {
|
||||||
|
const defaultConfig = {
|
||||||
|
disableNotificationsPage: appConfig.disableNotificationsPage,
|
||||||
|
disableFavicon: appConfig.disableFavicon,
|
||||||
|
additionalDrawerLink: appConfig.additionalDrawerLink,
|
||||||
|
additionalDrawerLinkText: appConfig.additionalDrawerLinkText,
|
||||||
|
};
|
||||||
|
|
||||||
|
let config = await Config.query().orderBy('key', 'asc');
|
||||||
|
|
||||||
|
config = config.reduce((computedConfig, configEntry) => {
|
||||||
|
const { key, value } = configEntry;
|
||||||
|
|
||||||
|
computedConfig[key] = value?.data;
|
||||||
|
|
||||||
|
return computedConfig;
|
||||||
|
}, defaultConfig);
|
||||||
|
|
||||||
|
renderObject(response, config);
|
||||||
|
};
|
@@ -0,0 +1,51 @@
|
|||||||
|
import { vi, expect, describe, it } from 'vitest';
|
||||||
|
import request from 'supertest';
|
||||||
|
import { createConfig } from '../../../../../test/factories/config.js';
|
||||||
|
import app from '../../../../app.js';
|
||||||
|
import configMock from '../../../../../test/mocks/rest/api/v1/automatisch/config.js';
|
||||||
|
import * as license from '../../../../helpers/license.ee.js';
|
||||||
|
|
||||||
|
describe('GET /api/v1/automatisch/config', () => {
|
||||||
|
it('should return Automatisch config', async () => {
|
||||||
|
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
||||||
|
|
||||||
|
const logoConfig = await createConfig({
|
||||||
|
key: 'logo.svgData',
|
||||||
|
value: { data: '<svg>Sample</svg>' },
|
||||||
|
});
|
||||||
|
|
||||||
|
const primaryDarkConfig = await createConfig({
|
||||||
|
key: 'palette.primary.dark',
|
||||||
|
value: { data: '#001F52' },
|
||||||
|
});
|
||||||
|
|
||||||
|
const primaryLightConfig = await createConfig({
|
||||||
|
key: 'palette.primary.light',
|
||||||
|
value: { data: '#4286FF' },
|
||||||
|
});
|
||||||
|
|
||||||
|
const primaryMainConfig = await createConfig({
|
||||||
|
key: 'palette.primary.main',
|
||||||
|
value: { data: '#0059F7' },
|
||||||
|
});
|
||||||
|
|
||||||
|
const titleConfig = await createConfig({
|
||||||
|
key: 'title',
|
||||||
|
value: { data: 'Sample Title' },
|
||||||
|
});
|
||||||
|
|
||||||
|
const response = await request(app)
|
||||||
|
.get('/api/v1/automatisch/config')
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
const expectedPayload = configMock(
|
||||||
|
logoConfig,
|
||||||
|
primaryDarkConfig,
|
||||||
|
primaryLightConfig,
|
||||||
|
primaryMainConfig,
|
||||||
|
titleConfig
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(response.body).toEqual(expectedPayload);
|
||||||
|
});
|
||||||
|
});
|
@@ -1,9 +1,11 @@
|
|||||||
import { Router } from 'express';
|
import { Router } from 'express';
|
||||||
import asyncHandler from 'express-async-handler';
|
import asyncHandler from 'express-async-handler';
|
||||||
|
import { checkIsEnterprise } from '../../../helpers/check-is-enterprise.js';
|
||||||
import versionAction from '../../../controllers/api/v1/automatisch/version.js';
|
import versionAction from '../../../controllers/api/v1/automatisch/version.js';
|
||||||
import notificationsAction from '../../../controllers/api/v1/automatisch/notifications.js';
|
import notificationsAction from '../../../controllers/api/v1/automatisch/notifications.js';
|
||||||
import infoAction from '../../../controllers/api/v1/automatisch/info.js';
|
import infoAction from '../../../controllers/api/v1/automatisch/info.js';
|
||||||
import licenseAction from '../../../controllers/api/v1/automatisch/license.js';
|
import licenseAction from '../../../controllers/api/v1/automatisch/license.js';
|
||||||
|
import configAction from '../../../controllers/api/v1/automatisch/config.ee.js';
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
@@ -11,5 +13,6 @@ router.get('/version', asyncHandler(versionAction));
|
|||||||
router.get('/notifications', asyncHandler(notificationsAction));
|
router.get('/notifications', asyncHandler(notificationsAction));
|
||||||
router.get('/info', asyncHandler(infoAction));
|
router.get('/info', asyncHandler(infoAction));
|
||||||
router.get('/license', asyncHandler(licenseAction));
|
router.get('/license', asyncHandler(licenseAction));
|
||||||
|
router.get('/config', checkIsEnterprise, asyncHandler(configAction));
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@@ -0,0 +1,28 @@
|
|||||||
|
const infoMock = (
|
||||||
|
logoConfig,
|
||||||
|
primaryDarkConfig,
|
||||||
|
primaryLightConfig,
|
||||||
|
primaryMainConfig,
|
||||||
|
titleConfig
|
||||||
|
) => {
|
||||||
|
return {
|
||||||
|
data: {
|
||||||
|
disableFavicon: false,
|
||||||
|
disableNotificationsPage: false,
|
||||||
|
'logo.svgData': logoConfig.value.data,
|
||||||
|
'palette.primary.dark': primaryDarkConfig.value.data,
|
||||||
|
'palette.primary.light': primaryLightConfig.value.data,
|
||||||
|
'palette.primary.main': primaryMainConfig.value.data,
|
||||||
|
title: titleConfig.value.data,
|
||||||
|
},
|
||||||
|
meta: {
|
||||||
|
count: 1,
|
||||||
|
currentPage: null,
|
||||||
|
isArray: false,
|
||||||
|
totalPages: null,
|
||||||
|
type: 'Object',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default infoMock;
|
Reference in New Issue
Block a user