Changeset 7881080 in Klonkt for src/routes/admin-sites.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-sites.js

    r98ecf51 r7881080  
    161161  const sites = db.prepare(`
    162162    SELECT s.id, s.slug, s.title, s.description, s.created_at,
    163            s.is_public, s.robots_index,
     163           s.is_public, s.robots_index, s.is_primary,
    164164           u.username AS owner_username,
    165165           (SELECT COUNT(*) FROM posts WHERE site_id = s.id) AS post_count
    166166    FROM sites s LEFT JOIN users u ON u.id = s.owner_id
    167     ORDER BY s.created_at DESC
     167    ORDER BY s.is_primary DESC, s.created_at DESC
    168168  `).all();
    169169
     
    354354});
    355355
     356// ==================== MAAK PRIMAIR ====================
     357// God kiest welke site de primaire/hoofd-site is (de label-/bedrijfssite in hub;
     358// in solo dé site). Precies één site is primair → eerst alles uit, dan deze aan.
     359router.post('/:slug/make-primary', requireGod, (req, res) => {
     360  const site = db.prepare('SELECT id FROM sites WHERE slug = ?').get(req.params.slug);
     361  if (!site) return res.redirect('/admin/sites?error=Niet+gevonden');
     362  db.transaction(() => {
     363    db.prepare('UPDATE sites SET is_primary = 0').run();
     364    db.prepare('UPDATE sites SET is_primary = 1 WHERE id = ?').run(site.id);
     365  })();
     366  res.redirect('/admin/sites?success=' + encodeURIComponent('Primaire site bijgewerkt'));
     367});
     368
    356369// ==================== DELETE ====================
    357370router.post('/:slug/delete', requireGod, (req, res) => {
Note: See TracChangeset for help on using the changeset viewer.