Skip to content

Commit

Permalink
Prevent multiple listings of organization when creating a repository (g…
Browse files Browse the repository at this point in the history
…o-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>
  • Loading branch information
2 people authored and Yohann Delafollye committed Jul 31, 2020
1 parent 2192c56 commit f808426
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions models/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit f808426

Please sign in to comment.