Say what each action did in a one-line notice (closes #383)
check / check (push) Waiting to run
check / check (push) Waiting to run
Saving, deleting, activating or deactivating a webhook, entrypoint or target, and signing out, now land on their page with a one-line notice such as "Webhook deleted." or "Signed out.". The redirect carries a fixed code that maps to fixed text; an unknown code shows nothing, so nothing from the URL is ever echoed. One partial in the page layout shows the notice on every page, and replay and resubmit now use the same codes and partial. Error pages show no notice. Model: opus-5-5
This commit was merged in pull request #420.
This commit is contained in:
@@ -322,7 +322,8 @@ func (h *Handlers) createWebhookWithEntrypoint(
|
||||
)
|
||||
|
||||
http.Redirect(
|
||||
w, r, "/hook/"+webhook.ID, http.StatusSeeOther,
|
||||
w, r, withNotice("/hook/"+webhook.ID, webhookCreated),
|
||||
http.StatusSeeOther,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -579,7 +580,8 @@ func (h *Handlers) applyWebhookEdit(
|
||||
}
|
||||
|
||||
http.Redirect(
|
||||
w, r, "/hook/"+webhook.ID, http.StatusSeeOther,
|
||||
w, r, withNotice("/hook/"+webhook.ID, webhookSaved),
|
||||
http.StatusSeeOther,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -662,7 +664,9 @@ func (h *Handlers) deleteWebhookResources(
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, "/hooks", http.StatusSeeOther)
|
||||
http.Redirect(
|
||||
w, r, withNotice("/hooks", webhookDeleted), http.StatusSeeOther,
|
||||
)
|
||||
}
|
||||
|
||||
// commitWebhookDeletion soft-deletes a webhook's entrypoints,
|
||||
@@ -841,31 +845,16 @@ func (h *Handlers) HandleSourceLogs() http.HandlerFunc {
|
||||
totalPages++
|
||||
}
|
||||
|
||||
// The banner a replay or resubmit POST redirected back
|
||||
// with. The message comes from a fixed set keyed by the
|
||||
// outcome code, never from the query string itself.
|
||||
replayMsg, replayOK := replayOutcome(
|
||||
r.URL.Query().Get(replayOutcomeParam),
|
||||
)
|
||||
|
||||
resubmitMsg, resubmitOK := resubmitOutcome(
|
||||
r.URL.Query().Get(resubmitOutcomeParam),
|
||||
)
|
||||
|
||||
data := map[string]any{
|
||||
tmplKeyWebhook: &webhook,
|
||||
"Events": evts,
|
||||
"ReplayMessage": replayMsg,
|
||||
"ReplayQueued": replayOK,
|
||||
"ResubmitMessage": resubmitMsg,
|
||||
"ResubmitQueued": resubmitOK,
|
||||
"Page": page,
|
||||
"TotalPages": totalPages,
|
||||
"TotalEvents": total,
|
||||
"HasPrev": page > 1,
|
||||
"HasNext": page < totalPages,
|
||||
"PrevPage": page - 1,
|
||||
"NextPage": page + 1,
|
||||
tmplKeyWebhook: &webhook,
|
||||
"Events": evts,
|
||||
"Page": page,
|
||||
"TotalPages": totalPages,
|
||||
"TotalEvents": total,
|
||||
"HasPrev": page > 1,
|
||||
"HasNext": page < totalPages,
|
||||
"PrevPage": page - 1,
|
||||
"NextPage": page + 1,
|
||||
}
|
||||
|
||||
h.renderTemplate(w, r, "source_logs.html", data)
|
||||
@@ -1254,7 +1243,8 @@ func (h *Handlers) HandleEntrypointCreate() http.HandlerFunc {
|
||||
}
|
||||
|
||||
http.Redirect(
|
||||
w, r, "/hook/"+webhook.ID, http.StatusSeeOther,
|
||||
w, r, withNotice("/hook/"+webhook.ID, entrypointAdded),
|
||||
http.StatusSeeOther,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1365,7 +1355,8 @@ func (h *Handlers) processTargetCreate(
|
||||
}
|
||||
|
||||
http.Redirect(
|
||||
w, r, "/hook/"+webhook.ID, http.StatusSeeOther,
|
||||
w, r, withNotice("/hook/"+webhook.ID, targetAdded),
|
||||
http.StatusSeeOther,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1643,6 +1634,7 @@ func (h *Handlers) HandleEntrypointDelete() http.HandlerFunc {
|
||||
"entrypointID", &database.Entrypoint{},
|
||||
"failed to delete entrypoint",
|
||||
nil,
|
||||
entrypointDeleted,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1655,18 +1647,21 @@ func (h *Handlers) HandleTargetDelete() http.HandlerFunc {
|
||||
"targetID", &database.Target{},
|
||||
"failed to delete target",
|
||||
h.evictArchiveWriterIfUnused,
|
||||
targetDeleted,
|
||||
)
|
||||
}
|
||||
|
||||
// deleteChildResource returns a handler that deletes a child
|
||||
// resource (entrypoint or target) belonging to a webhook. The
|
||||
// optional afterDelete hook runs with the webhook's id once the
|
||||
// delete has succeeded, before the redirect.
|
||||
// delete has succeeded, before the redirect, which carries done as
|
||||
// its notice.
|
||||
func (h *Handlers) deleteChildResource(
|
||||
idParam string,
|
||||
model any,
|
||||
errMsg string,
|
||||
afterDelete func(webhookID string),
|
||||
done noticeCode,
|
||||
) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
userID, ok := h.getUserID(r)
|
||||
@@ -1708,7 +1703,7 @@ func (h *Handlers) deleteChildResource(
|
||||
|
||||
http.Redirect(
|
||||
w, r,
|
||||
"/hook/"+webhook.ID,
|
||||
withNotice("/hook/"+webhook.ID, done),
|
||||
http.StatusSeeOther,
|
||||
)
|
||||
}
|
||||
@@ -1719,7 +1714,7 @@ func (h *Handlers) deleteChildResource(
|
||||
func (h *Handlers) HandleEntrypointToggle() http.HandlerFunc {
|
||||
return h.toggleChildResource(
|
||||
"entrypointID",
|
||||
func(webhookID, childID string) error {
|
||||
func(webhookID, childID string) (bool, error) {
|
||||
var ep database.Entrypoint
|
||||
|
||||
err := h.db.DB().Where(
|
||||
@@ -1727,14 +1722,15 @@ func (h *Handlers) HandleEntrypointToggle() http.HandlerFunc {
|
||||
childID, webhookID,
|
||||
).First(&ep).Error
|
||||
if err != nil {
|
||||
return err
|
||||
return false, err
|
||||
}
|
||||
|
||||
ep.Active = !ep.Active
|
||||
|
||||
return h.db.DB().Save(&ep).Error
|
||||
return ep.Active, h.db.DB().Save(&ep).Error
|
||||
},
|
||||
"failed to toggle entrypoint",
|
||||
entrypointActivated, entrypointDeactivated,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1742,7 +1738,7 @@ func (h *Handlers) HandleEntrypointToggle() http.HandlerFunc {
|
||||
func (h *Handlers) HandleTargetToggle() http.HandlerFunc {
|
||||
return h.toggleChildResource(
|
||||
"targetID",
|
||||
func(webhookID, childID string) error {
|
||||
func(webhookID, childID string) (bool, error) {
|
||||
var tgt database.Target
|
||||
|
||||
err := h.db.DB().Where(
|
||||
@@ -1750,23 +1746,27 @@ func (h *Handlers) HandleTargetToggle() http.HandlerFunc {
|
||||
childID, webhookID,
|
||||
).First(&tgt).Error
|
||||
if err != nil {
|
||||
return err
|
||||
return false, err
|
||||
}
|
||||
|
||||
tgt.Active = !tgt.Active
|
||||
|
||||
return h.db.DB().Save(&tgt).Error
|
||||
return tgt.Active, h.db.DB().Save(&tgt).Error
|
||||
},
|
||||
"failed to toggle target",
|
||||
targetActivated, targetDeactivated,
|
||||
)
|
||||
}
|
||||
|
||||
// toggleChildResource returns a handler that toggles the active
|
||||
// state of a child resource belonging to a webhook.
|
||||
// state of a child resource belonging to a webhook. toggleFn returns
|
||||
// the new state, and the redirect carries activated or deactivated as
|
||||
// its notice to match.
|
||||
func (h *Handlers) toggleChildResource(
|
||||
idParam string,
|
||||
toggleFn func(webhookID, childID string) error,
|
||||
toggleFn func(webhookID, childID string) (bool, error),
|
||||
errMsg string,
|
||||
activated, deactivated noticeCode,
|
||||
) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
userID, ok := h.getUserID(r)
|
||||
@@ -1792,16 +1792,21 @@ func (h *Handlers) toggleChildResource(
|
||||
return
|
||||
}
|
||||
|
||||
err = toggleFn(webhook.ID, childID)
|
||||
active, err := toggleFn(webhook.ID, childID)
|
||||
if err != nil {
|
||||
h.serverError(w, r, errMsg, err)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
done := deactivated
|
||||
if active {
|
||||
done = activated
|
||||
}
|
||||
|
||||
http.Redirect(
|
||||
w, r,
|
||||
"/hook/"+webhook.ID,
|
||||
withNotice("/hook/"+webhook.ID, done),
|
||||
http.StatusSeeOther,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user