actionlog

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Assets embed.FS

Assets - the module's templates/ and static/, built into the binary (modules.Assets, paths.SetModuleAssets): a site runs without the module's source directory.

Functions

func ObjectLink(kind, id string) string

ObjectLink - the address of an object's own log (?kind=&id=).

func RegisterRoutes

func RegisterRoutes(r modulekit.Mux, c *Controller, admin func(http.Handler) http.Handler)

RegisterRoutes registers the log and its settings (behind admin; the handlers check the log's permission).

func Wire

func Wire(d modulekit.Deps) modulekit.Parts

Wire - the listener keeping the actions the site records, the job deleting the old entries, the log beside what it's about (the content form's row, the users list's button), its block on the admin's Overview and the log's pages.

Types

type Controller

type Controller struct {
	*modulekit.BaseController
	// contains filtered or unexported fields
}

Controller - the log and its settings.

func NewController

func NewController(base *modulekit.BaseController, repo *Repo, recorder *Recorder, types modulekit.ContentTypeService) *Controller

NewController creates a Controller.

func (*Controller) List

func (c *Controller) List(w http.ResponseWriter, r *http.Request)

List renders GET /admin/reports/action-log: the entries the filter (who, the group, the object, the days; a user's or an object's own) shows, newest first.

func (*Controller) Settings

func (c *Controller) Settings(w http.ResponseWriter, r *http.Request)

Settings renders GET /admin/reports/action-log/settings and saves it (POST): how long entries are kept, the addresses, the groups recorded.

type Entry

type Entry struct {
	ID        int
	At        time.Time
	Type      string
	Group     string
	ActorID   int
	ActorName string
	IP        string
	Object    modulekit.ActionObject
	Changes   []modulekit.ActionChange
}

Entry - a recorded action: when, its type and group, who (ActorID 0 - nobody signed in; ActorName - their name at the time), from where (IP, "" - not kept), what it was done to and what it changed.

type Filter

type Filter struct {
	Actor      string
	ActorID    int
	Group      string
	Object     string
	ObjectKind string
	ObjectID   string
	From, To   time.Time
}

Filter - what the log shows: Actor - a part of who's name, ActorID - one user's actions; Group - one group; Object - a part of the object's name, or its ID; ObjectKind and ObjectID - one object (the content's own log); From, To - the days (zero - no limit).

type Hooks

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

Hooks - the log beside what it's about: the "Log" row of a content's form, the log icon of a user in the admin's list.

func (Hooks) NodeSettings

func (h Hooks) NodeSettings() modulekit.NodeSettings

NodeSettings - the "Log" row of a content's form (a link, nothing saved): for an existing content and a user who may see the log.

func (Hooks) PageData

func (h Hooks) PageData(r *http.Request, data map[string]any)

PageData - every page's data (AddPageData): actionLogCanView, whether the user may see the log (the users list's log icons).

type Recorder

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

Recorder keeps the actions the site records (modulekit.OnAction) while the module is on, as its settings say: the groups turned off aren't kept, nor the address unless asked to.

func NewRecorder

func NewRecorder(repo *Repo, users modulekit.UserRepository, logger *slog.Logger) *Recorder

NewRecorder creates a Recorder.

func (*Recorder) Purge

func (r *Recorder) Purge(ctx context.Context) error

Purge deletes the entries older than the settings keep them - the module's background job.

func (*Recorder) Record

func (r *Recorder) Record(ctx context.Context, e modulekit.ActionEvent)

Record keeps the action e (the listener of modulekit.OnAction). Its failure is logged: the action itself is done.

func (*Recorder) SaveSettings

func (r *Recorder) SaveSettings(ctx context.Context, st Settings) error

SaveSettings saves the settings.

func (*Recorder) Settings

func (r *Recorder) Settings(ctx context.Context) Settings

Settings returns the module's settings (kept in memory once read).

type Repo

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

Repo - the module's tables.

func NewRepo

func NewRepo(db *sql.DB) *Repo

NewRepo creates a Repo on db, in the repositories' dialect. Its client is the database's own, never a transaction's: an action is recorded in the acting request, maybe inside the core's change, and the log's write isn't part of it - failing (on PostgreSQL a failed statement ends the transaction), it would fail the change.

func (*Repo) Add

func (r *Repo) Add(ctx context.Context, e Entry) error

Add stores an entry.

func (*Repo) Count

func (r *Repo) Count(ctx context.Context, f Filter) (int, error)

Count - how many entries the filter shows.

func (*Repo) List

func (r *Repo) List(ctx context.Context, f Filter, limit, offset int) ([]Entry, int, error)

List returns the entries the filter shows, newest first, a page at a time, with how many there are.

func (*Repo) Purge

func (r *Repo) Purge(ctx context.Context, before time.Time) (int, error)

Purge deletes the entries older than before; returns how many.

func (*Repo) SaveSettings

func (r *Repo) SaveSettings(ctx context.Context, s Settings) error

SaveSettings saves the module's settings.

func (*Repo) Settings

func (r *Repo) Settings(ctx context.Context) (Settings, error)

Settings returns the module's settings (the defaults until saved).

type Settings

type Settings struct {
	KeepDays  int
	LogIP     bool
	GroupsOff []string
}

Settings - the module's settings: KeepDays - how long entries are kept (0 - forever); LogIP - whether the address is kept; GroupsOff - the groups not recorded.

func (Settings) Off

func (s Settings) Off(group string) bool

Off - whether the group isn't recorded.

Directories

Path Synopsis
ent
Package ent - the action log module's own ent schema (schema/), its generated client (generated/, go generate) and migration files (migrations/<dialect>/, scripts/migrations_gen.sh writes them), apart from the core's: the module's set of migrations (Schema).
Package ent - the action log module's own ent schema (schema/), its generated client (generated/, go generate) and migration files (migrations/<dialect>/, scripts/migrations_gen.sh writes them), apart from the core's: the module's set of migrations (Schema).
schema
Package schema - the action log module's own ent schema: the recorded actions and the module's settings.
Package schema - the action log module's own ent schema: the recorded actions and the module's settings.
Package manifest declares the action log module (its registry entry): who did what on the site - content deleted, a role's permissions changed, settings saved, sign-ins.
Package manifest declares the action log module (its registry entry): who did what on the site - content deleted, a role's permissions changed, settings saved, sign-ins.

Jump to

Keyboard shortcuts

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