Skip to content

Commit baff119

Browse files
authored
Feat: System settings (#66)
* Format checked, contributing.md update * Middleware setup * IAP API, create user/roles in frontend * RBAC using CASL library * Switch to CASL, secure search, resource-level access control * Remove inherent behavior, index userEmail, adding docs for IAM policies * Format * System settings setup --------- Co-authored-by: Wayne <5291640+ringoinca@users.noreply.github.com>
1 parent f1da17e commit baff119

20 files changed

Lines changed: 1692 additions & 134 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { Request, Response } from 'express';
2+
import { SettingsService } from '../../services/SettingsService';
3+
4+
const settingsService = new SettingsService();
5+
6+
export const getSettings = async (req: Request, res: Response) => {
7+
try {
8+
const settings = await settingsService.getSettings();
9+
res.status(200).json(settings);
10+
} catch (error) {
11+
// A more specific error could be logged here
12+
res.status(500).json({ message: 'Failed to retrieve settings' });
13+
}
14+
};
15+
16+
export const updateSettings = async (req: Request, res: Response) => {
17+
try {
18+
// Basic validation can be performed here if necessary
19+
const updatedSettings = await settingsService.updateSettings(req.body);
20+
res.status(200).json(updatedSettings);
21+
} catch (error) {
22+
// A more specific error could be logged here
23+
res.status(500).json({ message: 'Failed to update settings' });
24+
}
25+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Router } from 'express';
2+
import * as settingsController from '../controllers/settings.controller';
3+
import { requireAuth } from '../middleware/requireAuth';
4+
import { requirePermission } from '../middleware/requirePermission';
5+
import { AuthService } from '../../services/AuthService';
6+
7+
export const createSettingsRouter = (authService: AuthService): Router => {
8+
const router = Router();
9+
10+
// Public route to get non-sensitive settings. settings read should not be scoped with a permission because all end users need the settings data in the frontend. However, for sensitive settings data, we need to add a new permission subject to limit access. So this route should only expose non-sensitive settings data.
11+
router.get('/', settingsController.getSettings);
12+
13+
// Protected route to update settings
14+
router.put(
15+
'/',
16+
requireAuth(authService),
17+
requirePermission('manage', 'settings', 'You do not have permission to update system settings.'),
18+
settingsController.updateSettings
19+
);
20+
21+
return router;
22+
};

packages/backend/src/api/routes/test.routes.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CREATE TABLE "system_settings" (
2+
"id" serial PRIMARY KEY NOT NULL,
3+
"config" jsonb NOT NULL
4+
);

0 commit comments

Comments
 (0)