fix: unify WebDAV upload behavior across roles

This commit is contained in:
OpenClaw Agent
2026-09-17 06:47:34 +08:00
parent 40d99e1e22
commit 020944d4a0
+6 -32
View File
@@ -112,46 +112,20 @@ func (a *App) storageForTask(t *Task) (RemoteStorage, string, bool) {
if a.db.First(&user, t.UserID).Error != nil {
return nil, "", false
}
if user.Role != RoleAdmin && !a.hasPermission(user.ID, PermWebDAV) {
if !a.hasPermission(user.ID, PermWebDAV) && user.Role != RoleAdmin {
return nil, "", false
}
// Regular users use the system/global WebDAV only. They cannot override
// the destination; privileged users may have their own WebDAV config.
if user.Role == RoleUser {
// All users share the same global WebDAV connection by default. Each user
// gets an isolated destination directory, so upload/retry behavior is
// identical for admin, privileged, and regular users.
if a.cfg.WebDAVURL == "" || a.storage == nil {
return nil, "", false
}
var cfg WebDAVConfig
if a.db.Where("user_id = ?", user.ID).First(&cfg).Error == nil && cfg.RootPath != "" {
return a.storage, cfg.RootPath, true
}
return a.storage, a.cfg.WebDAVPath, true
}
if user.Role == RoleAdmin {
if a.cfg.WebDAVURL == "" || a.storage == nil {
return nil, "", false
}
return a.storage, a.cfg.WebDAVPath, true
}
var cfg WebDAVConfig
if a.db.Where("user_id = ? AND enabled = ?", user.ID, true).First(&cfg).Error != nil {
// Privileged users fall back to the global WebDAV until a custom
// WebDAV configuration is enabled.
if a.cfg.WebDAVURL == "" || a.storage == nil {
return nil, "", false
}
return a.storage, a.cfg.WebDAVPath, true
}
if cfg.URL == "" {
// An empty URL means this user inherits the global WebDAV connection,
// while keeping the user's own destination path.
if a.cfg.WebDAVURL == "" || a.storage == nil {
return nil, "", false
}
if cfg.RootPath != "" {
return a.storage, cfg.RootPath, true
}
return a.storage, a.cfg.WebDAVPath, true
}
return NewWebDAVStorage(Config{WebDAVURL: cfg.URL, WebDAVUser: cfg.Username, WebDAVPass: cfg.Password}), cfg.RootPath, true
}