From 2d756783035ed9dab4286349cd801b878f5c1aa6 Mon Sep 17 00:00:00 2001 From: Otto Richter Date: Sat, 23 Nov 2024 19:59:25 +0100 Subject: [PATCH] fix: Do not delete global Oauth2 applications (cherry picked from commit 1d5aee6ef80bf6a864a1a9caf4a0f2d7c55ea498) --- models/auth/oauth2.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/models/auth/oauth2.go b/models/auth/oauth2.go index 83d60e3abe..3c9a7ee2e7 100644 --- a/models/auth/oauth2.go +++ b/models/auth/oauth2.go @@ -651,6 +651,7 @@ func CountOrphanedOAuth2Applications(ctx context.Context) (int64, error) { Table("`oauth2_application`"). Join("LEFT", "`user`", "`oauth2_application`.`uid` = `user`.`id`"). Where(builder.IsNull{"`user`.id"}). + Where(builder.Neq{"uid": 0}). // exclude instance-wide admin applications Where(builder.NotIn("`oauth2_application`.`client_id`", BuiltinApplicationsClientIDs())). Select("COUNT(`oauth2_application`.`id`)"). Count() @@ -662,6 +663,7 @@ func DeleteOrphanedOAuth2Applications(ctx context.Context) (int64, error) { From("`oauth2_application`"). Join("LEFT", "`user`", "`oauth2_application`.`uid` = `user`.`id`"). Where(builder.IsNull{"`user`.id"}). + Where(builder.Neq{"uid": 0}). // exclude instance-wide admin applications Where(builder.NotIn("`oauth2_application`.`client_id`", BuiltinApplicationsClientIDs())) b := builder.Delete(builder.In("id", subQuery)).From("`oauth2_application`")