Changeset 7881080 in Klonkt for src/routes/admin.js


Ignore:
Timestamp:
06/18/2026 03:28:34 AM (3 months ago)
Author:
roboburr <roboburr@…>
Branches:
main
Children:
8398935
Parents:
98ecf51
Message:

Hub #3: explicit is_primary flag + shared getPrimarySite() (DRY)

The "oldest site = primary site" assumption was duplicated independently in
resolveSite, hub.js, account.js and admin.js (fragile: if the oldest happened
to be an artist site, the hub home would be wrong). Now:

  • sites.is_primary column + backfill (marks the oldest if none is primary yet; ensurePrimarySite sets it on fresh installs) → existing behaviour exactly preserved.
  • one getPrimarySite() helper (is_primary, fallback oldest) replaces the 4 copies.
  • god can CHOOSE the primary/main site: ★ button + "primary" badge on /admin/sites (exactly one primary via a transaction).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/routes/admin.js

    r98ecf51 r7881080  
    1010import { requireAuth } from '../middleware/auth.js';
    1111import { getTenancy } from '../services/SettingsService.js';
     12import { getPrimarySite } from '../middleware/site.js';
    1213
    1314const router = express.Router();
     
    5960  const tenancy = getTenancy();
    6061
    61   // De primaire/owner-site — in solo dé site, in hub de hoofdsite. Geeft de
     62  // De primaire/hoofd-site — in solo dé site, in hub de hoofdsite. Geeft de
    6263  // "Uiterlijk"-tegel z'n edit-link + de posts/concepten-lijst.
    63   const primarySite = db.prepare(
    64     'SELECT id, slug, title FROM sites ORDER BY created_at ASC LIMIT 1'
    65   ).get() || null;
     64  const primarySite = getPrimarySite();
    6665
    6766  const stats = {
Note: See TracChangeset for help on using the changeset viewer.