check / check (push) Successful in 3m21s
The event log offered Replay on a delivery whose target was deleted, and the refusal told the operator to recreate the target and replay. That cannot work: a recreated target is a new one the old delivery does not name, so the replay is refused again. The Replay button is now left off such a delivery, whose row already names the target as deleted, and the refusal a page left open can still reach now points to Resubmit, which sends the event to the webhook's currently active targets. Model: opus-5-5
113 lines
3.9 KiB
Go
113 lines
3.9 KiB
Go
package handlers
|
|
|
|
import "net/http"
|
|
|
|
// noticeParam is the query parameter an action's redirect carries its
|
|
// notice code in.
|
|
const noticeParam = "notice"
|
|
|
|
// noticeCode names one of the fixed lines noticeFor knows. An action
|
|
// redirects with the code rather than the line, so nothing a client
|
|
// puts in the URL reaches the page: a code noticeFor does not know
|
|
// shows nothing.
|
|
type noticeCode string
|
|
|
|
// The codes of the actions on the webhook pages and of signing out.
|
|
// Replay's codes, with the reasons a replay can be refused, and
|
|
// resubmit's codes are defined beside those actions.
|
|
const (
|
|
webhookCreated noticeCode = "webhook-created"
|
|
webhookSaved noticeCode = "webhook-saved"
|
|
webhookDeleted noticeCode = "webhook-deleted"
|
|
entrypointAdded noticeCode = "entrypoint-added"
|
|
entrypointSaved noticeCode = "entrypoint-saved"
|
|
entrypointDeleted noticeCode = "entrypoint-deleted"
|
|
entrypointActivated noticeCode = "entrypoint-activated"
|
|
entrypointDeactivated noticeCode = "entrypoint-deactivated"
|
|
targetAdded noticeCode = "target-added"
|
|
targetSaved noticeCode = "target-saved"
|
|
targetDeleted noticeCode = "target-deleted"
|
|
targetActivated noticeCode = "target-activated"
|
|
targetDeactivated noticeCode = "target-deactivated"
|
|
signedOut noticeCode = "signed-out"
|
|
)
|
|
|
|
// notice is the line templates/notice.html shows above a page to say
|
|
// what an action did.
|
|
type notice struct {
|
|
Text string
|
|
|
|
// Failed shows the line as an error: the action was refused.
|
|
Failed bool
|
|
}
|
|
|
|
// noticeFor returns the notice the request's URL names, or nil when it
|
|
// names none or an unknown code.
|
|
func noticeFor(r *http.Request) *notice {
|
|
n, ok := map[noticeCode]notice{
|
|
webhookCreated: {Text: "Webhook created."},
|
|
webhookSaved: {Text: "Webhook saved."},
|
|
webhookDeleted: {Text: "Webhook deleted."},
|
|
entrypointAdded: {Text: "Entrypoint added."},
|
|
entrypointSaved: {Text: "Entrypoint description saved."},
|
|
entrypointDeleted: {Text: "Entrypoint deleted."},
|
|
entrypointActivated: {Text: "Entrypoint activated."},
|
|
entrypointDeactivated: {Text: "Entrypoint deactivated."},
|
|
targetAdded: {Text: "Target added."},
|
|
targetSaved: {Text: "Target saved."},
|
|
targetDeleted: {Text: "Target deleted."},
|
|
targetActivated: {Text: "Target activated."},
|
|
targetDeactivated: {Text: "Target deactivated."},
|
|
signedOut: {Text: "Signed out."},
|
|
|
|
replayQueued: {
|
|
Text: "Replay queued: a new delivery was created " +
|
|
"against the target's current configuration.",
|
|
},
|
|
replayTargetDeleted: {
|
|
Text: "Not replayed: the target this delivery was for " +
|
|
"has been deleted. Use Resubmit to send the event " +
|
|
"to the webhook's currently active targets.",
|
|
Failed: true,
|
|
},
|
|
replayTargetMissing: {
|
|
Text: "Not replayed: the target this delivery was for " +
|
|
"no longer exists.",
|
|
Failed: true,
|
|
},
|
|
replayTargetInactive: {
|
|
Text: "Not replayed: the target this delivery was for " +
|
|
"is deactivated. Activate it, then replay.",
|
|
Failed: true,
|
|
},
|
|
replayNotTerminal: {
|
|
Text: "Not replayed: this delivery has not finished yet.",
|
|
Failed: true,
|
|
},
|
|
replayInFlight: {
|
|
Text: "Not replayed: a delivery of this event to this " +
|
|
"target is already in flight.",
|
|
Failed: true,
|
|
},
|
|
|
|
resubmitQueued: {
|
|
Text: "Resubmitted: a new event was created from the " +
|
|
"stored one and queued to every active target.",
|
|
},
|
|
resubmitNoTargets: {
|
|
Text: "Resubmitted: a new event was created, but this " +
|
|
"source has no active targets, so nothing was queued.",
|
|
},
|
|
}[noticeCode(r.URL.Query().Get(noticeParam))]
|
|
if !ok {
|
|
return nil
|
|
}
|
|
|
|
return &n
|
|
}
|
|
|
|
// withNotice returns path with code added as its notice.
|
|
func withNotice(path string, code noticeCode) string {
|
|
return path + "?" + noticeParam + "=" + string(code)
|
|
}
|