Skip to content

Commit 1a152ad

Browse files
committed
Fix bug
1 parent 1ed9934 commit 1a152ad

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

models/organization/org_list.go

+12-8
Original file line numberDiff line numberDiff line change
@@ -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

models/organization/org_list_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func TestGetUserOrgsList(t *testing.T) {
5656
assert.NoError(t, err)
5757
if assert.Len(t, orgs, 1) {
5858
assert.EqualValues(t, 3, orgs[0].ID)
59-
assert.EqualValues(t, 3, orgs[0].NumRepos)
59+
// repo_id: 3 is in the team, 32 is public, 5 is private with no team
60+
assert.EqualValues(t, 2, orgs[0].NumRepos)
6061
}
6162
}

0 commit comments

Comments
 (0)