Skip to content

Commit a5f2894

Browse files
author
Gusted
authored
Fix showing issues in your repositories (#18916)
- Make a restriction on which issues can be shown based on if you the user or team has write permission to the repository. - Fixes a issue whereby you wouldn't see any associated issues with a specific team on a organization if you wasn't a member(fixed by zeroing the User{ID} in the options). - Resolves #18913
1 parent f7883a6 commit a5f2894

File tree

2 files changed

+53
-5
lines changed

2 files changed

+53
-5
lines changed

models/issue.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -1603,6 +1603,7 @@ const (
16031603
FilterModeCreate
16041604
FilterModeMention
16051605
FilterModeReviewRequested
1606+
FilterModeYourRepositories
16061607
)
16071608

16081609
func parseCountResult(results []map[string][]byte) int64 {
@@ -1747,6 +1748,7 @@ type UserIssueStatsOptions struct {
17471748
IssueIDs []int64
17481749
IsArchived util.OptionalBool
17491750
LabelIDs []int64
1751+
RepoCond builder.Cond
17501752
Org *Organization
17511753
Team *Team
17521754
}
@@ -1764,6 +1766,9 @@ func GetUserIssueStats(opts UserIssueStatsOptions) (*IssueStats, error) {
17641766
if len(opts.IssueIDs) > 0 {
17651767
cond = cond.And(builder.In("issue.id", opts.IssueIDs))
17661768
}
1769+
if opts.RepoCond != nil {
1770+
cond = cond.And(opts.RepoCond)
1771+
}
17671772

17681773
if opts.UserID > 0 {
17691774
cond = cond.And(issuePullAccessibleRepoCond("issue.repo_id", opts.UserID, opts.Org, opts.Team, opts.IsPull))
@@ -1785,7 +1790,7 @@ func GetUserIssueStats(opts UserIssueStatsOptions) (*IssueStats, error) {
17851790
}
17861791

17871792
switch opts.FilterMode {
1788-
case FilterModeAll:
1793+
case FilterModeAll, FilterModeYourRepositories:
17891794
stats.OpenCount, err = sess(cond).
17901795
And("issue.is_closed = ?", false).
17911796
Count(new(Issue))

routers/web/user/home.go

+47-4
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
362362
var (
363363
viewType string
364364
sortType = ctx.FormString("sort")
365-
filterMode = models.FilterModeAll
365+
filterMode int
366366
)
367367

368368
// --------------------------------------------------------------------------------
@@ -388,8 +388,10 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
388388
filterMode = models.FilterModeMention
389389
case "review_requested":
390390
filterMode = models.FilterModeReviewRequested
391-
case "your_repositories": // filterMode already set to All
391+
case "your_repositories":
392+
fallthrough
392393
default:
394+
filterMode = models.FilterModeYourRepositories
393395
viewType = "your_repositories"
394396
}
395397

@@ -419,6 +421,30 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
419421
User: ctx.Doer,
420422
}
421423

424+
// Search all repositories which
425+
//
426+
// As user:
427+
// - Owns the repository.
428+
// - Have collaborator permissions in repository.
429+
//
430+
// As org:
431+
// - Owns the repository.
432+
//
433+
// As team:
434+
// - Team org's owns the repository.
435+
// - Team has read permission to repository.
436+
repoOpts := &models.SearchRepoOptions{
437+
Actor: ctx.Doer,
438+
OwnerID: ctx.Doer.ID,
439+
Private: true,
440+
AllPublic: false,
441+
AllLimited: false,
442+
}
443+
444+
if ctxUser.IsOrganization() && ctx.Org.Team != nil {
445+
repoOpts.TeamID = ctx.Org.Team.ID
446+
}
447+
422448
switch filterMode {
423449
case models.FilterModeAll:
424450
case models.FilterModeAssign:
@@ -429,6 +455,19 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
429455
opts.MentionedID = ctx.Doer.ID
430456
case models.FilterModeReviewRequested:
431457
opts.ReviewRequestedID = ctx.Doer.ID
458+
case models.FilterModeYourRepositories:
459+
if ctxUser.IsOrganization() && ctx.Org.Team != nil {
460+
// Fixes a issue whereby the user's ID would be used
461+
// to check if it's in the team(which possible isn't the case).
462+
opts.User = nil
463+
}
464+
userRepoIDs, _, err := models.SearchRepositoryIDs(repoOpts)
465+
if err != nil {
466+
ctx.ServerError("models.SearchRepositoryIDs: %v", err)
467+
return
468+
}
469+
470+
opts.RepoIDs = userRepoIDs
432471
}
433472

434473
// keyword holds the search term entered into the search field.
@@ -560,8 +599,12 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
560599
Org: org,
561600
Team: team,
562601
}
563-
if len(repoIDs) > 0 {
564-
statsOpts.RepoIDs = repoIDs
602+
if filterMode == models.FilterModeYourRepositories {
603+
statsOpts.RepoCond = models.SearchRepositoryCondition(repoOpts)
604+
}
605+
// Detect when we only should search by team.
606+
if opts.User == nil {
607+
statsOpts.UserID = 0
565608
}
566609
issueStats, err = models.GetUserIssueStats(statsOpts)
567610
if err != nil {

0 commit comments

Comments
 (0)