feat(web): RBAC, tenant scope, and WS room hooks

Add configurable role⊥permission (five tables, gate permissions, register,
/_rbac desk), multi-tenant path/header resolution with JSON tenant_scope,
and route_ws on_message/presence/dynamic room_key — with author surfaces,
demos, and smokes.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-09-17 20:54:02 +08:00
1 parent 27991a7822
commit 5cf84fe9b7
27 files changed
+2372 -80

No files matched your search

+15 -2
View File
@@ -86,7 +86,7 @@ func cellStr(v any) string {
}
// Login validates credentials and creates a session.
// Success: {"ok":true,"session_id":…,"username":…,"role":…}
// Success: {"ok":true,"session_id":…,"username":…,"role":…,"permissions":…}
// Failure: {"ok":false}
func Login(username, pass string, users any, sessionTTL uint64) map[string]any {
u, role, ok := CheckCredentials(users, username, pass)
@@ -104,6 +104,14 @@ func Login(username, pass string, users any, sessionTTL uint64) map[string]any {
}
}
// AttachPermissions writes permission codes onto an existing login session.
func AttachPermissions(sessionID string, codes []string) {
if sessionID == "" {
return
}
session.SetPermissions(sessionID, codes)
}
// Check returns session auth state (web_auth_check).
func Check(sessionID string) map[string]any {
v, ok := session.GetValue(sessionID, "username")
@@ -120,7 +128,12 @@ func Check(sessionID string) map[string]any {
role = s
}
}
return map[string]any{"ok": true, "username": u, "role": role}
perms := session.PermissionsFromSession(sessionID)
out := map[string]any{"ok": true, "username": u, "role": role}
if len(perms) > 0 {
out["permissions"] = perms
}
return out
}
// Logout destroys the session (web_auth_logout).