Merge: smoke cleanup batch 2 (t-paliad-040)

This commit is contained in:
m
2026-04-26 02:14:08 +02:00
3 changed files with 32 additions and 9 deletions

View File

@@ -24,16 +24,36 @@ func handleAppointmentsCalendarPage(w http.ResponseWriter, r *http.Request) {
}
// handleSettingsPage serves the unified settings page with tabs for
// Profil / Benachrichtigungen / CalDAV. The active tab is picked client-side
// from ?tab=<name> so switching tabs doesn't round-trip.
// Profil / Benachrichtigungen / CalDAV / Dezernat. The active tab is picked
// client-side from ?tab=<name> so switching tabs doesn't round-trip.
func handleSettingsPage(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "dist/settings.html")
}
// handleSettingsCalDAVRedirect keeps /settings/caldav working for
// bookmarks and any external links while the canonical URL moves to
// /settings?tab=caldav. 301 Moved Permanently — browsers cache the hop
// so the redirect only costs once per bookmark.
func handleSettingsCalDAVRedirect(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/settings?tab=caldav", http.StatusMovedPermanently)
// settingsTabAliases maps every supported /settings/<slug> deep-link to its
// canonical ?tab=<name> value the client TS understands. Both the German tab
// IDs (profil/benachrichtigungen/dezernat) and intuitive English aliases
// (profile/notifications/department) are accepted so bookmarks, smoke tests,
// and manually-typed URLs all land on the right tab.
var settingsTabAliases = map[string]string{
"profil": "profil",
"profile": "profil",
"benachrichtigungen": "benachrichtigungen",
"notifications": "benachrichtigungen",
"caldav": "caldav",
"dezernat": "dezernat",
"department": "dezernat",
}
// handleSettingsTabRedirect turns /settings/<slug> into /settings?tab=<canonical>
// as 301 Moved Permanently. Unknown slugs fall back to the bare /settings page
// (the client picks the default tab) so a typo doesn't 404.
func handleSettingsTabRedirect(w http.ResponseWriter, r *http.Request) {
slug := r.PathValue("tab")
canonical, ok := settingsTabAliases[slug]
if !ok {
http.Redirect(w, r, "/settings", http.StatusMovedPermanently)
return
}
http.Redirect(w, r, "/settings?tab="+canonical, http.StatusMovedPermanently)
}

View File

@@ -245,7 +245,7 @@ func Register(mux *http.ServeMux, client *auth.Client, giteaAPIToken string, svc
// Settings
protected.HandleFunc("GET /settings", gateOnboarded(handleSettingsPage))
protected.HandleFunc("GET /settings/caldav", handleSettingsCalDAVRedirect)
protected.HandleFunc("GET /settings/{tab}", handleSettingsTabRedirect)
// Catch-all 404 — runs for any authenticated path that no more-specific
// pattern claimed. Renders the chromed shell with HTTP 404 (Bug 9 from

View File

@@ -28,6 +28,9 @@ func registerLegacyRedirects(mux *http.ServeMux) {
"/parteien": "/parties",
"/gerichte": "/courts",
"/glossar": "/glossary",
// Memorable aliases — sidebar uses the canonical path but users
// type these from memory and would otherwise hit the 404 chrome.
"/whatsnew": "/changelog",
}
for oldPrefix, newPrefix := range prefixes {
mux.Handle("GET "+oldPrefix, redirectPrefix(oldPrefix, newPrefix))