@@ -107,17 +107,21 @@ func GetUserOrgsList(ctx context.Context, user *user_model.User) ([]*MinimalOrg,
107107 OrgID int64
108108 RepoCount int
109109 }
110- // FIXME: This doesn't counting those public repos in the organization that the user has access to
111110 var orgCounts []orgCount
112111 if err := db .GetEngine (ctx ).
113- Select ("team.org_id, COUNT(DISTINCT(team_repo.repo_id)) as repo_count" ).
114- Table ("team" ).
115- Join ("INNER" , "team_repo" , "team_repo.team_id = team.id" ).
116- Where (builder .In ("`team`.`id`" ,
117- builder .Select ("team_id" ).From ("team_user" ).
118- Where (builder.Eq {"uid" : user .ID }),
112+ Select ("owner_id AS org_id, COUNT(DISTINCT(repository.id)) as repo_count" ).
113+ Table ("repository" ).
114+ Join ("INNER" , "org_user" , "owner_id = org_user.org_id" ).
115+ Where ("org_user.uid = ?" , user .ID ).
116+ And (builder .Or (
117+ builder.Eq {"repository.is_private" : false },
118+ builder .In ("repository.id" , builder .Select ("repo_id" ).From ("team_repo" ).
119+ InnerJoin ("team_user" , "team_user.team_id = team_repo.team_id" ).
120+ Where (builder.Eq {"team_user.uid" : user .ID })),
121+ builder .In ("repository.id" , builder .Select ("repo_id" ).From ("collaboration" ).
122+ Where (builder.Eq {"user_id" : user .ID })),
119123 )).
120- GroupBy ("team.org_id " ).Find (& orgCounts ); err != nil {
124+ GroupBy ("owner_id " ).Find (& orgCounts ); err != nil {
121125 return nil , err
122126 }
123127
0 commit comments