1
0
Fork 0

Prevent multiple listings of organization when creating a repository (#11303)

prevent double entries in results of GetOrgsCanCreateRepoByUserID

I first try to only add GroupBy directly but xorm return broken user objects ...

... solution was to just query related UserIDs(OrgIDs) first and return OrgUsers based on this IDs

close #11258

Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
6543 2020-05-07 15:24:59 +02:00 committed by GitHub
parent a6b8de282c
commit 507d0ec57a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -473,12 +473,12 @@ func GetOwnedOrgsByUserIDDesc(userID int64, desc string) ([]*User, error) {
func GetOrgsCanCreateRepoByUserID(userID int64) ([]*User, error) { func GetOrgsCanCreateRepoByUserID(userID int64) ([]*User, error) {
orgs := make([]*User, 0, 10) orgs := make([]*User, 0, 10)
return orgs, x.Join("INNER", "`team_user`", "`team_user`.org_id=`user`.id"). return orgs, x.Where(builder.In("id", builder.Select("`user`.id").From("`user`").
Join("INNER", "`team_user`", "`team_user`.org_id = `user`.id").
Join("INNER", "`team`", "`team`.id = `team_user`.team_id"). Join("INNER", "`team`", "`team`.id = `team_user`.team_id").
Where("`team_user`.uid=?", userID). Where(builder.Eq{"`team_user`.uid": userID}).
And(builder.Eq{"`team`.authorize": AccessModeOwner}.Or(builder.Eq{"`team`.can_create_org_repo": true})). And(builder.Eq{"`team`.authorize": AccessModeOwner}.Or(builder.Eq{"`team`.can_create_org_repo": true})))).
Desc("`user`.updated_unix"). Desc("`user`.updated_unix").Find(&orgs)
Find(&orgs)
} }
// GetOrgUsersByUserID returns all organization-user relations by user ID. // GetOrgUsersByUserID returns all organization-user relations by user ID.