mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-23 14:53:34 +01:00
Merge pull request '[v7.0/forgejo] fix: Do not delete global Oauth2 applications' (#6056) from bp-v7.0/forgejo-665d5f7-1d5aee6 into v7.0/forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6056 Reviewed-by: Otto <otto@codeberg.org> Reviewed-by: Gusted <gusted@noreply.codeberg.org>
This commit is contained in:
commit
f93a7a93a3
3 changed files with 11 additions and 0 deletions
|
@ -23,3 +23,11 @@
|
||||||
redirect_uris: '["http://127.0.0.1", "https://127.0.0.1"]'
|
redirect_uris: '["http://127.0.0.1", "https://127.0.0.1"]'
|
||||||
created_unix: 1712358091
|
created_unix: 1712358091
|
||||||
updated_unix: 1712358091
|
updated_unix: 1712358091
|
||||||
|
-
|
||||||
|
id: 1003
|
||||||
|
uid: 0
|
||||||
|
name: "Global Auth source that should be kept"
|
||||||
|
client_id: "2f3467c1-7b3b-463d-ab04-2ae2b2712826"
|
||||||
|
redirect_uris: '["http://example.com/globalapp", "https://example.com/globalapp"]'
|
||||||
|
created_unix: 1732387292
|
||||||
|
updated_unix: 1732387292
|
||||||
|
|
|
@ -651,6 +651,7 @@ func CountOrphanedOAuth2Applications(ctx context.Context) (int64, error) {
|
||||||
Table("`oauth2_application`").
|
Table("`oauth2_application`").
|
||||||
Join("LEFT", "`user`", "`oauth2_application`.`uid` = `user`.`id`").
|
Join("LEFT", "`user`", "`oauth2_application`.`uid` = `user`.`id`").
|
||||||
Where(builder.IsNull{"`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())).
|
Where(builder.NotIn("`oauth2_application`.`client_id`", BuiltinApplicationsClientIDs())).
|
||||||
Select("COUNT(`oauth2_application`.`id`)").
|
Select("COUNT(`oauth2_application`.`id`)").
|
||||||
Count()
|
Count()
|
||||||
|
@ -662,6 +663,7 @@ func DeleteOrphanedOAuth2Applications(ctx context.Context) (int64, error) {
|
||||||
From("`oauth2_application`").
|
From("`oauth2_application`").
|
||||||
Join("LEFT", "`user`", "`oauth2_application`.`uid` = `user`.`id`").
|
Join("LEFT", "`user`", "`oauth2_application`.`uid` = `user`.`id`").
|
||||||
Where(builder.IsNull{"`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()))
|
Where(builder.NotIn("`oauth2_application`.`client_id`", BuiltinApplicationsClientIDs()))
|
||||||
|
|
||||||
b := builder.Delete(builder.In("id", subQuery)).From("`oauth2_application`")
|
b := builder.Delete(builder.In("id", subQuery)).From("`oauth2_application`")
|
||||||
|
|
|
@ -296,4 +296,5 @@ func TestOrphanedOAuth2Applications(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.EqualValues(t, 0, count)
|
assert.EqualValues(t, 0, count)
|
||||||
unittest.AssertExistsIf(t, false, &auth_model.OAuth2Application{ID: 1002})
|
unittest.AssertExistsIf(t, false, &auth_model.OAuth2Application{ID: 1002})
|
||||||
|
unittest.AssertExistsIf(t, true, &auth_model.OAuth2Application{ID: 1003})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue