Files
sm-feedback-plugin/jobs.go
Jakub Zych af5d77c997 feat: G15Office job, widget settings and submissions admin, embed.js and the settings importer
- SyncG15Office files each submission as a G15Office task with its screenshot through a fetchguard client limited to the configured host; a River job with 3 attempts, PHP's messages on failure, nothing sent when unconfigured
- the replay of PHP's recorded G15Office exchange (classes/testdata) asserts the task JSON, headers and the screenshot part
- settings screen (cabana field types only), read-only submissions list, manage_settings permission and navigation
- embed.js served byte for byte at /plugins/golem15/feedback/assets/js/embed.js
- feedback:import-settings copies the WinterCMS settings row once
2026-10-04 00:22:08 +02:00

55 lines
1.6 KiB
Go

package feedback
import (
"context"
"errors"
"log/slog"
"git.golem15.com/golem15/sm-feedback-plugin/classes"
"git.golem15.com/golem15/summercms/modules/conga"
"git.golem15.com/golem15/summercms/modules/pact"
"gocloud.dev/blob"
"gorm.io/gorm"
)
var _ pact.HasJobs = (*Plugin)(nil)
// Jobs registers the G15Office sync worker on the feedback queue, with
// SyncFeedbackToG15Office::$tries attempts (River's backoff replaces PHP's
// fixed 30 s between them).
func (p *Plugin) Jobs() []pact.Job {
return []pact.Job{
conga.Job(p.syncG15Office, conga.OnQueue(classes.SyncG15OfficeQueue), conga.MaxAttempts(3)),
}
}
// syncG15Office resolves the app services per run (Boot runs before serve
// publishes the database), files the submission and completes its
// summer_jobs row. The submission's content, the token and the URLs are
// never logged; only the submission id is.
func (p *Plugin) syncG15Office(ctx context.Context, args classes.SyncG15OfficeArgs) error {
if p.app == nil {
return errors.New("feedback: app is not booted")
}
gdb, ok := p.app.Lookup[*gorm.DB]()
if !ok || gdb == nil {
return errors.New("feedback: database is not published")
}
bucket, _ := p.app.Lookup[*blob.Bucket]()
err := classes.SyncG15Office(ctx, classes.SyncDeps{
DB: gdb,
Bucket: bucket,
Client: classes.NewG15OfficeClient(p.app.Config),
}, args)
if err != nil {
slog.Default().Warn("golem15.feedback: filing a submission in G15Office failed", slog.Uint64("submission_id", uint64(args.SubmissionID)))
return err
}
if id, ok := conga.JobID(ctx); ok {
if m, err := conga.From(p.app); err == nil {
return m.CompleteJob(ctx, id, nil)
}
}
return nil
}