Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix showing issues in your repositories #18916

Merged
merged 14 commits into from
Mar 23, 2022
7 changes: 6 additions & 1 deletion models/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,7 @@ const (
FilterModeCreate
FilterModeMention
FilterModeReviewRequested
FilterModeYourRepositories
)

func parseCountResult(results []map[string][]byte) int64 {
Expand Down Expand Up @@ -1747,6 +1748,7 @@ type UserIssueStatsOptions struct {
IssueIDs []int64
IsArchived util.OptionalBool
LabelIDs []int64
RepoCond builder.Cond
Org *Organization
Team *Team
}
Expand All @@ -1764,6 +1766,9 @@ func GetUserIssueStats(opts UserIssueStatsOptions) (*IssueStats, error) {
if len(opts.IssueIDs) > 0 {
cond = cond.And(builder.In("issue.id", opts.IssueIDs))
}
if opts.RepoCond != nil {
cond = cond.And(opts.RepoCond)
}

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

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

// --------------------------------------------------------------------------------
Expand All @@ -388,8 +388,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 @@ -419,6 +421,30 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
User: ctx.Doer,
}

// 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.Doer,
OwnerID: ctx.Doer.ID,
Private: true,
AllPublic: false,
AllLimited: false,
}

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

switch filterMode {
case models.FilterModeAll:
case models.FilterModeAssign:
Expand All @@ -429,6 +455,19 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
opts.MentionedID = ctx.Doer.ID
case models.FilterModeReviewRequested:
opts.ReviewRequestedID = ctx.Doer.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
}
userRepoIDs, _, err := models.SearchRepositoryIDs(repoOpts)
lunny marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
ctx.ServerError("models.SearchRepositoryIDs: %v", err)
return
}

opts.RepoIDs = userRepoIDs
}

// keyword holds the search term entered into the search field.
Expand Down Expand Up @@ -560,8 +599,12 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
Org: org,
Team: team,
}
if len(repoIDs) > 0 {
statsOpts.RepoIDs = repoIDs
if filterMode == models.FilterModeYourRepositories {
statsOpts.RepoCond = models.SearchRepositoryCondition(repoOpts)
}
// Detect when we only should search by team.
if opts.User == nil {
statsOpts.UserID = 0
}
issueStats, err = models.GetUserIssueStats(statsOpts)
if err != nil {
Expand Down