权限整改:完成项目审计日志读取隔离
完成项目审计日志读取权限隔离、路由调整、测试及整改清单进度同步。
This commit is contained in:
1 parent
1bc823d8de
commit
408bd5f8ab
10 files changed
+225
-3
No files matched your search
@@ -12,6 +12,7 @@ import (
|
||||
func (s *Server) registerProjectResourceRoutes() {
|
||||
api := s.router.Group("/api/v1", privateProjectResponse, s.requireAuthenticated)
|
||||
api.GET("/domains", s.listDomains)
|
||||
api.GET("/audit-logs", s.listAuditLogs)
|
||||
api.GET("/servers", s.listServers)
|
||||
api.GET("/servers/:id", s.getServer)
|
||||
api.GET("/domains/:id/servers", s.listDomainServers)
|
||||
|
||||
@@ -217,7 +217,7 @@ func (s *Server) registerRoutes() {
|
||||
adminAPI.GET("/tasks/:id", s.getTask)
|
||||
adminAPI.DELETE("/tasks/:id", s.cancelTask)
|
||||
adminAPI.GET("/tasks/:id/attempts", s.listTaskAttempts)
|
||||
adminAPI.GET("/audit-logs", s.listAuditLogs)
|
||||
|
||||
adminAPI.GET("/settings", s.getSettings)
|
||||
adminAPI.PUT("/settings", s.updateSettings)
|
||||
adminAPI.GET("/dns/providers", s.listAdminDNSProviders)
|
||||
|
||||
@@ -302,13 +302,16 @@ func (s *Server) listTaskAttempts(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (s *Server) listAuditLogs(c *gin.Context) {
|
||||
reader, ok := s.audit.(repository.AuditReader)
|
||||
if !s.requireProjectResourceReader(c) {
|
||||
return
|
||||
}
|
||||
reader, ok := s.projectResources.(repository.ProjectAuditReader)
|
||||
if !ok {
|
||||
s.writeError(c, http.StatusNotImplemented, "审计日志查询接口尚未配置", errors.New("审计日志读取服务未配置"))
|
||||
return
|
||||
}
|
||||
limit, _ := strconv.Atoi(c.DefaultQuery("limit", "50"))
|
||||
items, err := reader.ListAuditLogs(c.Request.Context(), limit)
|
||||
items, err := reader.ListVisibleAuditLogs(c.Request.Context(), c.GetString(authenticatedActorKey), limit)
|
||||
if err != nil {
|
||||
s.writeError(c, http.StatusInternalServerError, "查询审计日志失败", err)
|
||||
return
|
||||
|
||||
@@ -28,6 +28,11 @@ func newTaskAPITestServer(t *testing.T, issue func(context.Context, string) (cer
|
||||
db.Close()
|
||||
t.Fatalf("迁移测试数据库失败:%v", err)
|
||||
}
|
||||
if _, err := db.DB.ExecContext(context.Background(), repository.Rebind(cfg.Database.Driver, `INSERT INTO users
|
||||
(id, username, password_hash, role, status) VALUES ('test-admin', 'test-admin', 'test-only-no-login', 'admin', 'active')`)); err != nil {
|
||||
db.Close()
|
||||
t.Fatalf("创建测试管理员失败:%v", err)
|
||||
}
|
||||
domainRepo := repository.NewSQLDomainRepository(db.DB)
|
||||
taskRepo := repository.NewSQLTaskRepository(db.DB)
|
||||
auditRepo := repository.NewSQLAuditRepository(db.DB)
|
||||
@@ -47,6 +52,7 @@ func newTaskAPITestServer(t *testing.T, issue func(context.Context, string) (cer
|
||||
IssueCertificate: issue,
|
||||
Tasks: taskRepo,
|
||||
Audit: auditRepo,
|
||||
ProjectResources: repository.NewSQLProjectMemberRepository(db.DB, cfg.Database.Driver),
|
||||
Users: repository.NewSQLUserRepository(db.DB, cfg.Database.Driver),
|
||||
})
|
||||
return server, taskRepo, auditRepo, func() { _ = db.Close() }
|
||||
|
||||
Reference in new issue
Block a user