fix(tenant): 收紧双站运营提号与录单边界

This commit is contained in:
yml
2026-11-16 16:12:55 +08:00
parent 1108df195d
commit 1ce9f7aaf5
60 changed files with 1531 additions and 337 deletions
+23 -5
View File
@@ -27,8 +27,8 @@ type ObjectAuthorizer func(ctx context.Context, userID uint64, key string) (bool
// AdminObjectAuthorizer 校验管理员是否可在当前经营站点读取指定私有对象。
type AdminObjectAuthorizer func(ctx context.Context, adminID uint64, key string) (bool, error)
// UploadOwnerRecorder 保存用户上传私有文件的归属。
type UploadOwnerRecorder func(ctx context.Context, userID uint64, objectKeys []string) error
// UploadOwnerRecorder 保存用户或管理员上传私有文件的归属。
type UploadOwnerRecorder func(ctx context.Context, userID, adminID uint64, objectKeys []string) error
func NewHandler(service *Service, storage *Storage, objectAuthorizer ObjectAuthorizer, uploadOwnerRecorder UploadOwnerRecorder, adminObjectAuthorizers ...AdminObjectAuthorizer) *Handler {
var adminObjectAuthorizer AdminObjectAuthorizer
@@ -69,9 +69,27 @@ func (h *Handler) Upload(c *gin.Context) {
writeFileError(c, err)
return
}
if userID, ok := c.Get("user_id"); ok && h.uploadOwnerRecorder != nil {
id, valid := userID.(uint64)
if !valid || h.uploadOwnerRecorder(c.Request.Context(), id, item.ObjectKeys()) != nil {
if h.uploadOwnerRecorder != nil {
var userID uint64
if value, exists := c.Get("user_id"); exists {
id, ok := value.(uint64)
if !ok {
response.Unauthorized(c, "用户上下文无效")
return
}
userID = id
}
var adminID uint64
if value, exists := c.Get("admin_id"); exists {
id, ok := value.(uint64)
if !ok {
response.Unauthorized(c, "管理员上下文无效")
return
}
adminID = id
}
if (userID > 0 || adminID > 0) &&
h.uploadOwnerRecorder(c.Request.Context(), userID, adminID, item.ObjectKeys()) != nil {
// 归属记录失败时补偿删除刚写入的对象,避免用户重试产生孤儿文件。
if h.storage != nil {
if removeErr := h.storage.RemoveObjects(c.Request.Context(), item.ObjectKeys()); removeErr != nil {