Skip to content
3 changes: 2 additions & 1 deletion models/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -1552,6 +1552,7 @@ const (
FilterModeCreate
FilterModeMention
FilterModeReviewRequested
FilterModeYourRepositories
)

func parseCountResult(results []map[string][]byte) int64 {
Expand Down Expand Up @@ -1734,7 +1735,7 @@ func GetUserIssueStats(opts UserIssueStatsOptions) (*IssueStats, error) {
}

switch opts.FilterMode {
case FilterModeAll:
case FilterModeAll, FilterModeYourRepositories:
stats.OpenCount, err = sess(cond).
And("issue.is_closed = ?", false).
Count(new(Issue))
Expand Down
48 changes: 46 additions & 2 deletions routers/web/user/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
var (
viewType string
sortType = ctx.FormString("sort")
filterMode = models.FilterModeAll
filterMode int
)

// --------------------------------------------------------------------------------
Expand All @@ -389,8 +389,10 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
filterMode = models.FilterModeMention
case "review_requested":
filterMode = models.FilterModeReviewRequested
case "your_repositories": // filterMode already set to All
case "your_repositories":
fallthrough
default:
filterMode = models.FilterModeYourRepositories
viewType = "your_repositories"
}

Expand Down Expand Up @@ -420,6 +422,36 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
User: ctx.User,
}

// Search all repositories which
//
// As user:
// - Owns the repository.
// - Have collaborator permissions in repository.
//
// As org:
// - Owns the repository.
//
// As team:
// - Team org's owns the repository.
// - Team has read permission to repository.
repoOpts := &models.SearchRepoOptions{
Actor: ctx.User,
OwnerID: ctx.User.ID,
Private: true,
AllPublic: false,
AllLimited: false,
}

if ctxUser.IsOrganization() && ctx.Org.Team != nil {
repoOpts.TeamID = ctx.Org.Team.ID
}

userRepoIDs, _, err := models.SearchRepositoryIDs(repoOpts)
if err != nil {
ctx.ServerError("models.SearchRepositoryIDs: %v", err)
return
}

switch filterMode {
case models.FilterModeAll:
case models.FilterModeAssign:
Expand All @@ -430,6 +462,13 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
opts.MentionedID = ctx.User.ID
case models.FilterModeReviewRequested:
opts.ReviewRequestedID = ctx.User.ID
case models.FilterModeYourRepositories:
if ctxUser.IsOrganization() && ctx.Org.Team != nil {
// Fixes a issue whereby the user's ID would be used
// to check if it's in the team(which possible isn't the case).
opts.User = nil
}
opts.RepoIDs = userRepoIDs
}

// keyword holds the search term entered into the search field.
Expand Down Expand Up @@ -553,6 +592,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
statsOpts := models.UserIssueStatsOptions{
UserID: ctx.User.ID,
FilterMode: filterMode,
RepoIDs: userRepoIDs,
IsPull: isPullList,
IsClosed: isShowClosed,
IssueIDs: issueIDsFromSearch,
Expand All @@ -564,6 +604,10 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
if len(repoIDs) > 0 {
statsOpts.RepoIDs = repoIDs
}
// Detect when we only should search by team.
if opts.User == nil {
statsOpts.UserID = 0
}
issueStats, err = models.GetUserIssueStats(statsOpts)
if err != nil {
ctx.ServerError("GetUserIssueStats Shown", err)
Expand Down