Adminbereich mit Rollen und Nutzerauswertung ergänzen

Admin-API serverseitig absichern, Kennzahlen und paginierte Nutzersuche bereitstellen, Weboberfläche ergänzen und Einrichtung sowie spätere Kauf-Funktionen dokumentieren.
This commit is contained in:
Eugenius Naumenko
2026-10-10 18:45:52 +00:00
parent 82d8768a99
commit e432943ea7
14 changed files with 634 additions and 18 deletions
+17
View File
@@ -125,6 +125,23 @@ func (s *Server) requireAuth(next http.Handler) http.Handler {
})
}
// Admin rights are read from PostgreSQL for every request. A previously
// issued token does not preserve privileges after an account is demoted.
func (s *Server) requireAdmin(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
user, err := s.store.GetUser(r.Context(), currentUserID(r))
if err != nil {
writeError(w, http.StatusInternalServerError, err)
return
}
if user.Role != "admin" {
writeError(w, http.StatusForbidden, nil)
return
}
next.ServeHTTP(w, r)
})
}
func currentUserID(r *http.Request) string {
value, _ := r.Context().Value(userIDKey).(string)
return value