Feature user and admin panels (#30)

This commit is contained in:
2026-02-16 20:30:36 +00:00
parent c5866ae785
commit 2fc4f6980c
15 changed files with 1805 additions and 111 deletions

View File

@@ -57,6 +57,8 @@ func TestAllRoutesRegistered(t *testing.T) {
msgs := handlers.NewMessageHandler()
comp := handlers.NewCompletionHandler()
apiCfg := handlers.NewAPIConfigHandler()
settings := handlers.NewSettingsHandler()
adm := handlers.NewAdminHandler()
r := gin.New()
api := r.Group("/api/v1")
@@ -94,6 +96,28 @@ func TestAllRoutesRegistered(t *testing.T) {
protected.DELETE("/api-configs/:id", apiCfg.DeleteConfig)
protected.GET("/api-configs/:id/models", apiCfg.ListModels)
protected.GET("/models", apiCfg.ListAllModels)
// User Settings & Profile
protected.GET("/profile", settings.GetProfile)
protected.PUT("/profile", settings.UpdateProfile)
protected.POST("/profile/password", settings.ChangePassword)
protected.GET("/settings", settings.GetSettings)
protected.PUT("/settings", settings.UpdateSettings)
}
// Admin routes
admin := api.Group("/admin")
{
admin.GET("/users", adm.ListUsers)
admin.POST("/users", adm.CreateUser)
admin.PUT("/users/:id/role", adm.UpdateUserRole)
admin.PUT("/users/:id/active", adm.ToggleUserActive)
admin.POST("/users/:id/reset-password", adm.ResetPassword)
admin.DELETE("/users/:id", adm.DeleteUser)
admin.GET("/settings", adm.ListGlobalSettings)
admin.GET("/settings/:key", adm.GetGlobalSetting)
admin.PUT("/settings/:key", adm.UpdateGlobalSetting)
admin.GET("/stats", adm.GetStats)
}
routes := r.Routes()
@@ -129,6 +153,23 @@ func TestAllRoutesRegistered(t *testing.T) {
"GET /api/v1/api-configs/:id/models",
// Models
"GET /api/v1/models",
// Profile & Settings
"GET /api/v1/profile",
"PUT /api/v1/profile",
"POST /api/v1/profile/password",
"GET /api/v1/settings",
"PUT /api/v1/settings",
// Admin
"GET /api/v1/admin/users",
"POST /api/v1/admin/users",
"PUT /api/v1/admin/users/:id/role",
"PUT /api/v1/admin/users/:id/active",
"POST /api/v1/admin/users/:id/reset-password",
"DELETE /api/v1/admin/users/:id",
"GET /api/v1/admin/settings",
"GET /api/v1/admin/settings/:key",
"PUT /api/v1/admin/settings/:key",
"GET /api/v1/admin/stats",
}
for _, e := range expected {
@@ -192,19 +233,6 @@ func TestAnthropicStaticModels(t *testing.T) {
}
}
func TestStubHandler(t *testing.T) {
r := gin.New()
r.GET("/test", stubHandler("settings"))
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/test", nil)
r.ServeHTTP(w, req)
if w.Code != 501 {
t.Errorf("Expected 501, got %d", w.Code)
}
}
func TestAuthMiddlewareNoDatabase(t *testing.T) {
cfg := &config.Config{JWTSecret: "test"}
r := gin.New()