From cb0b5d2a395f09cded7bfcbd24510f0c20f81cfc Mon Sep 17 00:00:00 2001 From: Aaron Liu Date: Thu, 12 Mar 2026 16:07:57 +0800 Subject: [PATCH] fix(dashboard): cannot delete user with OAuth grants (close #3354) --- assets | 2 +- inventory/user.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/assets b/assets index a5ade069..194c0c3f 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit a5ade06951d6e3dd9168ba303cfd250d41ceffb9 +Subproject commit 194c0c3f227e9a49a475d3436acf356ed6ac97f7 diff --git a/inventory/user.go b/inventory/user.go index 569c579d..bb0391fe 100644 --- a/inventory/user.go +++ b/inventory/user.go @@ -16,6 +16,7 @@ import ( "github.com/cloudreve/Cloudreve/v4/ent" "github.com/cloudreve/Cloudreve/v4/ent/davaccount" "github.com/cloudreve/Cloudreve/v4/ent/file" + "github.com/cloudreve/Cloudreve/v4/ent/oauthgrant" "github.com/cloudreve/Cloudreve/v4/ent/passkey" "github.com/cloudreve/Cloudreve/v4/ent/schema" "github.com/cloudreve/Cloudreve/v4/ent/task" @@ -214,6 +215,11 @@ func (c *userClient) Delete(ctx context.Context, uid int) error { return fmt.Errorf("failed to delete tasks: %w", err) } + // OAuth grants + if _, err := c.client.OAuthGrant.Delete().Where(oauthgrant.UserID(uid)).Exec(schema.SkipSoftDelete(ctx)); err != nil { + return fmt.Errorf("failed to delete oauth grants: %w", err) + } + return c.client.User.DeleteOneID(uid).Exec(schema.SkipSoftDelete(ctx)) }