Skip to content

Commit cd7fa15

Browse files
6543zeripath
andauthored
Prevent multiple listings of organization when creating a repository (go-gitea#11303) (go-gitea#11325)
Backport go-gitea#11303 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 <[email protected]>
1 parent 79868d7 commit cd7fa15

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
@@ -470,12 +470,12 @@ func GetOwnedOrgsByUserIDDesc(userID int64, desc string) ([]*User, error) {
470470
func GetOrgsCanCreateRepoByUserID(userID int64) ([]*User, error) {
471471
orgs := make([]*User, 0, 10)
472472

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

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

0 commit comments

Comments
 (0)