system-settings.js (1335B)
1 import { app } from '../../app.js'; 2 import { authenticateAdminSession } from '../../lib/admin-auth.js'; 3 import { HttpError } from '../../lib/http/http-error.js'; 4 import { isSystemAdmin } from '../../lib/policy.js'; 5 import { 6 getAdminSystemSettings, 7 updateAdminSystemSettings, 8 } from '../../lib/system-settings.js'; 9 10 function requireSystemAdmin(user) { 11 if (!isSystemAdmin(user)) { 12 throw new HttpError(403, 'forbidden', 'System administrator access is required'); 13 } 14 } 15 16 export default [ 17 { 18 method: 'get', 19 path: '/api/v1/admin/system/settings', 20 name: 'admin.system-settings.get', 21 async handler(req) { 22 const auth = await authenticateAdminSession(req); 23 requireSystemAdmin(auth.user); 24 const settings = await getAdminSystemSettings(auth.systemDb); 25 26 return new app.HttpOk({ settings }, { 'cache-control': 'no-store' }); 27 }, 28 }, 29 { 30 method: 'patch', 31 path: '/api/v1/admin/system/settings', 32 name: 'admin.system-settings.update', 33 async handler(req) { 34 const auth = await authenticateAdminSession(req); 35 requireSystemAdmin(auth.user); 36 const settings = await updateAdminSystemSettings({ 37 systemDb: auth.systemDb, 38 body: req.body || {}, 39 }); 40 41 return new app.HttpOk({ ok: true, settings }, { 'cache-control': 'no-store' }); 42 }, 43 }, 44 ];