From 020944d4a0d22d709c4e360b28ecd6e529e37091 Mon Sep 17 00:00:00 2001 From: OpenClaw Agent Date: Thu, 17 Sep 2026 06:47:34 +0800 Subject: [PATCH] fix: unify WebDAV upload behavior across roles --- user_webdav.go | 48 +++++++++++------------------------------------- 1 file changed, 11 insertions(+), 37 deletions(-) diff --git a/user_webdav.go b/user_webdav.go index 921ae64..b1fcb61 100644 --- a/user_webdav.go +++ b/user_webdav.go @@ -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 { - 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 + + // 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 = ? 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 a.db.Where("user_id = ?", user.ID).First(&cfg).Error == nil && cfg.RootPath != "" { + return a.storage, cfg.RootPath, 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 + return a.storage, a.cfg.WebDAVPath, true }