Skip to content

Commit f808426

Browse files
6543zeripath
authored andcommitted
Prevent multiple listings of organization when creating a repository (go-gitea#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 go-gitea#11258 Co-authored-by: zeripath <art27@cantab.net>
1 parent 2192c56 commit f808426

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

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)