Changeset 98ecf51 in Klonkt for src/services


Ignore:
Timestamp:
06/18/2026 03:19:09 AM (3 months ago)
Author:
roboburr <roboburr@…>
Branches:
main
Children:
7881080
Parents:
6a2abb1
Message:

Hub #1+#2: site admin permissions work + assign owner to another user

#1 — canAdminSite was reading user.siteRoles which was NEVER populated (dead
code) → only god and the literal owner passed admin checks. Now canAdminSite
queries site_members directly (an assigned co-admin). requireSiteManager/BySlug
use canAdminSite so collaborators can access site management too.

#2 — owner_id was hard-coded to the creating god → you couldn't assign a site to
another user (the core of hub mode was missing). Now: god-only "Owner" select in
the site form; create/save set owner_id + a site_members-admin row for that owner
(upsert). Non-god doesn't see the field and cannot change the owner.

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/services/PermissionsService.js

    r6a2abb1 r98ecf51  
    33 * Used in templates to show/hide edit buttons, delete buttons, etc.
    44 */
     5
     6import db from '../config/database.js';
    57
    68class PermissionsService {
     
    5456   */
    5557  static canAdminSite(user, site) {
    56     if (!user) return false;
     58    if (!user || !site) return false;
    5759    if (user.role === 'god') return true;
    5860    if (user.id === site.owner_id) return true;
    59     // Check site_members table
    60     return user.siteRoles && user.siteRoles[site.id] === 'admin';
     61    // Toegewezen mede-beheerder (collaborator) via site_members. Dit werd
     62    // voorheen via een nooit-gevulde user.siteRoles gelezen → dode code; nu
     63    // direct op de tabel (paar checks per pagina, indexed = goedkoop).
     64    return !!db.prepare(
     65      "SELECT 1 FROM site_members WHERE site_id = ? AND user_id = ? AND role = 'admin' LIMIT 1"
     66    ).get(site.id, user.id);
    6167  }
    6268
Note: See TracChangeset for help on using the changeset viewer.