Skip to content

Commit

Permalink
Fix NPE /repos/issues/search when not signed in (#19154)
Browse files Browse the repository at this point in the history
- Don't panic when on
`/repos/issues/search?{created,assigned,mentioned,review_requested}=true`
when client didn't pass any authentication.
- Resolves #19115
  • Loading branch information
Gusted authored Mar 20, 2022
1 parent 83a2f79 commit 49c5fc5
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions routers/api/v1/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,18 +245,23 @@ func SearchIssues(ctx *context.APIContext) {
UpdatedAfterUnix: since,
}

ctxUserID := int64(0)
if ctx.IsSigned {
ctxUserID = ctx.User.ID
}

// Filter for: Created by User, Assigned to User, Mentioning User, Review of User Requested
if ctx.FormBool("created") {
issuesOpt.PosterID = ctx.User.ID
issuesOpt.PosterID = ctxUserID
}
if ctx.FormBool("assigned") {
issuesOpt.AssigneeID = ctx.User.ID
issuesOpt.AssigneeID = ctxUserID
}
if ctx.FormBool("mentioned") {
issuesOpt.MentionedID = ctx.User.ID
issuesOpt.MentionedID = ctxUserID
}
if ctx.FormBool("review_requested") {
issuesOpt.ReviewRequestedID = ctx.User.ID
issuesOpt.ReviewRequestedID = ctxUserID
}

if issues, err = models.Issues(issuesOpt); err != nil {
Expand Down

0 comments on commit 49c5fc5

Please sign in to comment.