Documentation
¶
Overview ¶
Package admin exposes the /admin/v1 organization-scoped admin API: user / session / role / audit / oauth-account management.
Extracted from root handlers_admin.go in PR F of the 2026-06 architecture reorg. Collapsed from internal/admin/handlers into internal/admin in PR H (2026-06-22): the handlers/ subdir was the only child so the extra nesting added no value. The agent + delegation admin routes live in a sibling package (internal/agent/handlers) and are mounted as a subtree of the same /admin/v1/organizations/{orgID} route via the mountAgents callback supplied at Mount time.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuditService ¶
type AuditService interface {
QueryAudit(ctx context.Context, q models.AuditQuery) ([]models.AuditEvent, string, error)
EmitAudit(ctx context.Context, action string, target models.TargetRef, meta map[string]any)
HashEmailForAudit(email string) string
}
AuditService is the audit query + emit surface.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler owns the 12 /admin/v1 endpoints (plus the requireOrgMatch middleware that gates the entire /organizations/{orgID} subtree).
func New ¶
func New( storage Storage, rbac RBACService, audit AuditService, pathPrefix string, userFromCtx UserFromCtx, sessFromCtx SessionFromCtx, ) *Handler
New constructs a Handler. pathPrefix is the operator-supplied /admin path override (defaults to /admin/v1 when empty).
func (*Handler) Mount ¶
func (h *Handler) Mount(r chi.Router, requireAuth func(http.Handler) http.Handler, requirePermission PermissionGate, mountAgents MountAgents)
Mount wires the entire /admin/v1 tree under r. requireAuth wraps every route; requirePermission gates each endpoint per the v1.0 spec section 9 table. mountAgents (optional, may be nil) attaches the agent + delegation subroutes under the same /organizations/{orgID} scope.
func (*Handler) WithLifecycle ¶ added in v2.10.0
WithLifecycle enables the account lifecycle endpoints. It returns h.
type Lifecycle ¶ added in v2.10.0
type Lifecycle interface {
SetMustChangePassword(ctx context.Context, userID models.ULID, required bool) error
DisableUser(ctx context.Context, userID models.ULID) error
EnableUser(ctx context.Context, userID models.ULID) error
DeleteUser(ctx context.Context, userID models.ULID) error
}
Lifecycle is the optional account lifecycle surface. When supplied through WithLifecycle, PATCH /users/{userID} accepts mustChangePassword and disabled, and DELETE /users/{userID}/account deletes the account. Disabling and deleting are global, so they require the super_admin role; forcing a password change only requires users:admin.
type MountAgents ¶
MountAgents wires the sibling internal/agent/handlers Mount onto an existing chi router scoped under /admin/v1/organizations/{orgID}. Supplied by root because the agent handler has its own constructor + service dependencies.
type PermissionGate ¶
PermissionGate returns a middleware that rejects requests whose session lacks the named permission.
type RBACService ¶
type RBACService interface {
GrantRole(ctx context.Context, actorID, userID, roleID models.ULID) error
RevokeRole(ctx context.Context, actorID, userID, roleID models.ULID) error
CreateRole(ctx context.Context, orgID models.ULID, name, description string, permissions []string) (models.Role, error)
UpdateRole(ctx context.Context, roleID models.ULID, name, description string, permissions []string) (models.Role, error)
DeleteRole(ctx context.Context, roleID models.ULID) error
}
RBACService is the role-mutation surface used by the user / role endpoints.
type SessionFromCtx ¶
SessionFromCtx pulls the authenticated session from the request context.
type Storage ¶
type Storage interface {
ListUsersByOrganization(ctx context.Context, orgID models.ULID, offset, limit int, f models.SCIMUserFilter) ([]models.User, int, error)
UserByID(ctx context.Context, id models.ULID) (*models.User, error)
UserByEmail(ctx context.Context, email string) (*models.User, error)
CreateUser(ctx context.Context, u models.User) (models.User, error)
UpsertOrganizationMember(ctx context.Context, m models.OrganizationMember) error
DeleteOrganizationMember(ctx context.Context, orgID, userID models.ULID) error
OrganizationMemberRole(ctx context.Context, orgID, userID models.ULID) (string, error)
RolesForUser(ctx context.Context, userID models.ULID, orgID *models.ULID) ([]models.Role, error)
RoleByID(ctx context.Context, id models.ULID) (*models.Role, error)
RolesByOrganization(ctx context.Context, orgID *models.ULID) ([]models.Role, error)
RevokeSession(ctx context.Context, id models.ULID) error
}
Storage is the persistence surface this handler needs. Declared here (not imported from root) so the extracted package does not import root.