admin

package
v0.31.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	ActionUserDisabled          = "user.disabled"
	ActionUserEnabled           = "user.enabled"
	ActionUserAdminGranted      = "user.admin_granted"
	ActionUserAdminRevoked      = "user.admin_revoked"
	ActionUserSessionRevoked    = "user.session_revoked"
	ActionUserSessionsRevoked   = "user.sessions_revoked"
	ActionAllowlistEmailAdded   = "allowlist.email_added"
	ActionAllowlistEmailRemoved = "allowlist.email_removed"
)
View Source
const (
	ReasonSelfDisable        = "You cannot disable your own account."
	ReasonSelfRevokeAdmin    = "You cannot remove your own admin role."
	ReasonSelfRevokeSessions = "You cannot revoke all sessions for your own account from here."
	ReasonLastAdmin          = "You cannot remove the last admin."
)

Variables

View Source
var (
	ErrSelfDisable              = errors.New("admin cannot disable themselves")
	ErrSelfRevokeAdmin          = errors.New("admin cannot remove their own admin role")
	ErrSelfRevokeSessions       = errors.New("admin cannot revoke all sessions for themselves")
	ErrSelfRemoveAllowedEmail   = errors.New("admin cannot remove their own allowlisted email")
	ErrLastAdmin                = errors.New("operation would leave no active admins")
	ErrAllowlistDisabled        = errors.New("allowlist feature disabled")
	ErrAllowedEmailAlreadyAdded = errors.New("allowed email already exists")
	ErrInvalidEmail             = errors.New("invalid email")
)

Functions

This section is empty.

Types

type ActionAvailability

type ActionAvailability struct {
	Allowed bool
	Reason  string
}

type Actor

type Actor struct {
	UserID uuid.UUID
	Email  string
	Roles  roles.Roles
}

type AllowedEmailPage

type AllowedEmailPage struct {
	Emails  []domain.AllowedEmail
	Query   string
	Page    int
	Size    int
	Total   int
	Message string
}

func (AllowedEmailPage) HasNext

func (p AllowedEmailPage) HasNext() bool

func (AllowedEmailPage) HasPrevious

func (p AllowedEmailPage) HasPrevious() bool

type AuditEventPage

type AuditEventPage struct {
	Events  []domain.AdminAuditEvent
	Page    int
	Size    int
	HasNext bool
}

type AuthProviderSummary

type AuthProviderSummary struct {
	ID          uuid.UUID
	Provider    string
	CreatedAt   time.Time
	HasPassword bool
	HasOAuthID  bool
}

type Config

type Config struct {
	Store                  *store.Store
	Tx                     *tx.Manager
	Now                    func() time.Time
	AllowlistEnabled       bool
	AuditRetention         time.Duration
	Policy                 config.AdminPolicyReader
	AllowlistPolicy        config.AllowlistPolicyReader
	WebhookPublisher       webhook.Publisher
	AccessTokenRevocations *token.AccessTokenRevocations
	SecurityEvents         *securityevent.Service
}

type DashboardStats

type DashboardStats struct {
	TotalUsers         int
	SignupsLast24Hours int
	DisabledUsers      int
	ActiveSessions     int
}

type Page

type Page struct {
	Page int
	Size int
}

type PasskeySummary

type PasskeySummary struct {
	ID             uuid.UUID
	Name           string
	CreatedAt      time.Time
	LastUsedAt     *time.Time
	CloneWarning   bool
	RestrictedAt   *time.Time
	BackupEligible bool
	BackupState    bool
	DeviceLabel    string
	Transport      []string
}

type RecentFailures

type RecentFailures struct {
	EmailJobs  []domain.EmailJob
	Challenges []domain.Challenge
	Page       int
	Size       int
}

type RequestMeta

type RequestMeta struct {
	IP        string
	UserAgent string
}

type SecurityEventPage added in v0.22.0

type SecurityEventPage struct {
	Events  []domain.SecurityEvent
	Page    int
	Size    int
	HasNext bool
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func New

func New(cfg Config) *Service

func (*Service) AddAllowedEmail

func (s *Service) AddAllowedEmail(ctx context.Context, actor Actor, email string, meta RequestMeta) error

func (*Service) CanRevokeAllSessions

func (s *Service) CanRevokeAllSessions(actorID uuid.UUID, targetID uuid.UUID) ActionAvailability

func (*Service) CleanupExpiredAuditEventsBatch added in v0.22.0

func (s *Service) CleanupExpiredAuditEventsBatch(ctx context.Context, now time.Time, batchSize int) (int64, bool, error)

func (*Service) DashboardStats

func (s *Service) DashboardStats(ctx context.Context) (DashboardStats, error)

func (*Service) DisableUser

func (s *Service) DisableUser(ctx context.Context, actor Actor, userID uuid.UUID, meta RequestMeta) error

func (*Service) EnableUser

func (s *Service) EnableUser(ctx context.Context, actor Actor, userID uuid.UUID, meta RequestMeta) error

func (*Service) GetUserDetail

func (s *Service) GetUserDetail(ctx context.Context, actor Actor, userID uuid.UUID, pages UserDetailPages) (UserDetail, error)

func (*Service) GrantAdmin

func (s *Service) GrantAdmin(ctx context.Context, actor Actor, userID uuid.UUID, meta RequestMeta) error

func (*Service) ListAllowedEmails

func (s *Service) ListAllowedEmails(ctx context.Context, query string, page Page) (AllowedEmailPage, error)

func (*Service) ListAuditEvents

func (s *Service) ListAuditEvents(ctx context.Context, page Page) (AuditEventPage, error)

func (*Service) ListSecurityEvents added in v0.22.0

func (s *Service) ListSecurityEvents(ctx context.Context, page Page) (SecurityEventPage, error)

func (*Service) RecentFailures

func (s *Service) RecentFailures(ctx context.Context, page Page) (RecentFailures, error)

func (*Service) RemoveAllowedEmail

func (s *Service) RemoveAllowedEmail(ctx context.Context, actor Actor, allowedEmailID uuid.UUID, meta RequestMeta) error

func (*Service) RevokeAdmin

func (s *Service) RevokeAdmin(ctx context.Context, actor Actor, userID uuid.UUID, meta RequestMeta) error

func (*Service) RevokeAllUserSessions

func (s *Service) RevokeAllUserSessions(ctx context.Context, actor Actor, userID uuid.UUID, meta RequestMeta) error

func (*Service) RevokeUserSession

func (s *Service) RevokeUserSession(ctx context.Context, actor Actor, userID, sessionID uuid.UUID, meta RequestMeta) error

func (*Service) SearchUser

func (s *Service) SearchUser(ctx context.Context, query string) (UserSummary, error)

type SessionSummary

type SessionSummary struct {
	ID               uuid.UUID
	CreatedAt        time.Time
	ExpiresAt        time.Time
	RevokedAt        *time.Time
	UserAgent        string
	UserAgentSummary string
	Status           string
}

type UserDetail

type UserDetail struct {
	User          UserSummary
	AuthProviders []AuthProviderSummary
	Passkeys      []PasskeySummary
	Sessions      []SessionSummary
	SessionPage   int
	SessionSize   int
	SessionsNext  bool
	PasskeyPage   int
	PasskeySize   int
	PasskeysNext  bool
	Actions       UserDetailActions
}

func (UserDetail) PasskeysPrevious added in v0.22.0

func (d UserDetail) PasskeysPrevious() bool

func (UserDetail) SessionsPrevious added in v0.22.0

func (d UserDetail) SessionsPrevious() bool

type UserDetailActions

type UserDetailActions struct {
	Disable           ActionAvailability
	Enable            ActionAvailability
	GrantAdmin        ActionAvailability
	RevokeAdmin       ActionAvailability
	RevokeAllSessions ActionAvailability
}

type UserDetailPages added in v0.22.0

type UserDetailPages struct {
	Sessions Page
	Passkeys Page
}

type UserSummary

type UserSummary struct {
	ID                 uuid.UUID
	CreatedAt          time.Time
	UpdatedAt          time.Time
	DisabledAt         *time.Time
	Username           string
	Email              string
	Roles              []string
	AuthProviderCount  int
	ActiveSessionCount int
}

func (UserSummary) Disabled

func (u UserSummary) Disabled() bool

func (UserSummary) HasRole

func (u UserSummary) HasRole(roleName string) bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL