From 507d0ec57aaf02a60a3de8aca3e635616b592fc5 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 7 May 2020 15:24:59 +0200 Subject: [PATCH] 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 --- models/org.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/models/org.go b/models/org.go index 4961db2ac..58afc5cb5 100644 --- a/models/org.go +++ b/models/org.go @@ -473,12 +473,12 @@ func GetOwnedOrgsByUserIDDesc(userID int64, desc string) ([]*User, error) { func GetOrgsCanCreateRepoByUserID(userID int64) ([]*User, error) { orgs := make([]*User, 0, 10) - return orgs, x.Join("INNER", "`team_user`", "`team_user`.org_id=`user`.id"). - Join("INNER", "`team`", "`team`.id=`team_user`.team_id"). - Where("`team_user`.uid=?", userID). - And(builder.Eq{"`team`.authorize": AccessModeOwner}.Or(builder.Eq{"`team`.can_create_org_repo": true})). - Desc("`user`.updated_unix"). - Find(&orgs) + 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"). + Where(builder.Eq{"`team_user`.uid": userID}). + And(builder.Eq{"`team`.authorize": AccessModeOwner}.Or(builder.Eq{"`team`.can_create_org_repo": true})))). + Desc("`user`.updated_unix").Find(&orgs) } // GetOrgUsersByUserID returns all organization-user relations by user ID.