Fix getUserWebDAVClient to use actual username and COALESCE for NULL handling

This commit is contained in:
Leon Bösche
2026-01-10 23:16:02 +01:00
parent 18600a6bc1
commit 4a4e03e041
2 changed files with 5 additions and 5 deletions

Binary file not shown.

View File

@@ -32,22 +32,22 @@ import (
// getUserWebDAVClient gets or creates a user's Nextcloud account and returns a WebDAV client for them
func getUserWebDAVClient(ctx context.Context, db *database.DB, userID uuid.UUID, nextcloudBaseURL, adminUser, adminPass string) (*storage.WebDAVClient, error) {
var user struct {
Username string
NextcloudUsername string
NextcloudPassword string
Email string
}
err := db.QueryRowContext(ctx,
"SELECT nextcloud_username, nextcloud_password, email FROM users WHERE id = $1",
userID).Scan(&user.NextcloudUsername, &user.NextcloudPassword, &user.Email)
"SELECT username, COALESCE(nextcloud_username, ''), COALESCE(nextcloud_password, '') FROM users WHERE id = $1",
userID).Scan(&user.Username, &user.NextcloudUsername, &user.NextcloudPassword)
if err != nil {
return nil, fmt.Errorf("failed to get user: %w", err)
}
// If user doesn't have Nextcloud credentials, create them
if user.NextcloudUsername == "" || user.NextcloudPassword == "" {
// Use email prefix as username
ncUsername := strings.Split(user.Email, "@")[0]
// Use the actual username from the users table
ncUsername := user.Username
ncPassword, err := storage.GenerateSecurePassword(32)
if err != nil {
return nil, fmt.Errorf("failed to generate password: %w", err)