Reimplement GetUserOrgsList to make it simple and clear (#32486)

Reimplement GetUserOrgsList and also move some functions and test to
org_list file.

---------

Co-authored-by: Zettat123 <zettat123@gmail.com>
This commit is contained in:
Lunny Xiao 2024-11-13 21:31:47 -08:00 committed by GitHub
parent 3f9c3e7bc3
commit b4abb6deff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 205 additions and 172 deletions

View file

@ -8,6 +8,7 @@ import (
"fmt"
auth "code.gitea.io/gitea/models/auth"
"code.gitea.io/gitea/models/db"
org_model "code.gitea.io/gitea/models/organization"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/log"
@ -192,7 +193,10 @@ func NewAccessTokenResponse(ctx context.Context, grant *auth.OAuth2Grant, server
// returns a list of "org" and "org:team" strings,
// that the given user is a part of.
func GetOAuthGroupsForUser(ctx context.Context, user *user_model.User) ([]string, error) {
orgs, err := org_model.GetUserOrgsList(ctx, user)
orgs, err := db.Find[org_model.Organization](ctx, org_model.FindOrgOptions{
UserID: user.ID,
IncludePrivate: true,
})
if err != nil {
return nil, fmt.Errorf("GetUserOrgList: %w", err)
}