Documentation
¶
Index ¶
- Constants
- Variables
- func PageData(_ *http.Request, data map[string]any)
- func RegisterRoutes(r modulekit.Mux, erc *ErrorReportController, submitRL *ratelimit.RateLimiter, ...)
- func ValidateErrorReportPageURL(pageURL, siteHost string) error
- func Wire(d modulekit.Deps) modulekit.Parts
- type EntErrorReportRepository
- func (r *EntErrorReportRepository) CountNew(ctx context.Context) (int, error)
- func (r *EntErrorReportRepository) Create(ctx context.Context, report ErrorReport) (*ErrorReport, error)
- func (r *EntErrorReportRepository) ListForAdmin(ctx context.Context, opts ErrorReportListOpts) (ErrorReports, int, error)
- func (r *EntErrorReportRepository) Reopen(ctx context.Context, id int) error
- func (r *EntErrorReportRepository) Resolve(ctx context.Context, id int) error
- type ErrorReport
- type ErrorReportController
- func (c *ErrorReportController) AdminList(w http.ResponseWriter, r *http.Request)
- func (c *ErrorReportController) Reopen(w http.ResponseWriter, r *http.Request)
- func (c *ErrorReportController) Resolve(w http.ResponseWriter, r *http.Request)
- func (c *ErrorReportController) Submit(w http.ResponseWriter, r *http.Request)
- type ErrorReportCreateInput
- type ErrorReportDeps
- type ErrorReportListOpts
- type ErrorReportRepository
- type ErrorReportService
- func (s *ErrorReportService) CountNew(ctx context.Context) (int, error)
- func (s *ErrorReportService) Create(ctx context.Context, in ErrorReportCreateInput, siteBase, adminListURL string) (*ErrorReport, error)
- func (s *ErrorReportService) ListForAdmin(ctx context.Context, all bool, page, perPage int) (ErrorReports, int, error)
- func (s *ErrorReportService) Reopen(ctx context.Context, id int) error
- func (s *ErrorReportService) Resolve(ctx context.Context, id int) error
- type ErrorReports
Constants ¶
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.
const MailNewReport = manifest.Name + ".new_report"
MailNewReport - the e-mail of a new report to the site's address (modulekit.AddMail).
Variables ¶
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.
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 ¶
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 ¶
ValidateErrorReportPageURL ensures page_url is a path or an address of the site at siteHost (its host name, from the site's address).
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 ¶
func (r *EntErrorReportRepository) Create(ctx context.Context, report ErrorReport) (*ErrorReport, error)
Create inserts a new error report.
func (*EntErrorReportRepository) ListForAdmin ¶
func (r *EntErrorReportRepository) ListForAdmin(ctx context.Context, opts ErrorReportListOpts) (ErrorReports, int, error)
ListForAdmin returns error reports newest first with total count: the new ones, or all with opts.All.
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 ¶
func (c *ErrorReportController) AdminList(w http.ResponseWriter, r *http.Request)
AdminList renders GET /admin/error-reports: the new reports (not marked fixed), newest first; ?status=all - all of them.
func (*ErrorReportController) Reopen ¶
func (c *ErrorReportController) Reopen(w http.ResponseWriter, r *http.Request)
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 ¶
func (c *ErrorReportController) Resolve(w http.ResponseWriter, r *http.Request)
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 ¶
func (c *ErrorReportController) Submit(w http.ResponseWriter, r *http.Request)
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.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
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). |