errorreports

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorReportSelectedTextMin = 3
	ErrorReportSelectedTextMax = 10000
	ErrorReportCommentMax      = 2000
	ErrorReportPageURLMax      = 2048
)

The bounds of a report's fields, in characters: the selected text's least and greatest length, the comment's and the page address's greatest.

View Source
const MailNewReport = manifest.Name + ".new_report"

MailNewReport - the e-mail of a new report to the site's address (modulekit.AddMail).

Variables

View Source
var (
	ErrErrorReportSelectedText = i18n.Errorf("the selected text is too short or too long")
	ErrErrorReportPageURL      = i18n.Errorf("invalid page address")
	ErrErrorReportComment      = i18n.Errorf("the comment is too long")
)

The errors of invalid report input (ErrorReportService.Create): the selected text's length out of its bounds, a page address that is not the site's, a comment too long.

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 PageData

func PageData(_ *http.Request, data map[string]any)

PageData - every page's data for the report form (AddPageData): its CAPTCHA site key, when the CAPTCHA protects it.

func RegisterRoutes

func RegisterRoutes(r modulekit.Mux, erc *ErrorReportController, submitRL *ratelimit.RateLimiter, admin func(http.Handler) http.Handler)

RegisterRoutes registers the report form's endpoint (rate limited) and the admin list and its "fixed" and "back to the new ones" actions (behind admin - sign-in and the admin permission).

func ValidateErrorReportPageURL

func ValidateErrorReportPageURL(pageURL, siteHost string) error

ValidateErrorReportPageURL ensures page_url is a path or an address of the site at siteHost (its host name, from the site's address).

func Wire

func Wire(d modulekit.Deps) modulekit.Parts

Wire - the module's service, its e-mail (the Mail page), page data, the admin menu's count of new reports, controller and routes (modulekit).

Types

type EntErrorReportRepository

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

EntErrorReportRepository implements ErrorReportRepository on the module's own ent schema (ent/); the reporters - core users - come from the core's user repository.

func NewErrorReportRepository

func NewErrorReportRepository(db *sql.DB, users modulekit.UserRepository) *EntErrorReportRepository

NewErrorReportRepository creates a new EntErrorReportRepository on db, in the repositories' dialect (modulekit.DBDialect).

func (*EntErrorReportRepository) CountNew

func (r *EntErrorReportRepository) CountNew(ctx context.Context) (int, error)

CountNew returns the number of reports not marked fixed.

func (*EntErrorReportRepository) Create

Create inserts a new error report.

func (*EntErrorReportRepository) ListForAdmin

ListForAdmin returns error reports newest first with total count: the new ones, or all with opts.All.

func (*EntErrorReportRepository) Reopen

func (r *EntErrorReportRepository) Reopen(ctx context.Context, id int) error

Reopen returns a fixed report to the new ones (its fixed time cleared).

func (*EntErrorReportRepository) Resolve

func (r *EntErrorReportRepository) Resolve(ctx context.Context, id int) error

Resolve marks the report fixed now; an already fixed one is left as is.

type ErrorReport

type ErrorReport struct {
	ID           int
	UserID       *int
	PageURL      string
	SelectedText string
	Comment      string
	ClientIP     string
	UserAgent    string
	CreatedAt    time.Time
	// ResolvedAt - when an administrator marked the report fixed; nil
	// while it is new.
	ResolvedAt *time.Time
	// Populated for admin list when UserID is set.
	Username string
	UserSlug string
}

ErrorReport is a user-submitted report about incorrect text on a page.

type ErrorReportController

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

ErrorReportController - the error reports' handlers: the report form's endpoint and the admin list with its actions.

func NewErrorReportController

func NewErrorReportController(deps modulekit.BaseDeps, d ErrorReportDeps) *ErrorReportController

NewErrorReportController - the error reports' handlers on the base deps and the reports' service.

func (*ErrorReportController) AdminList

AdminList renders GET /admin/error-reports: the new reports (not marked fixed), newest first; ?status=all - all of them.

func (*ErrorReportController) Reopen

Reopen handles POST /admin/error-reports/{id}/reopen: returns a fixed report to the new ones, back to the list it was sent from.

func (*ErrorReportController) Resolve

Resolve handles POST /admin/error-reports/{id}/resolve: marks the report fixed and goes back to the list it was sent from (the form's "back").

func (*ErrorReportController) Submit

Submit handles POST /api/error-report (public, CSRF + optional reCAPTCHA).

type ErrorReportCreateInput

type ErrorReportCreateInput struct {
	UserID       *int
	PageURL      string
	SelectedText string
	Comment      string
	ClientIP     string
	UserAgent    string
}

ErrorReportCreateInput is validated input for creating a report.

type ErrorReportDeps

type ErrorReportDeps struct {
	ErrorReportService *ErrorReportService
}

ErrorReportDeps - what NewErrorReportController needs besides the BaseDeps.

type ErrorReportListOpts

type ErrorReportListOpts struct {
	Limit  int
	Offset int
	// All - the fixed reports too; otherwise only the new ones.
	All bool
}

ErrorReportListOpts filters admin listing.

type ErrorReportRepository

type ErrorReportRepository interface {
	Create(ctx context.Context, report ErrorReport) (*ErrorReport, error)
	ListForAdmin(ctx context.Context, opts ErrorReportListOpts) (ErrorReports, int, error)
	// CountNew - the reports not marked fixed.
	CountNew(ctx context.Context) (int, error)
	// Resolve marks a report fixed (now); a fixed one keeps its time.
	Resolve(ctx context.Context, id int) error
	// Reopen returns a fixed report to the new ones.
	Reopen(ctx context.Context, id int) error
}

ErrorReportRepository persists error reports.

type ErrorReportService

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

ErrorReportService handles error report submission and admin notifications.

func NewErrorReportService

func NewErrorReportService(
	repo ErrorReportRepository,
	siteInformationRepo modulekit.SiteInformationRepository,
	userRepo modulekit.UserRepository,
	emailSender mailtemplate.Mailer,
	logger *slog.Logger,
) *ErrorReportService

NewErrorReportService creates ErrorReportService.

func (*ErrorReportService) CountNew

func (s *ErrorReportService) CountNew(ctx context.Context) (int, error)

CountNew returns the number of reports not marked fixed (the admin menu's count).

func (*ErrorReportService) Create

func (s *ErrorReportService) Create(ctx context.Context, in ErrorReportCreateInput, siteBase, adminListURL string) (*ErrorReport, error)

Create validates input, saves the report, and emails the site admin. The lengths are in characters, as the form's maxlength and the columns count. siteBase - the site's address (modulekit.MailBaseURL): the page must be the site's, and the administrators' e-mail links it there, not at the request's host (a request can name any).

func (*ErrorReportService) ListForAdmin

func (s *ErrorReportService) ListForAdmin(ctx context.Context, all bool, page, perPage int) (ErrorReports, int, error)

ListForAdmin returns paginated reports for the admin UI: the new ones, or all with all.

func (*ErrorReportService) Reopen

func (s *ErrorReportService) Reopen(ctx context.Context, id int) error

Reopen returns a fixed report to the new ones.

func (*ErrorReportService) Resolve

func (s *ErrorReportService) Resolve(ctx context.Context, id int) error

Resolve marks a report fixed.

type ErrorReports

type ErrorReports []ErrorReport

ErrorReports is a slice of ErrorReport.

Directories

Path Synopsis
ent
Package ent - the error reports 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 error reports 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 error reports module's own ent schema: its tables, apart from the core's (internal/infrastructure/ent/schema).
Package schema - the error reports module's own ent schema: its tables, apart from the core's (internal/infrastructure/ent/schema).
Package manifest declares the error reports module (its registry entry).
Package manifest declares the error reports module (its registry entry).

Jump to

Keyboard shortcuts

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