main
|
Last change
on this file since 6351545 was 6351545, checked in by roboburr <roboburr@…>, 3 months ago |
|
tenancy: runtime Solo/Hub mode + mode-aware /admin (Phase 1)
Admin can switch live between modes in Admin -> Settings:
- solo: exactly one site (the primary/owner site), no /sites routing, leaner /admin.
- hub: main site + /sites/:slug routing (company; /gebruikers + assignment flow = Phase 2).
Switching is non-destructive (hides only, deletes nothing).
- app_settings (key/value singleton) + SettingsService (cached getTenancy/setTenancy).
- resolveSite: solo pins to the primary site + disables /sites/:slug + host mapping.
- /admin/settings (god-only) toggle; /admin dashboard rewritten, mode-aware.
Tested on the demo: solo/hub dashboard tiles, /sites routing per mode, toggle back/forth.
Co-Authored-By: Claude <noreply@…>
|
-
Property mode
set to
100644
|
|
File size:
1.2 KB
|
| Rev | Line | |
|---|
| [6351545] | 1 | // Globale app-instellingen (key/value, gecached). Nu vooral de tenancy-modus.
|
|---|
| 2 | //
|
|---|
| 3 | // tenancy = 'solo' -> precies één site (de primaire/owner-site)
|
|---|
| 4 | // tenancy = 'hub' -> hoofdsite (bedrijf) + /gebruikers, admin wijst PrutFolio's toe
|
|---|
| 5 | //
|
|---|
| 6 | // De cache wordt bij setSetting meteen ververst, dus een toggle in Beheer werkt
|
|---|
| 7 | // live zonder herstart.
|
|---|
| 8 |
|
|---|
| 9 | import db from '../config/database.js';
|
|---|
| 10 |
|
|---|
| 11 | let _cache = null;
|
|---|
| 12 |
|
|---|
| 13 | function load() {
|
|---|
| 14 | if (!_cache) {
|
|---|
| 15 | _cache = {};
|
|---|
| 16 | for (const r of db.prepare('SELECT key, value FROM app_settings').all()) {
|
|---|
| 17 | _cache[r.key] = r.value;
|
|---|
| 18 | }
|
|---|
| 19 | }
|
|---|
| 20 | return _cache;
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | export function getSetting(key, fallback = null) {
|
|---|
| 24 | const v = load()[key];
|
|---|
| 25 | return v === undefined ? fallback : v;
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
| 28 | export function setSetting(key, value) {
|
|---|
| 29 | db.prepare(`
|
|---|
| 30 | INSERT INTO app_settings (key, value, updated_at) VALUES (?, ?, CURRENT_TIMESTAMP)
|
|---|
| 31 | ON CONFLICT(key) DO UPDATE SET value = excluded.value, updated_at = CURRENT_TIMESTAMP
|
|---|
| 32 | `).run(key, String(value));
|
|---|
| 33 | if (_cache) _cache[key] = String(value);
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | export function getTenancy() {
|
|---|
| 37 | return getSetting('tenancy', 'solo') === 'hub' ? 'hub' : 'solo';
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | export function setTenancy(mode) {
|
|---|
| 41 | setSetting('tenancy', mode === 'hub' ? 'hub' : 'solo');
|
|---|
| 42 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.