Fix NPE /repos/issues/search when not signed in (#19154) (#19155)

- Backport #19154

  - Don't panic when on `/repos/issues/search?{created,assigned,mentioned,review_requested}=true` when client didn't pass any authentication.
  - Resolves #19115
This commit is contained in:
Gusted 2022-03-20 21:42:31 +00:00 committed by GitHub
parent a3f3e310fb
commit ee234aff61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -245,18 +245,23 @@ func SearchIssues(ctx *context.APIContext) {
UpdatedAfterUnix: since, 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 // Filter for: Created by User, Assigned to User, Mentioning User, Review of User Requested
if ctx.FormBool("created") { if ctx.FormBool("created") {
issuesOpt.PosterID = ctx.User.ID issuesOpt.PosterID = ctxUserID
} }
if ctx.FormBool("assigned") { if ctx.FormBool("assigned") {
issuesOpt.AssigneeID = ctx.User.ID issuesOpt.AssigneeID = ctxUserID
} }
if ctx.FormBool("mentioned") { if ctx.FormBool("mentioned") {
issuesOpt.MentionedID = ctx.User.ID issuesOpt.MentionedID = ctxUserID
} }
if ctx.FormBool("review_requested") { if ctx.FormBool("review_requested") {
issuesOpt.ReviewRequestedID = ctx.User.ID issuesOpt.ReviewRequestedID = ctxUserID
} }
if issues, err = models.Issues(issuesOpt); err != nil { if issues, err = models.Issues(issuesOpt); err != nil {
@ -599,7 +604,7 @@ func CreateIssue(ctx *context.APIContext) {
DeadlineUnix: deadlineUnix, DeadlineUnix: deadlineUnix,
} }
var assigneeIDs = make([]int64, 0) assigneeIDs := make([]int64, 0)
var err error var err error
if ctx.Repo.CanWrite(unit.TypeIssues) { if ctx.Repo.CanWrite(unit.TypeIssues) {
issue.MilestoneID = form.Milestone issue.MilestoneID = form.Milestone