fix: Admin-Link in der Navigation zeigen
Nach dem Login landet jeder Nutzer (auch ein Admin, jeder Login gehört
zu einem Account) auf der normalen Startseite — ohne einen Link zu
/admin in der Navigation war der Admin-Bereich für einen Admin ohne
die URL im Kopf praktisch unerreichbar (genau das hat der Nutzer nach
dem Login gemeldet).
navData{IsAdmin} wird jetzt von jeder angemeldeten Seite (Start,
Beiträge, Beitrag-Detail, alle Admin-Seiten) an den gemeinsamen
"nav"-Template-Block durchgereicht; der Link erscheint nur für
role=admin. Test deckt beide Fälle ab (Admin sieht den Link, Mandant
nicht).
This commit is contained in:
@@ -34,6 +34,7 @@ func (s *Server) handlePublicKanzleiList(w http.ResponseWriter, r *http.Request)
|
|||||||
|
|
||||||
type adminDashboardData struct {
|
type adminDashboardData struct {
|
||||||
Title string
|
Title string
|
||||||
|
Nav navData
|
||||||
AccountCount int
|
AccountCount int
|
||||||
UnverifiedCount int
|
UnverifiedCount int
|
||||||
RecentAuditCount int
|
RecentAuditCount int
|
||||||
@@ -61,7 +62,7 @@ func (s *Server) handleAdminDashboard(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data := adminDashboardData{
|
data := adminDashboardData{
|
||||||
Title: "Admin", AccountCount: len(accounts), UnverifiedCount: unverified, RecentAuditCount: len(auditLog),
|
Title: "Admin", Nav: navFor(r), AccountCount: len(accounts), UnverifiedCount: unverified, RecentAuditCount: len(auditLog),
|
||||||
}
|
}
|
||||||
if err := s.templates.ExecuteTemplate(w, "admin-dashboard", data); err != nil {
|
if err := s.templates.ExecuteTemplate(w, "admin-dashboard", data); err != nil {
|
||||||
http.Error(w, "Seite konnte nicht gerendert werden", http.StatusInternalServerError)
|
http.Error(w, "Seite konnte nicht gerendert werden", http.StatusInternalServerError)
|
||||||
@@ -77,6 +78,7 @@ type adminAccountListItem struct {
|
|||||||
|
|
||||||
type adminAccountListData struct {
|
type adminAccountListData struct {
|
||||||
Title string
|
Title string
|
||||||
|
Nav navData
|
||||||
Accounts []adminAccountListItem
|
Accounts []adminAccountListItem
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,7 +89,7 @@ func (s *Server) handleAdminAccountList(w http.ResponseWriter, r *http.Request)
|
|||||||
http.Error(w, "Accounts konnten nicht geladen werden: "+err.Error(), http.StatusInternalServerError)
|
http.Error(w, "Accounts konnten nicht geladen werden: "+err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data := adminAccountListData{Title: "Accounts"}
|
data := adminAccountListData{Title: "Accounts", Nav: navFor(r)}
|
||||||
for _, a := range accounts {
|
for _, a := range accounts {
|
||||||
data.Accounts = append(data.Accounts, adminAccountListItem{
|
data.Accounts = append(data.Accounts, adminAccountListItem{
|
||||||
ID: a.ID, Name: a.Name, Verified: a.Verified, CreatedAt: a.CreatedAt.Format("02.01.2006 15:04"),
|
ID: a.ID, Name: a.Name, Verified: a.Verified, CreatedAt: a.CreatedAt.Format("02.01.2006 15:04"),
|
||||||
@@ -105,6 +107,7 @@ type adminUserView struct {
|
|||||||
|
|
||||||
type adminAccountDetailData struct {
|
type adminAccountDetailData struct {
|
||||||
Title string
|
Title string
|
||||||
|
Nav navData
|
||||||
AccountID string
|
AccountID string
|
||||||
Name string
|
Name string
|
||||||
Verified bool
|
Verified bool
|
||||||
@@ -130,7 +133,7 @@ func (s *Server) handleAdminAccountDetail(w http.ResponseWriter, r *http.Request
|
|||||||
}
|
}
|
||||||
|
|
||||||
data := adminAccountDetailData{
|
data := adminAccountDetailData{
|
||||||
Title: "Account", AccountID: acc.ID, Name: acc.Name, Verified: acc.Verified,
|
Title: "Account", Nav: navFor(r), AccountID: acc.ID, Name: acc.Name, Verified: acc.Verified,
|
||||||
CreatedAt: acc.CreatedAt.Format("02.01.2006 15:04"),
|
CreatedAt: acc.CreatedAt.Format("02.01.2006 15:04"),
|
||||||
}
|
}
|
||||||
for _, u := range users {
|
for _, u := range users {
|
||||||
@@ -190,6 +193,7 @@ type adminAuditEntryView struct {
|
|||||||
|
|
||||||
type adminAuditLogData struct {
|
type adminAuditLogData struct {
|
||||||
Title string
|
Title string
|
||||||
|
Nav navData
|
||||||
Entries []adminAuditEntryView
|
Entries []adminAuditEntryView
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,7 +204,7 @@ func (s *Server) handleAdminAuditLog(w http.ResponseWriter, r *http.Request) {
|
|||||||
http.Error(w, "Audit-Log konnte nicht geladen werden: "+err.Error(), http.StatusInternalServerError)
|
http.Error(w, "Audit-Log konnte nicht geladen werden: "+err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data := adminAuditLogData{Title: "Audit-Log"}
|
data := adminAuditLogData{Title: "Audit-Log", Nav: navFor(r)}
|
||||||
for _, e := range entries {
|
for _, e := range entries {
|
||||||
data.Entries = append(data.Entries, adminAuditEntryView{
|
data.Entries = append(data.Entries, adminAuditEntryView{
|
||||||
CreatedAt: e.CreatedAt.Format("02.01.2006 15:04:05"), Action: e.Action,
|
CreatedAt: e.CreatedAt.Format("02.01.2006 15:04:05"), Action: e.Action,
|
||||||
|
|||||||
@@ -40,6 +40,28 @@ func TestAdminDashboardAccessibleForAdmin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestNavShowsAdminLinkOnlyForAdmins deckt genau den gemeldeten Fall ab:
|
||||||
|
// nach der Anmeldung als Admin landet man auf der normalen Startseite
|
||||||
|
// (jeder Nutzer hat einen Account+Login, auch ein Admin) — ohne einen
|
||||||
|
// sichtbaren Weg zu /admin wäre der Admin-Bereich für einen Admin, der
|
||||||
|
// die URL nicht auswendig kennt, praktisch unerreichbar.
|
||||||
|
func TestNavShowsAdminLinkOnlyForAdmins(t *testing.T) {
|
||||||
|
fs := newFakeStore()
|
||||||
|
s := newServer(t, fakeExtractor{}, fs)
|
||||||
|
adminCookie := seedAccountWithRole(t, fs, "Deklarix Admin", "admin@example.com", "admin")
|
||||||
|
tenantCookie := seedAccount(t, fs, "Mandant", "mandant@example.com")
|
||||||
|
|
||||||
|
adminResp := getWithCookie(t, s, adminCookie, "/")
|
||||||
|
if !strings.Contains(adminResp.Body.String(), `href="/admin"`) {
|
||||||
|
t.Errorf("expected an /admin nav link for an admin user, got: %s", adminResp.Body.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
tenantResp := getWithCookie(t, s, tenantCookie, "/")
|
||||||
|
if strings.Contains(tenantResp.Body.String(), `href="/admin"`) {
|
||||||
|
t.Errorf("expected no /admin nav link for a non-admin user, got: %s", tenantResp.Body.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestAdminAccountListShowsAllAccountsAcrossTenants(t *testing.T) {
|
func TestAdminAccountListShowsAllAccountsAcrossTenants(t *testing.T) {
|
||||||
fs := newFakeStore()
|
fs := newFakeStore()
|
||||||
s := newServer(t, fakeExtractor{}, fs)
|
s := newServer(t, fakeExtractor{}, fs)
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ type submissionListItem struct {
|
|||||||
|
|
||||||
type submissionListData struct {
|
type submissionListData struct {
|
||||||
Title string
|
Title string
|
||||||
|
Nav navData
|
||||||
Submissions []submissionListItem
|
Submissions []submissionListItem
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,7 +32,7 @@ func (s *Server) handleSubmissionList(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data := submissionListData{Title: "Beiträge"}
|
data := submissionListData{Title: "Beiträge", Nav: navFor(r)}
|
||||||
for _, sum := range summaries {
|
for _, sum := range summaries {
|
||||||
data.Submissions = append(data.Submissions, submissionListItem{
|
data.Submissions = append(data.Submissions, submissionListItem{
|
||||||
ID: sum.ID, Platform: sum.Platform, PostType: sum.PostType, Status: sum.Status,
|
ID: sum.ID, Platform: sum.Platform, PostType: sum.PostType, Status: sum.Status,
|
||||||
@@ -56,6 +57,7 @@ type participantView struct {
|
|||||||
|
|
||||||
type submissionDetailData struct {
|
type submissionDetailData struct {
|
||||||
Title string
|
Title string
|
||||||
|
Nav navData
|
||||||
SubmissionID string
|
SubmissionID string
|
||||||
Platform string
|
Platform string
|
||||||
PostType string
|
PostType string
|
||||||
@@ -125,7 +127,7 @@ func (s *Server) handleSubmissionDetail(w http.ResponseWriter, r *http.Request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
data := submissionDetailData{
|
data := submissionDetailData{
|
||||||
Title: "Beitrag", SubmissionID: sub.ID, Platform: sub.Platform, PostType: sub.PostType,
|
Title: "Beitrag", Nav: navFor(r), SubmissionID: sub.ID, Platform: sub.Platform, PostType: sub.PostType,
|
||||||
Caption: sub.Caption, Status: sub.Status, CreatedAt: sub.CreatedAt.Format("02.01.2006 15:04"),
|
Caption: sub.Caption, Status: sub.Status, CreatedAt: sub.CreatedAt.Format("02.01.2006 15:04"),
|
||||||
CanArchive: sub.Status == "checked", IsPublished: sub.Status == "published",
|
CanArchive: sub.Status == "checked", IsPublished: sub.Status == "published",
|
||||||
DossierURL: "/dossier/" + sub.ID, Findings: findings, Participants: toParticipantViews(participants),
|
DossierURL: "/dossier/" + sub.ID, Findings: findings, Participants: toParticipantViews(participants),
|
||||||
|
|||||||
@@ -21,10 +21,12 @@ func (s *Server) handleHealth(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
type indexData struct {
|
type indexData struct {
|
||||||
Title string
|
Title string
|
||||||
|
Nav navData
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) handleIndex(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) handleIndex(w http.ResponseWriter, r *http.Request) {
|
||||||
if err := s.templates.ExecuteTemplate(w, "index", indexData{Title: "Pre-Publish-Prüfung"}); err != nil {
|
data := indexData{Title: "Pre-Publish-Prüfung", Nav: navFor(r)}
|
||||||
|
if err := s.templates.ExecuteTemplate(w, "index", data); err != nil {
|
||||||
http.Error(w, "Seite konnte nicht gerendert werden", http.StatusInternalServerError)
|
http.Error(w, "Seite konnte nicht gerendert werden", http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,6 +88,21 @@ func (s *Server) requireAdmin(next http.HandlerFunc) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// navData steuert die gemeinsame Navigation (layout.html, "nav"-Block).
|
||||||
|
// Eigenes, kleines Struct statt jeder Seite Zugriff auf den vollen
|
||||||
|
// currentUser zu geben — die Navigation braucht nur, ob ein Admin-Link
|
||||||
|
// gezeigt werden soll.
|
||||||
|
type navData struct {
|
||||||
|
IsAdmin bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// navFor liefert die Nav-Daten für den angemeldeten Nutzer der Anfrage.
|
||||||
|
// Nur für Seiten hinter requirePage/requireAdmin aufrufbar (braucht
|
||||||
|
// currentUser).
|
||||||
|
func navFor(r *http.Request) navData {
|
||||||
|
return navData{IsAdmin: currentUser(r).Role == "admin"}
|
||||||
|
}
|
||||||
|
|
||||||
// currentUser liest den Nutzer, den requirePage/requireAPI in den
|
// currentUser liest den Nutzer, den requirePage/requireAPI in den
|
||||||
// Kontext gelegt haben. Panics, wenn es aufgerufen wird, ohne dass eine
|
// Kontext gelegt haben. Panics, wenn es aufgerufen wird, ohne dass eine
|
||||||
// dieser Middlewares vorgeschaltet war — das ist ein Programmierfehler,
|
// dieser Middlewares vorgeschaltet war — das ist ein Programmierfehler,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<html lang="de">
|
<html lang="de">
|
||||||
<head>{{template "head" .}}</head>
|
<head>{{template "head" .}}</head>
|
||||||
<body>
|
<body>
|
||||||
{{template "nav" .}}
|
{{template "nav" .Nav}}
|
||||||
<div class="page">
|
<div class="page">
|
||||||
<p><a href="/admin/accounts">← Alle Accounts</a></p>
|
<p><a href="/admin/accounts">← Alle Accounts</a></p>
|
||||||
<h1>{{.Name}}</h1>
|
<h1>{{.Name}}</h1>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<html lang="de">
|
<html lang="de">
|
||||||
<head>{{template "head" .}}</head>
|
<head>{{template "head" .}}</head>
|
||||||
<body>
|
<body>
|
||||||
{{template "nav" .}}
|
{{template "nav" .Nav}}
|
||||||
<div class="page">
|
<div class="page">
|
||||||
<p><a href="/admin">← Admin</a></p>
|
<p><a href="/admin">← Admin</a></p>
|
||||||
<h1>Accounts</h1>
|
<h1>Accounts</h1>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<html lang="de">
|
<html lang="de">
|
||||||
<head>{{template "head" .}}</head>
|
<head>{{template "head" .}}</head>
|
||||||
<body>
|
<body>
|
||||||
{{template "nav" .}}
|
{{template "nav" .Nav}}
|
||||||
<div class="page">
|
<div class="page">
|
||||||
<p><a href="/admin">← Admin</a></p>
|
<p><a href="/admin">← Admin</a></p>
|
||||||
<h1>Audit-Log</h1>
|
<h1>Audit-Log</h1>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<html lang="de">
|
<html lang="de">
|
||||||
<head>{{template "head" .}}</head>
|
<head>{{template "head" .}}</head>
|
||||||
<body>
|
<body>
|
||||||
{{template "nav" .}}
|
{{template "nav" .Nav}}
|
||||||
<div class="page">
|
<div class="page">
|
||||||
<h1>Admin</h1>
|
<h1>Admin</h1>
|
||||||
<ul class="admin-kacheln">
|
<ul class="admin-kacheln">
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<html lang="de">
|
<html lang="de">
|
||||||
<head>{{template "head" .}}</head>
|
<head>{{template "head" .}}</head>
|
||||||
<body>
|
<body>
|
||||||
{{template "nav" .}}
|
{{template "nav" .Nav}}
|
||||||
<div class="page">
|
<div class="page">
|
||||||
<h1>Beiträge</h1>
|
<h1>Beiträge</h1>
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<html lang="de">
|
<html lang="de">
|
||||||
<head>{{template "head" .}}</head>
|
<head>{{template "head" .}}</head>
|
||||||
<body>
|
<body>
|
||||||
{{template "nav" .}}
|
{{template "nav" .Nav}}
|
||||||
<div class="page">
|
<div class="page">
|
||||||
<p><a href="/beitraege">← Alle Beiträge</a></p>
|
<p><a href="/beitraege">← Alle Beiträge</a></p>
|
||||||
<h1>{{.Platform}} · {{.PostType}}</h1>
|
<h1>{{.Platform}} · {{.PostType}}</h1>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<html lang="de">
|
<html lang="de">
|
||||||
<head>{{template "head" .}}</head>
|
<head>{{template "head" .}}</head>
|
||||||
<body>
|
<body>
|
||||||
{{template "nav" .}}
|
{{template "nav" .Nav}}
|
||||||
<div class="page">
|
<div class="page">
|
||||||
<h1>Pre-Publish-Prüfung</h1>
|
<h1>Pre-Publish-Prüfung</h1>
|
||||||
<p>Caption und Plattform eingeben, um auf Kennzeichnungsrisiken zu prüfen.</p>
|
<p>Caption und Plattform eingeben, um auf Kennzeichnungsrisiken zu prüfen.</p>
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
<nav>
|
<nav>
|
||||||
<a href="/">Prüfen</a>
|
<a href="/">Prüfen</a>
|
||||||
<a href="/beitraege">Beiträge</a>
|
<a href="/beitraege">Beiträge</a>
|
||||||
|
{{if .IsAdmin}}<a href="/admin">Admin</a>{{end}}
|
||||||
<form method="post" action="/logout" style="display:inline">
|
<form method="post" action="/logout" style="display:inline">
|
||||||
<button type="submit">Abmelden</button>
|
<button type="submit">Abmelden</button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
Reference in New Issue
Block a user