diff --git a/lib/api/routes/backupRouter.js b/lib/api/routes/backupRouter.js index a4e5d60..859c449 100644 --- a/lib/api/routes/backupRouter.js +++ b/lib/api/routes/backupRouter.js @@ -9,6 +9,10 @@ import { precheckRestore, restoreFromZip, } from '../../services/storage/backupRestoreService.js'; +import { getSettings } from '../../services/storage/settingsStorage.js'; +import { isAdmin } from '../security.js'; + +const DEMO_MODE_ERROR = 'Backup and restore are not available in demo mode.'; /** * @param {import('fastify').FastifyInstance} fastify @@ -21,7 +25,11 @@ export default async function backupPlugin(fastify) { (req, body, done) => done(null, body), ); - fastify.get('/', async (_request, reply) => { + fastify.get('/', async (request, reply) => { + const settings = await getSettings(); + if (settings.demoMode && !isAdmin(request)) { + return reply.code(403).send({ error: DEMO_MODE_ERROR }); + } const zipBuffer = await createBackupZip(); const fileName = await buildBackupFileName(); reply.header('Content-Type', 'application/zip'); @@ -30,6 +38,10 @@ export default async function backupPlugin(fastify) { }); fastify.post('/restore', async (request, reply) => { + const settings = await getSettings(); + if (settings.demoMode && !isAdmin(request)) { + return reply.code(403).send({ error: DEMO_MODE_ERROR }); + } const { dryRun = 'false', force = 'false' } = request.query || {}; const doDryRun = String(dryRun) === 'true'; const doForce = String(force) === 'true'; diff --git a/package.json b/package.json index 7fce8b5..01314af 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fredy", - "version": "22.0.3", + "version": "22.0.4", "description": "[F]ind [R]eal [E]states [d]amn eas[y].", "scripts": { "prepare": "husky", diff --git a/ui/src/views/generalSettings/GeneralSettings.jsx b/ui/src/views/generalSettings/GeneralSettings.jsx index 357cbda..65d35b7 100644 --- a/ui/src/views/generalSettings/GeneralSettings.jsx +++ b/ui/src/views/generalSettings/GeneralSettings.jsx @@ -54,6 +54,7 @@ const GeneralSettings = function GeneralSettings() { const [loading, setLoading] = React.useState(true); const settings = useSelector((state) => state.generalSettings.settings); + const currentUser = useSelector((state) => state.user.currentUser); const [interval, setInterval] = React.useState(''); const [port, setPort] = React.useState(''); @@ -467,12 +468,26 @@ const GeneralSettings = function GeneralSettings() { itemKey="backup" >
+ {demoMode && !currentUser?.isAdmin && ( + + )}
- -