inspect

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 21 Imported by: 0

README

Arandu

Arandu Inspect

Renamed. This package is now hyz-is/arandu-impersonate, which follows laravel-impersonate's names and adds Protect() and CanBeImpersonated. This repository is archived; install the new one.

An operator goes into a user's account from the admin, without signing out of their own, acts there as the user — sees what the user sees, changes what the user can change — and comes back with one click. Every visit has a deadline, and everything is recorded in arandu-activitylog under the operator's name, with the account it was done in.

It is the "inspecionar" of the operator consoles the team runs, made safe: who may inspect is a Policy, an operator's own account and another operator's are refused, nobody inspects from inside an account, and nothing done inside goes unlogged.

How it works

  • POST /inspect/users/{id} — the operator goes into the account. The session is rotated to the account's owner with the operator kept as the one acting (hesape auth.ImpersonateActing), so the very same browser is now inside the account and every Grant writes as the owner would. The visit is recorded as an inspection with a deadline (one hour by default), and as the entry inspection.started in the inspect log.
  • Inside the account, every entry the application records names the operator as its causer and carries the impersonation property — by, on_behalf_of, mode: acting — which arandu-activitylog v0.3.0 adds by itself.
  • POST /inspect/leave (route name inspect.leave) — the operator comes back: the session is rotated to their own subject, the inspection is closed and inspection.left is recorded.
  • Guard() — past the deadline, the next request inside the account takes the operator back, closes the inspection and records inspection.expired.
  • GET /inspect/history — the inspections, newest first, for an operator.

The bar

Every page built with view.New (hesape v0.57.0) knows it is drawn for an operator inside somebody's account and where the way back is. The application's layout draws the bar from view.Inspection:

@if(inspecting(.))
	<div class="..." role="status">
		Você está na conta deste usuário como administrador.
		<form method="post" action="{{ leaveLink(.) }}">@csrf<button>Voltar ao administrador</button></form>
	</div>
@endif

with, in the layout's @go block:

func inspecting(d hview.Layout) bool {
	i, ok := d.(hview.Inspection)
	return ok && i.IsInspecting()
}

Install

go get github.com/hyz-is/arandu-activitylog@v0.3.0
go get github.com/hyz-is/arandu-inspect

It needs hesape v0.57.0 or newer.

Wire it

In bootstrap/app.go, after the session store and the activity log exist:

	inspectModule, err := inspect.New(inspect.Config{
		Targets:  inspect.TargetsFunc(users.InspectTarget), // the account as its owner signs in
		Activity: activityModule.Logger(),
		Landing:  "/painel",
		Return:   "/admin/usuarios",
	}, db, sessions)
	if err != nil {
		return App{}, err
	}

register inspectModule in k.Register(...), mount the guard after RequireAuth on the routes reachable from inside an account:

	panel := r.Group("/painel", middleware.RequireAuth(sessions), inspectModule.Guard())

and run aru migrate. Targets answers the subject the account's owner signs in as — identifier, tenant, roles, actions — because the package keeps no users.

Give people access

inspect.operator is the role that goes into accounts and reads the history; the application gives it through arandu-permission. An account that carries the role is never inspected.

Configuration

field required meaning
Targets yes loads the account an operator goes into.
Activity yes arandu-activitylog's logger.
Prefix no where the routes are mounted. Defaults to /inspect.
Landing no where the operator lands inside the account. Defaults to /.
Return no where they land back in their own. Defaults to /.
TTL no how long a visit lasts. Defaults to one hour; at most 12 hours.
UserType no the kind the activity log names accounts by. Defaults to user.

The data path

Inspection embeds model.Model and declares its table beside it. aru model:build generates InspectionQuery.go with Inspections(db), committed and never edited by hand; aru model:build --check fails when it is out of date. InspectService follows validate -> security.Authorize -> Grant -> Model terminal in every exported method, which the unit suite audits, and every route sits behind RequireAuth.

Example

go run -tags example ./example

It opens SQLite in a temporary directory, migrates arandu-activitylog and this package, and drives one browser: the operator goes into a user's account, changes a setting there, comes back, and the activity log is printed with every entry under the operator's name. It leaves nothing behind. The build tag is there so that installing this package never compiles it.

Tests

GOWORK=off go test ./... -race

The feature suite runs the whole visit in one browser against SQLite: going in, acting as the owner, coming back, the deadline, and every refusal, with the activity log's entries checked; the rules were checked by mutation.

Licence

MIT. See LICENSE.md.

Documentation

Overview

Package inspect is an Arandu module that takes an operator into somebody's account without signing them out of their own, lets them act there as the account's owner, brings them back, and holds the visit to a deadline. Everything is recorded in arandu-activitylog under the operator's name.

module.go   -> registration, routes, handlers, the guard and the migration
config.go   -> what the application passes in
model.go    -> the inspection
policy.go   -> who may go into which account
service.go  -> going in, coming back, the deadline, the history

The bar that tells the operator whose account they are in is drawn by the application's layout from hesape's view.Inspection, which every page built with view.New answers; its button posts to the route named inspect.leave, which this module registers.

Index

Constants

View Source
const (
	// DefaultPrefix is where the routes are mounted when Config leaves Prefix
	// empty.
	DefaultPrefix = "/inspect"
	// DefaultTTL is how long an inspection lasts before it lapses.
	DefaultTTL = time.Hour
	// MaxTTL is the longest an inspection may be configured to last.
	MaxTTL = 12 * time.Hour
	// DefaultUserType is the kind the activity log names an account by.
	DefaultUserType = "user"
	// LogName is the activity log the package's own entries go in.
	LogName = "inspect"
)
View Source
const (
	// EndLeft is the operator going back to their own account.
	EndLeft = "left"
	// EndExpired is the deadline passing.
	EndExpired = "expired"
)

The reasons an inspection ends.

View Source
const (
	// InspectStart is an operator going into somebody's account.
	InspectStart security.Action = "inspect.start"
	// InspectLeave is the operator going back to their own account.
	InspectLeave security.Action = "inspect.leave"
	// InspectHistory is reading who went into which account, and when.
	InspectHistory security.Action = "inspect.history"
)

The actions of the package. Constants rather than strings at the call site: a typo in an action name would silently authorize nothing, or worse, everything.

View Source
const OperatorRole = "inspect.operator"

OperatorRole is the role that may go into other people's accounts and read the history. The application gives it through arandu-permission, which fills the Subject's roles.

Variables

View Source
var (
	// ErrOperatorAccount is an operator going into another operator's
	// account.
	ErrOperatorAccount = fmt.Errorf("inspect: an operator's account is not inspected: %w", security.ErrForbidden)
	// ErrNotInspecting is a leave asked by somebody who is in no account but
	// their own.
	ErrNotInspecting = fmt.Errorf("inspect: nobody is inside another account here: %w", security.ErrForbidden)
)

The refusals of an inspection the policy cannot see, because they are about the account and not the inspection. Each wraps ErrForbidden.

View Source
var ErrNotFound = fmt.Errorf("inspect: record not found: %w", model.ErrModelNotFound)

ErrNotFound is a record the caller may not see or that does not exist. It wraps model.ErrModelNotFound, which the router answers with 404.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Prefix is the path the routes are mounted under. Empty means
	// DefaultPrefix.
	Prefix string

	// Targets loads the account an operator goes into. Required.
	Targets Targets

	// Activity is arandu-activitylog's logger. Required: going in, coming
	// back and the deadline passing are entries, and everything done inside
	// the account is recorded under the operator's name by the log itself.
	Activity *activitylog.Logger

	// Landing is where the operator lands inside the account, and Return
	// where they land back in their own. Empty means "/".
	Landing string
	Return  string

	// TTL is how long an inspection lasts. Zero means DefaultTTL; above
	// MaxTTL is refused.
	TTL time.Duration

	// UserType is the kind the activity log names accounts by, the one the
	// application's own entries use. Empty means DefaultUserType.
	UserType string
}

Config is everything the module needs from the application.

func (Config) Validate

func (c Config) Validate() error

Validate reports the first setting that cannot work.

type Flag

type Flag bool

Flag is a yes-or-no stored as 0 or 1, which every engine reads the same.

func (*Flag) Scan

func (f *Flag) Scan(value any) error

Scan reads a flag from whatever the engine answers.

func (Flag) Value

func (f Flag) Value() (driver.Value, error)

Value writes the flag as 0 or 1.

type HistoryQuery

type HistoryQuery struct {
	ActorID  string
	TargetID string
	Status   Status
	Page     int
	PerPage  int
}

HistoryQuery narrows the history. Page counts from one.

type InspectPolicy

type InspectPolicy struct{}

InspectPolicy is the only authority over who goes into whose account.

It denies unless a rule below allows. An operator goes into accounts of their own tenant and reads its history; whoever an inspection names as its operator ends it. Whether the account itself may be gone into -- another operator's, the operator's own -- is the service's refusal, because the policy sees the inspection and not the account.

func (InspectPolicy) Can

Can decides whether the subject may perform the action on the record.

type InspectService

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

InspectService is the package's use cases. It owns the database handle; every exported method asks the policy before it reads or writes.

func NewInspectService

func NewInspectService(db *data.DB) *InspectService

NewInspectService returns the use cases over a database handle. New wires the rest.

func (*InspectService) Find

func (s *InspectService) Find(ctx context.Context, actor security.Subject, id string) (*Inspection, error)

Find answers one inspection, for an operator.

func (*InspectService) History

func (s *InspectService) History(ctx context.Context, actor security.Subject, q HistoryQuery) ([]*Inspection, int, error)

History is a page of inspections, newest first, and how many there are.

func (*InspectService) Lapsed

func (s *InspectService) Lapsed(ctx context.Context, current security.Subject) (bool, error)

Lapsed reports whether the inspection the current subject is in has passed its deadline, or no longer exists as open. A subject that is in no inspection has nothing lapsed.

func (*InspectService) Leave

func (s *InspectService) Leave(ctx context.Context, current security.Subject, reason string) (security.Subject, *Inspection, error)

Leave takes the operator inside an account back to their own: the answer is the operator's own subject, for the session, and the inspection it closed. reason is EndLeft or EndExpired.

func (*InspectService) OpenNow

func (s *InspectService) OpenNow(ctx context.Context, actor security.Subject) ([]*Inspection, error)

OpenNow lists the inspections under way: who is inside which account right now, and until when.

func (*InspectService) Start

func (s *InspectService) Start(ctx context.Context, actor security.Subject, targetID string) (security.Subject, *Inspection, error)

Start takes an operator into somebody's account: the answer is the subject the session carries from then on -- the account's owner, with the operator kept as the one acting, able to change it -- and the inspection that records the visit.

The operator may not go into their own account, into another operator's, or anywhere from inside an account already.

type Inspection

type Inspection struct {
	model.Model

	ID       string `db:"id"`
	TenantID string `db:"tenant_id"`

	// ActorID is the operator; TargetID the account they went into.
	ActorID  string `db:"actor_id"`
	TargetID string `db:"target_id"`

	// Acting says the operator could change the account, and not only look.
	Acting Flag `db:"acting"`

	// Status is open while the operator is inside, closed once they left or
	// the deadline passed. ClosedAt and EndReason mean something only once it
	// is closed.
	Status    Status    `db:"status"`
	StartedAt time.Time `db:"started_at"`
	ExpiresAt time.Time `db:"expires_at"`
	ClosedAt  time.Time `db:"closed_at"`
	EndReason string    `db:"end_reason"`

	CreatedAt time.Time `db:"created_at"`
	UpdatedAt time.Time `db:"updated_at"`
}

Inspection is one time an operator went into somebody's account: who, whose account, whether they could change it, when it began, when it lapses, and how it ended.

It is the package's own record of the visit, kept so the session can be held to a deadline and so the list of who went where can be read without reading the whole activity log. What the operator did inside the account is in the activity log, under their name, and not here.

func (Inspection) Expired

func (i Inspection) Expired(now time.Time) bool

Expired reports whether the deadline has passed at now.

func (*Inspection) Fresh

func (row *Inspection) Fresh(ctx context.Context, g auth.Grant, with ...string) (*Inspection, error)

Fresh reads the row again, as a new Inspection; it shadows the untyped one the embedded model promotes.

func (*Inspection) Replicate

func (row *Inspection) Replicate(except ...string) (*Inspection, error)

Replicate returns an unsaved copy of the row without its key; it shadows the untyped one the embedded model promotes.

type InspectionCollection

type InspectionCollection []*Inspection

InspectionCollection is rows of Inspection, as a query returns them.

func InspectionCollectionOf

func InspectionCollectionOf(rows model.Rows) InspectionCollection

InspectionCollectionOf converts rows of the table of Inspection. A nil input is a nil collection.

func (InspectionCollection) Contains

func (c InspectionCollection) Contains(key any) bool

func (InspectionCollection) Except

func (c InspectionCollection) Except(keys ...any) InspectionCollection

func (InspectionCollection) Find

func (c InspectionCollection) Find(key any) *Inspection

func (InspectionCollection) FindOrFail

func (c InspectionCollection) FindOrFail(key any) (*Inspection, error)

func (InspectionCollection) Fresh

func (InspectionCollection) Load

func (c InspectionCollection) Load(ctx context.Context, g auth.Grant, relations ...string) error

func (InspectionCollection) LoadCount

func (c InspectionCollection) LoadCount(ctx context.Context, g auth.Grant, relations ...string) error

func (InspectionCollection) LoadMissing

func (c InspectionCollection) LoadMissing(ctx context.Context, g auth.Grant, relations ...string) error

func (InspectionCollection) ModelKeys

func (c InspectionCollection) ModelKeys() []any

func (InspectionCollection) Only

func (InspectionCollection) Pluck

func (c InspectionCollection) Pluck(column string) []any

func (InspectionCollection) Rows

func (c InspectionCollection) Rows() model.Rows

Rows converts the collection back to the core's rows.

func (InspectionCollection) ToArray

func (c InspectionCollection) ToArray() []map[string]any

func (InspectionCollection) Unique

type InspectionQuery

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

InspectionQuery is a query on the table of Inspection.

The methods that build return the query, so they chain. The methods that run take a context and an auth.Grant, and return Inspection rows or a value; there is no way to run one without a Grant.

func Inspections

func Inspections(db model.DB) *InspectionQuery

Inspections starts a query on the table of Inspection, through db.

Global scopes are on and, unless the table is Global, every statement is filtered by the tenant of the Grant its terminal takes.

func (*InspectionQuery) AddSelect

func (q *InspectionQuery) AddSelect(columns ...any) *InspectionQuery

func (*InspectionQuery) Avg

func (q *InspectionQuery) Avg(ctx context.Context, g auth.Grant, column any) (any, error)

func (*InspectionQuery) Base

func (q *InspectionQuery) Base() *model.Builder

Base returns the core builder the query forwards to. It is for code in this package -- a local scope in the custom block of model.go -- and for the factory, which builds rows through it.

func (*InspectionQuery) Chunk

func (q *InspectionQuery) Chunk(ctx context.Context, g auth.Grant, count int, callback func(InspectionCollection, int) (bool, error)) error

func (*InspectionQuery) Clone

func (q *InspectionQuery) Clone() *InspectionQuery

Clone returns an independent copy of the query.

func (*InspectionQuery) Count

func (q *InspectionQuery) Count(ctx context.Context, g auth.Grant, columns ...any) (int64, error)

func (*InspectionQuery) Create

func (q *InspectionQuery) Create(ctx context.Context, g auth.Grant, attributes map[string]any) (*Inspection, error)

func (*InspectionQuery) Cursor

func (*InspectionQuery) CursorPaginate

func (q *InspectionQuery) CursorPaginate(ctx context.Context, g auth.Grant, perPage int, cursor *pagination.Cursor, opts pagination.Options, columns ...any) (InspectionCollection, *pagination.CursorPage, error)

func (*InspectionQuery) Decrement

func (q *InspectionQuery) Decrement(ctx context.Context, g auth.Grant, column string, amount any, extra map[string]any) (int64, error)

func (*InspectionQuery) Delete

func (q *InspectionQuery) Delete(ctx context.Context, g auth.Grant) (int64, error)

func (*InspectionQuery) DoesntExist

func (q *InspectionQuery) DoesntExist(ctx context.Context, g auth.Grant) (bool, error)

func (*InspectionQuery) DoesntHave

func (q *InspectionQuery) DoesntHave(relation, boolean string, callback func(*query.Builder)) *InspectionQuery

func (*InspectionQuery) Each

func (q *InspectionQuery) Each(ctx context.Context, g auth.Grant, count int, callback func(*Inspection, int) (bool, error)) error

func (*InspectionQuery) Exists

func (q *InspectionQuery) Exists(ctx context.Context, g auth.Grant) (bool, error)

func (*InspectionQuery) Find

func (q *InspectionQuery) Find(ctx context.Context, g auth.Grant, id any, columns ...any) (*Inspection, error)

func (*InspectionQuery) FindMany

func (q *InspectionQuery) FindMany(ctx context.Context, g auth.Grant, ids []any, columns ...any) (InspectionCollection, error)

func (*InspectionQuery) FindOrFail

func (q *InspectionQuery) FindOrFail(ctx context.Context, g auth.Grant, id any, columns ...any) (*Inspection, error)

func (*InspectionQuery) FindOrNew

func (q *InspectionQuery) FindOrNew(ctx context.Context, g auth.Grant, id any, columns ...any) (*Inspection, error)

func (*InspectionQuery) First

func (q *InspectionQuery) First(ctx context.Context, g auth.Grant, columns ...any) (*Inspection, error)

First returns the first row, or nil and no error when there is none.

func (*InspectionQuery) FirstOrCreate

func (q *InspectionQuery) FirstOrCreate(ctx context.Context, g auth.Grant, attributes, values map[string]any) (*Inspection, error)

func (*InspectionQuery) FirstOrFail

func (q *InspectionQuery) FirstOrFail(ctx context.Context, g auth.Grant, columns ...any) (*Inspection, error)

func (*InspectionQuery) FirstOrNew

func (q *InspectionQuery) FirstOrNew(ctx context.Context, g auth.Grant, attributes, values map[string]any) (*Inspection, error)

func (*InspectionQuery) FirstWhere

func (q *InspectionQuery) FirstWhere(ctx context.Context, g auth.Grant, column any, args ...any) (*Inspection, error)

func (*InspectionQuery) ForPage

func (q *InspectionQuery) ForPage(page, perPage int) *InspectionQuery

func (*InspectionQuery) ForceCreate

func (q *InspectionQuery) ForceCreate(ctx context.Context, g auth.Grant, attributes map[string]any) (*Inspection, error)

func (*InspectionQuery) Get

func (q *InspectionQuery) Get(ctx context.Context, g auth.Grant, columns ...any) (InspectionCollection, error)

Get runs the query and returns the rows.

func (*InspectionQuery) GroupBy

func (q *InspectionQuery) GroupBy(groups ...any) *InspectionQuery

func (*InspectionQuery) Has

func (q *InspectionQuery) Has(relation, operator string, count int, boolean string, callback func(*query.Builder)) *InspectionQuery

func (*InspectionQuery) Increment

func (q *InspectionQuery) Increment(ctx context.Context, g auth.Grant, column string, amount any, extra map[string]any) (int64, error)

func (*InspectionQuery) Insert

func (q *InspectionQuery) Insert(ctx context.Context, g auth.Grant, values ...map[string]any) (bool, error)

func (*InspectionQuery) InsertOrIgnore

func (q *InspectionQuery) InsertOrIgnore(ctx context.Context, g auth.Grant, values ...map[string]any) (bool, error)

func (*InspectionQuery) Join

func (q *InspectionQuery) Join(table any, first any, args ...any) *InspectionQuery

func (*InspectionQuery) Latest

func (q *InspectionQuery) Latest(column ...string) *InspectionQuery

func (*InspectionQuery) Limit

func (q *InspectionQuery) Limit(value int) *InspectionQuery

func (*InspectionQuery) Max

func (q *InspectionQuery) Max(ctx context.Context, g auth.Grant, column any) (any, error)

func (*InspectionQuery) Min

func (q *InspectionQuery) Min(ctx context.Context, g auth.Grant, column any) (any, error)

func (*InspectionQuery) New

func (q *InspectionQuery) New() (*Inspection, error)

New returns an empty Inspection on the query's connection, not yet saved, filled with what WithAttributes recorded on the query.

func (*InspectionQuery) Offset

func (q *InspectionQuery) Offset(value int) *InspectionQuery

func (*InspectionQuery) Oldest

func (q *InspectionQuery) Oldest(column ...string) *InspectionQuery

func (*InspectionQuery) OrDoesntHave

func (q *InspectionQuery) OrDoesntHave(relation string) *InspectionQuery

func (*InspectionQuery) OrHas

func (q *InspectionQuery) OrHas(relation, operator string, count int) *InspectionQuery

func (*InspectionQuery) OrWhere

func (q *InspectionQuery) OrWhere(column any, args ...any) *InspectionQuery

OrWhere adds an or-where clause; a func(*InspectionQuery) in place of the column adds a group.

func (*InspectionQuery) OrWhereDoesntHave

func (q *InspectionQuery) OrWhereDoesntHave(relation string, callback func(*query.Builder)) *InspectionQuery

func (*InspectionQuery) OrWhereHas

func (q *InspectionQuery) OrWhereHas(relation string, callback func(*query.Builder)) *InspectionQuery

func (*InspectionQuery) OrWhereNot

func (q *InspectionQuery) OrWhereNot(column any, args ...any) *InspectionQuery

OrWhereNot adds an or-joined negated where clause, or a negated group.

func (*InspectionQuery) OrWhereRelation

func (q *InspectionQuery) OrWhereRelation(relation string, column any, args ...any) *InspectionQuery

func (*InspectionQuery) OrderBy

func (q *InspectionQuery) OrderBy(column any, direction ...string) *InspectionQuery

func (*InspectionQuery) OrderByDesc

func (q *InspectionQuery) OrderByDesc(column any) *InspectionQuery

func (*InspectionQuery) Paginate

func (q *InspectionQuery) Paginate(ctx context.Context, g auth.Grant, perPage, page int, opts pagination.Options, columns ...any) (InspectionCollection, *pagination.LengthAwarePage, error)

func (*InspectionQuery) Pluck

func (q *InspectionQuery) Pluck(ctx context.Context, g auth.Grant, column string) ([]any, error)

func (*InspectionQuery) Select

func (q *InspectionQuery) Select(columns ...any) *InspectionQuery

func (*InspectionQuery) SelectRaw

func (q *InspectionQuery) SelectRaw(expression string, bindings ...any) *InspectionQuery

func (*InspectionQuery) SimplePaginate

func (q *InspectionQuery) SimplePaginate(ctx context.Context, g auth.Grant, perPage, page int, opts pagination.Options, columns ...any) (InspectionCollection, *pagination.Page, error)

func (*InspectionQuery) Sole

func (q *InspectionQuery) Sole(ctx context.Context, g auth.Grant, columns ...any) (*Inspection, error)

func (*InspectionQuery) SoleValue

func (q *InspectionQuery) SoleValue(ctx context.Context, g auth.Grant, column string) (any, error)

func (*InspectionQuery) Sum

func (q *InspectionQuery) Sum(ctx context.Context, g auth.Grant, column any) (any, error)

func (*InspectionQuery) Touch

func (q *InspectionQuery) Touch(ctx context.Context, g auth.Grant, column ...string) (int64, error)

func (*InspectionQuery) Update

func (q *InspectionQuery) Update(ctx context.Context, g auth.Grant, values map[string]any) (int64, error)

func (*InspectionQuery) UpdateOrCreate

func (q *InspectionQuery) UpdateOrCreate(ctx context.Context, g auth.Grant, attributes, values map[string]any) (*Inspection, error)

func (*InspectionQuery) Upsert

func (q *InspectionQuery) Upsert(ctx context.Context, g auth.Grant, values []map[string]any, uniqueBy, update []string) (int64, error)

func (*InspectionQuery) Value

func (q *InspectionQuery) Value(ctx context.Context, g auth.Grant, column string) (any, error)

func (*InspectionQuery) ValueOrFail

func (q *InspectionQuery) ValueOrFail(ctx context.Context, g auth.Grant, column string) (any, error)

func (*InspectionQuery) Where

func (q *InspectionQuery) Where(column any, args ...any) *InspectionQuery

Where adds a where clause; a func(*InspectionQuery) in place of the column adds a group.

func (*InspectionQuery) WhereBelongsTo

func (q *InspectionQuery) WhereBelongsTo(relationshipName string, related ...model.Entity) *InspectionQuery

func (*InspectionQuery) WhereBetween

func (q *InspectionQuery) WhereBetween(column any, from, to any) *InspectionQuery

func (*InspectionQuery) WhereColumn

func (q *InspectionQuery) WhereColumn(first any, args ...any) *InspectionQuery

func (*InspectionQuery) WhereDoesntHave

func (q *InspectionQuery) WhereDoesntHave(relation string, callback func(*query.Builder)) *InspectionQuery

func (*InspectionQuery) WhereExists

func (q *InspectionQuery) WhereExists(callback func(*query.Builder)) *InspectionQuery

func (*InspectionQuery) WhereHas

func (q *InspectionQuery) WhereHas(relation string, callback func(*query.Builder)) *InspectionQuery

func (*InspectionQuery) WhereHasCount

func (q *InspectionQuery) WhereHasCount(relation string, callback func(*query.Builder), operator string, count int) *InspectionQuery

func (*InspectionQuery) WhereIn

func (q *InspectionQuery) WhereIn(column any, values []any) *InspectionQuery

func (*InspectionQuery) WhereKey

func (q *InspectionQuery) WhereKey(id any) *InspectionQuery

func (*InspectionQuery) WhereNot

func (q *InspectionQuery) WhereNot(column any, args ...any) *InspectionQuery

WhereNot adds a negated where clause, or a negated group.

func (*InspectionQuery) WhereNotExists

func (q *InspectionQuery) WhereNotExists(callback func(*query.Builder)) *InspectionQuery

func (*InspectionQuery) WhereNotIn

func (q *InspectionQuery) WhereNotIn(column any, values []any) *InspectionQuery

func (*InspectionQuery) WhereNotNull

func (q *InspectionQuery) WhereNotNull(columns ...any) *InspectionQuery

func (*InspectionQuery) WhereNull

func (q *InspectionQuery) WhereNull(columns ...any) *InspectionQuery

func (*InspectionQuery) WhereRelation

func (q *InspectionQuery) WhereRelation(relation string, column any, args ...any) *InspectionQuery

func (*InspectionQuery) With

func (q *InspectionQuery) With(relations ...string) *InspectionQuery

func (*InspectionQuery) WithAvg

func (q *InspectionQuery) WithAvg(relation, column string) *InspectionQuery

func (*InspectionQuery) WithCount

func (q *InspectionQuery) WithCount(relations ...string) *InspectionQuery

func (*InspectionQuery) WithExists

func (q *InspectionQuery) WithExists(relation string) *InspectionQuery

func (*InspectionQuery) WithMax

func (q *InspectionQuery) WithMax(relation, column string) *InspectionQuery

func (*InspectionQuery) WithMin

func (q *InspectionQuery) WithMin(relation, column string) *InspectionQuery

func (*InspectionQuery) WithSum

func (q *InspectionQuery) WithSum(relation, column string) *InspectionQuery

func (*InspectionQuery) Without

func (q *InspectionQuery) Without(relations ...string) *InspectionQuery

func (*InspectionQuery) WithoutGlobalScope

func (q *InspectionQuery) WithoutGlobalScope(identifier string) *InspectionQuery

func (*InspectionQuery) WithoutGlobalScopes

func (q *InspectionQuery) WithoutGlobalScopes(identifiers ...string) *InspectionQuery

type Module

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

Module is what the application registers.

func New

func New(cfg Config, db *data.DB, sessions *security.SessionStore) (*Module, error)

New returns the module, or the reason it cannot be built.

func (*Module) Guard

func (m *Module) Guard() func(stdhttp.Handler) stdhttp.Handler

Guard ends an inspection whose deadline passed: the next request of the operator inside the account is taken back to their own, and the end is recorded. The application mounts it after RequireAuth on the routes an operator can reach from inside an account -- its panel, usually:

panel := r.Group("/painel", middleware.RequireAuth(sessions), inspectModule.Guard())

func (*Module) Migrations

func (m *Module) Migrations() []foundation.Migration

Migrations declares the schema this module owns.

func (*Module) Name

func (m *Module) Name() string

Name is the module identifier.

func (*Module) Routes

func (m *Module) Routes(r *fhttp.Router)

Routes registers the module's routes, behind RequireAuth.

inspect.leave is the name hesape's view.New links the way back by, so the bar every page draws posts here without the application spelling the path.

func (*Module) Service

func (m *Module) Service() *InspectService

Service is the use cases, for an application that calls them from its own code. Every method asks the policy.

type Status

type Status string

Status is where an inspection stands.

const (
	// Open is an operator inside the account now.
	Open Status = "open"
	// Closed is an inspection that ended.
	Closed Status = "closed"
)

type Targets

type Targets interface {
	Target(ctx context.Context, tenant, userID string) (security.Subject, error)
}

Targets is the application's answer to "who is this account": the subject its owner signs in as -- identifier, tenant, roles, actions -- so the operator inside the account is exactly what the owner is. The package keeps no users of its own.

type TargetsFunc

type TargetsFunc func(ctx context.Context, tenant, userID string) (security.Subject, error)

TargetsFunc is a function that answers Targets.

func (TargetsFunc) Target

func (f TargetsFunc) Target(ctx context.Context, tenant, userID string) (security.Subject, error)

Target calls f.

Jump to

Keyboard shortcuts

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