Feat v0.2.3 sdk tasks (#7)
Co-authored-by: Jeffrey Smith <jasafpro@gmail.com> Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
This commit was merged in pull request #7.
This commit is contained in:
@@ -2,7 +2,10 @@ package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"log"
|
||||
|
||||
"switchboard-core/database"
|
||||
"switchboard-core/store"
|
||||
)
|
||||
|
||||
@@ -65,8 +68,42 @@ func EnsureEveryoneGroup(ctx context.Context, stores store.Stores, userID string
|
||||
_ = stores.Groups.AddMember(ctx, EveryoneGroupID, userID, userID)
|
||||
}
|
||||
|
||||
// EnsureAdminsGroup creates the Admins system group if it does not exist.
|
||||
// Handles the case where migration 002 was applied before the Admins INSERT
|
||||
// was added (no new migrations pre-MVP — edits in place).
|
||||
// Uses raw SQL because the store's Create() overwrites the ID.
|
||||
func EnsureAdminsGroup(ctx context.Context, stores store.Stores) {
|
||||
if _, err := stores.Groups.GetByID(ctx, AdminsGroupID); err == nil {
|
||||
return // already exists
|
||||
}
|
||||
permsJSON, _ := json.Marshal(AllPermissions)
|
||||
db := database.DB
|
||||
if db == nil {
|
||||
return
|
||||
}
|
||||
_, err := db.ExecContext(ctx, `
|
||||
INSERT OR IGNORE INTO groups (id, name, description, scope, created_by, source, permissions)
|
||||
VALUES (?, 'Admins', 'Full platform access — replaces legacy admin role.',
|
||||
'global', NULL, 'system', ?)`,
|
||||
AdminsGroupID, string(permsJSON))
|
||||
if err != nil {
|
||||
// Postgres variant
|
||||
_, err = db.ExecContext(ctx, `
|
||||
INSERT INTO groups (id, name, description, scope, created_by, source, permissions)
|
||||
VALUES ($1, 'Admins', 'Full platform access — replaces legacy admin role.',
|
||||
'global', NULL, 'system', $2::jsonb)
|
||||
ON CONFLICT (id) DO NOTHING`,
|
||||
AdminsGroupID, string(permsJSON))
|
||||
if err != nil {
|
||||
log.Printf("⚠ EnsureAdminsGroup: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AddToAdminsGroup adds a user to the Admins group (idempotent).
|
||||
// Ensures the Admins group exists before attempting membership.
|
||||
func AddToAdminsGroup(ctx context.Context, stores store.Stores, userID string) {
|
||||
EnsureAdminsGroup(ctx, stores)
|
||||
_ = stores.Groups.AddMember(ctx, AdminsGroupID, userID, userID)
|
||||
}
|
||||
|
||||
|
||||
@@ -726,6 +726,7 @@ func (h *PackageHandler) ListEnabledSurfaces(c *gin.Context) {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Route string `json:"route"`
|
||||
Icon string `json:"icon,omitempty"`
|
||||
}
|
||||
|
||||
var enabled []navSurface
|
||||
@@ -738,10 +739,12 @@ func (h *PackageHandler) ListEnabledSurfaces(c *gin.Context) {
|
||||
continue
|
||||
}
|
||||
route, _ := p.Manifest["route"].(string)
|
||||
icon, _ := p.Manifest["icon"].(string)
|
||||
enabled = append(enabled, navSurface{
|
||||
ID: p.ID,
|
||||
Title: p.Title,
|
||||
Route: route,
|
||||
Icon: icon,
|
||||
})
|
||||
}
|
||||
if enabled == nil {
|
||||
|
||||
Reference in New Issue
Block a user