Scert/backend/internal/httpapi/resource_scope.go
xuans 7284958819 完善域名服务器项目归属与数据库关联约束
保存资源项目、所有者和操作人,接口从会话记录归属,普通更新保留创建信息。
新增三库第十一版迁移、同项目绑定约束和 SQLite 触发器保护,补充迁移回滚重试、仓储、接口及备份恢复测试。
本次整理验证:后端构建、静态检查、关联改造针对性测试和 CLI 包测试通过。
范围说明:项目成员权限及其他资源归属尚未完成;本次未重新执行外部数据库实库、独立程序及生产部署验收。
2026-09-28 10:45:00 +08:00

26 lines
768 B
Go

package httpapi
import (
"git.pcux.cn/xuans/Scert/backend/internal/domain"
"github.com/gin-gonic/gin"
)
// 归属由服务端会话填写,不能从请求体接受操作者或项目授权声明。
func (s *Server) newResourceScope(c *gin.Context) domain.ResourceScope {
scope := domain.ResourceScope{ProjectID: domain.DefaultProjectID}
if session, ok := s.currentAuthSession(c); ok {
scope.OwnerID = session.UserID
scope.CreatedBy = session.UserID
scope.UpdatedBy = session.UserID
}
return scope
}
func (s *Server) updatedResourceScope(c *gin.Context, existing domain.ResourceScope) domain.ResourceScope {
existing.UpdatedBy = ""
if session, ok := s.currentAuthSession(c); ok {
existing.UpdatedBy = session.UserID
}
return existing.Normalize()
}