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 and resubmit's are beside those actions, with the reasons // each can be refused. const ( webhookCreated noticeCode = "webhook-created" webhookSaved noticeCode = "webhook-saved" webhookDeleted noticeCode = "webhook-deleted" entrypointAdded noticeCode = "entrypoint-added" 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."}, 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. Recreate the target, then replay.", 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) }