Skip to content

Commit faf98ca

Browse files
author
Gusted
committed
Fix showing issues in your repositories
- 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 organisation if you wasn't a member(fixed by zeroing the User{ID} in the options). - Resolves go-gitea#18913
1 parent 5b0cdd6 commit faf98ca

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

models/issue.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,6 +1552,7 @@ const (
15521552
FilterModeCreate
15531553
FilterModeMention
15541554
FilterModeReviewRequested
1555+
FilterModeYourRepositories
15551556
)
15561557

15571558
func parseCountResult(results []map[string][]byte) int64 {
@@ -1735,6 +1736,7 @@ func GetUserIssueStats(opts UserIssueStatsOptions) (*IssueStats, error) {
17351736

17361737
switch opts.FilterMode {
17371738
case FilterModeAll:
1739+
case FilterModeYourRepositories:
17381740
stats.OpenCount, err = sess(cond).
17391741
And("issue.is_closed = ?", false).
17401742
Count(new(Issue))

routers/web/user/home.go

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,10 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
389389
filterMode = models.FilterModeMention
390390
case "review_requested":
391391
filterMode = models.FilterModeReviewRequested
392-
case "your_repositories": // filterMode already set to All
392+
case "your_repositories":
393+
fallthrough
393394
default:
395+
filterMode = models.FilterModeYourRepositories
394396
viewType = "your_repositories"
395397
}
396398

@@ -420,6 +422,26 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
420422
User: ctx.User,
421423
}
422424

425+
// Search all repositories which the given user or team
426+
// has write permissions.
427+
repoOpts := &models.SearchRepoOptions{
428+
Actor: ctx.User,
429+
OwnerID: ctx.User.ID,
430+
Private: true,
431+
AllPublic: false,
432+
AllLimited: false,
433+
}
434+
435+
if ctxUser.IsOrganization() && ctx.Org.Team != nil {
436+
repoOpts.TeamID = ctx.Org.Team.ID
437+
}
438+
439+
userRepoIDs, _, err := models.SearchRepositoryIDs(repoOpts)
440+
if err != nil {
441+
ctx.ServerError("models.SearchRepositoryIDs: %v", err)
442+
return
443+
}
444+
423445
switch filterMode {
424446
case models.FilterModeAll:
425447
case models.FilterModeAssign:
@@ -430,6 +452,13 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
430452
opts.MentionedID = ctx.User.ID
431453
case models.FilterModeReviewRequested:
432454
opts.ReviewRequestedID = ctx.User.ID
455+
case models.FilterModeYourRepositories:
456+
if ctxUser.IsOrganization() && ctx.Org.Team != nil {
457+
// Fixes a issue whereby the user's ID would be used
458+
// to check if it's in the team(which possible isn't the case).
459+
opts.User = nil
460+
}
461+
opts.RepoIDs = userRepoIDs
433462
}
434463

435464
// keyword holds the search term entered into the search field.
@@ -553,6 +582,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
553582
statsOpts := models.UserIssueStatsOptions{
554583
UserID: ctx.User.ID,
555584
FilterMode: filterMode,
585+
RepoIDs: userRepoIDs,
556586
IsPull: isPullList,
557587
IsClosed: isShowClosed,
558588
IssueIDs: issueIDsFromSearch,
@@ -564,6 +594,10 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
564594
if len(repoIDs) > 0 {
565595
statsOpts.RepoIDs = repoIDs
566596
}
597+
// Detect when we only should search by team.
598+
if opts.User == nil {
599+
statsOpts.UserID = 0
600+
}
567601
issueStats, err = models.GetUserIssueStats(statsOpts)
568602
if err != nil {
569603
ctx.ServerError("GetUserIssueStats Shown", err)

0 commit comments

Comments
 (0)