Skip to content

Commit 38acce2

Browse files
author
Gusted
authored
Fix issue overview for teams (#19652) (#19653)
- Backport #19652 - Don't use hacky solution to limit to the correct RepoID's, instead use current code to handle these limits. The existing code is more correct than the hacky solution. - Resolves #19636
1 parent 8f44d00 commit 38acce2

File tree

5 files changed

+24
-25
lines changed

5 files changed

+24
-25
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ require (
102102
gopkg.in/yaml.v2 v2.4.0
103103
mvdan.cc/xurls/v2 v2.2.0
104104
strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251
105-
xorm.io/builder v0.3.9
105+
xorm.io/builder v0.3.10
106106
xorm.io/xorm v1.2.5
107107
)
108108

go.sum

+2-1
Original file line numberDiff line numberDiff line change
@@ -2336,7 +2336,8 @@ sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
23362336
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=
23372337
strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251 h1:mUcz5b3FJbP5Cvdq7Khzn6J9OCUQJaBwgBkCR+MOwSs=
23382338
strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251/go.mod h1:FJGmPh3vz9jSos1L/F91iAgnC/aejc0wIIrF2ZwJxdY=
2339-
xorm.io/builder v0.3.9 h1:Sd65/LdWyO7LR8+Cbd+e7mm3sK/7U9k0jS3999IDHMc=
23402339
xorm.io/builder v0.3.9/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE=
2340+
xorm.io/builder v0.3.10 h1:Rvkncad3Lo9YIVqCbgIf6QnpR/HcW3IEr0AANNpuyMQ=
2341+
xorm.io/builder v0.3.10/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE=
23412342
xorm.io/xorm v1.2.5 h1:tqN7OhN8P9xi52qBb76I8m5maAJMz/SSbgK2RGPCPbo=
23422343
xorm.io/xorm v1.2.5/go.mod h1:fTG8tSjk6O1BYxwuohZUK+S1glnRycsCF05L1qQyEU0=

models/issue.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -1346,9 +1346,7 @@ func (opts *IssuesOptions) setupSessionNoLimit(sess *xorm.Session) {
13461346
}
13471347

13481348
if opts.User != nil {
1349-
sess.And(
1350-
issuePullAccessibleRepoCond("issue.repo_id", opts.User.ID, opts.Org, opts.Team, opts.IsPull.IsTrue()),
1351-
)
1349+
sess.And(issuePullAccessibleRepoCond("issue.repo_id", opts.User.ID, opts.Org, opts.Team, opts.IsPull.IsTrue()))
13521350
}
13531351
}
13541352

@@ -1413,7 +1411,6 @@ func CountIssuesByRepo(opts *IssuesOptions) (map[int64]int64, error) {
14131411
e := db.GetEngine(db.DefaultContext)
14141412

14151413
sess := e.Join("INNER", "repository", "`issue`.repo_id = `repository`.id")
1416-
14171414
opts.setupSessionNoLimit(sess)
14181415

14191416
countsSlice := make([]*struct {
@@ -1440,7 +1437,6 @@ func GetRepoIDsForIssuesOptions(opts *IssuesOptions, user *user_model.User) ([]i
14401437
e := db.GetEngine(db.DefaultContext)
14411438

14421439
sess := e.Join("INNER", "repository", "`issue`.repo_id = `repository`.id")
1443-
14441440
opts.setupSessionNoLimit(sess)
14451441

14461442
accessCond := accessibleRepositoryCondition(user)
@@ -1485,6 +1481,7 @@ func CountIssues(opts *IssuesOptions) (int64, error) {
14851481
sess := e.Select("COUNT(issue.id) AS count").Table("issue")
14861482
sess.Join("INNER", "repository", "`issue`.repo_id = `repository`.id")
14871483
opts.setupSessionNoLimit(sess)
1484+
14881485
if err := sess.Find(&countsSlice); err != nil {
14891486
return 0, fmt.Errorf("unable to CountIssues: %w", err)
14901487
}

models/repo_list.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,28 @@ func teamUnitsRepoCond(id string, userID, orgID, teamID int64, units ...unit.Typ
233233
builder.Select("repo_id").From("team_repo").Where(
234234
builder.Eq{
235235
"team_id": teamID,
236-
}.And(
236+
}.And(builder.Or(
237+
// Check if the user is member of the team.
237238
builder.In(
238239
"team_id", builder.Select("team_id").From("team_user").Where(
239240
builder.Eq{
240241
"uid": userID,
241242
},
242243
),
243-
)).And(
244+
),
245+
// Check if the user is in the owner team of the organisation.
246+
builder.Exists(builder.Select("team_id").From("team_user").
247+
Where(builder.Eq{
248+
"org_id": orgID,
249+
"team_id": builder.Select("id").From("team").Where(
250+
builder.Eq{
251+
"org_id": orgID,
252+
"lower_name": strings.ToLower(ownerTeamName),
253+
}),
254+
"uid": userID,
255+
}),
256+
),
257+
)).And(
244258
builder.In(
245259
"team_id", builder.Select("team_id").From("team_unit").Where(
246260
builder.Eq{

routers/web/user/home.go

+3-16
Original file line numberDiff line numberDiff line change
@@ -442,12 +442,13 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
442442
AllLimited: false,
443443
}
444444

445-
if ctxUser.IsOrganization() && ctx.Org.Team != nil {
446-
repoOpts.TeamID = ctx.Org.Team.ID
445+
if team != nil {
446+
repoOpts.TeamID = team.ID
447447
}
448448

449449
switch filterMode {
450450
case models.FilterModeAll:
451+
case models.FilterModeYourRepositories:
451452
case models.FilterModeAssign:
452453
opts.AssigneeID = ctx.User.ID
453454
case models.FilterModeCreate:
@@ -456,13 +457,6 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
456457
opts.MentionedID = ctx.User.ID
457458
case models.FilterModeReviewRequested:
458459
opts.ReviewRequestedID = ctx.User.ID
459-
case models.FilterModeYourRepositories:
460-
if ctxUser.IsOrganization() && ctx.Org.Team != nil {
461-
// Fixes a issue whereby the user's ID would be used
462-
// to check if it's in the team(which possible isn't the case).
463-
opts.User = nil
464-
}
465-
opts.RepoCond = models.SearchRepositoryCondition(repoOpts)
466460
}
467461

468462
// keyword holds the search term entered into the search field.
@@ -594,13 +588,6 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
594588
Org: org,
595589
Team: team,
596590
}
597-
if filterMode == models.FilterModeYourRepositories {
598-
statsOpts.RepoCond = models.SearchRepositoryCondition(repoOpts)
599-
}
600-
// Detect when we only should search by team.
601-
if opts.User == nil {
602-
statsOpts.UserID = 0
603-
}
604591
issueStats, err = models.GetUserIssueStats(statsOpts)
605592
if err != nil {
606593
ctx.ServerError("GetUserIssueStats Shown", err)

0 commit comments

Comments
 (0)