bjarneo 0c86efd56c
refactor: use fastify vite for the dev server (#284)
* refactor: use fastify vite for the server

by doing this we do not need to have local hacks for the routes. No local proxy needed. Everything just works.

* fix: update the dockerfile build path

* fix: update package.json

* fix: fonts path
2024-03-11 13:43:20 +01:00

70 lines
2.3 KiB
JavaScript

import getEmailDomain from '../../../shared/helpers/get-email-domain.js';
import { updateAdminSettings } from '../../bootstrap.js';
import prisma from '../../services/prisma.js';
async function settings(fastify) {
fastify.get(
'/',
{
preValidation: [fastify.authenticate, fastify.admin],
},
async () => {
const settings = await prisma.settings.findFirst({
where: {
id: 'admin_settings',
},
});
return settings;
}
);
fastify.put(
'/',
{
preValidation: [fastify.authenticate, fastify.admin],
schema: {
body: {
type: 'object',
properties: {
disable_users: { type: 'boolean', default: false },
disable_user_account_creation: { type: 'boolean', default: false },
read_only: { type: 'boolean', default: false },
disable_file_upload: { type: 'boolean', default: false },
restrict_organization_email: { type: 'string', default: '' },
},
},
},
},
async (request) => {
const {
disable_users,
disable_user_account_creation,
read_only,
disable_file_upload,
restrict_organization_email,
} = request.body;
const settings = await prisma.settings.upsert({
where: {
id: 'admin_settings',
},
update: {
disable_users, // Disable user registration
disable_user_account_creation, // Disable user account creation
read_only, // Allow visiting users to read secrets, and not create any except if you are an admin
disable_file_upload, // Disable file uploads
restrict_organization_email: getEmailDomain(restrict_organization_email), // Whitelist organization email for user creation
},
create: { id: 'admin_settings' },
});
updateAdminSettings(settings);
return settings;
}
);
}
export default settings;