Skip to content

Commit 507d0ec

Browse files
6543zeripath
andauthored
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 <[email protected]>
1 parent a6b8de2 commit 507d0ec

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

models/org.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -473,12 +473,12 @@ func GetOwnedOrgsByUserIDDesc(userID int64, desc string) ([]*User, error) {
473473
func GetOrgsCanCreateRepoByUserID(userID int64) ([]*User, error) {
474474
orgs := make([]*User, 0, 10)
475475

476-
return orgs, x.Join("INNER", "`team_user`", "`team_user`.org_id=`user`.id").
477-
Join("INNER", "`team`", "`team`.id=`team_user`.team_id").
478-
Where("`team_user`.uid=?", userID).
479-
And(builder.Eq{"`team`.authorize": AccessModeOwner}.Or(builder.Eq{"`team`.can_create_org_repo": true})).
480-
Desc("`user`.updated_unix").
481-
Find(&orgs)
476+
return orgs, x.Where(builder.In("id", builder.Select("`user`.id").From("`user`").
477+
Join("INNER", "`team_user`", "`team_user`.org_id = `user`.id").
478+
Join("INNER", "`team`", "`team`.id = `team_user`.team_id").
479+
Where(builder.Eq{"`team_user`.uid": userID}).
480+
And(builder.Eq{"`team`.authorize": AccessModeOwner}.Or(builder.Eq{"`team`.can_create_org_repo": true})))).
481+
Desc("`user`.updated_unix").Find(&orgs)
482482
}
483483

484484
// GetOrgUsersByUserID returns all organization-user relations by user ID.

0 commit comments

Comments
 (0)