From e72d94129c4666d5151f6131cb2f8c1de127d9d0 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 7 Nov 2019 18:56:50 +0100 Subject: [PATCH] keep sure if assigneeIDs == nil -> do nothing --- routers/api/v1/repo/issue.go | 32 +++++++++++++++++--------------- routers/api/v1/repo/pull.go | 33 ++++++++++++++++++--------------- 2 files changed, 35 insertions(+), 30 deletions(-) diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index 186e66cb8f..2df9811802 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -344,22 +344,24 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) { return } - // Check if the passed assignees is assignable - for _, aID := range assigneeIDs { - assignee, err := models.GetUserByID(aID) - if err != nil { - ctx.Error(500, "GetUserByID", err) - return - } + if assigneeIDs != nil { + for _, aID := range assigneeIDs { + assignee, err := models.GetUserByID(aID) + if err != nil { + ctx.Error(500, "GetUserByID", err) + return + } - valid, err := models.CanBeAssigned(assignee, ctx.Repo.Repository, false) - if err != nil { - ctx.Error(500, "canBeAssigned", err) - return - } - if !valid { - ctx.Error(422, "canBeAssigned", models.ErrUserDoesNotHaveAccessToRepo{UserID: aID, RepoName: ctx.Repo.Repository.Name}) - return + // Check if the passed assignees is assignable + valid, err := models.CanBeAssigned(assignee, ctx.Repo.Repository, false) + if err != nil { + ctx.Error(500, "canBeAssigned", err) + return + } + if !valid { + ctx.Error(422, "canBeAssigned", models.ErrUserDoesNotHaveAccessToRepo{UserID: aID, RepoName: ctx.Repo.Repository.Name}) + return + } } } } else { diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 6d86105a15..1e1eb2ceaf 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -286,22 +286,25 @@ func CreatePullRequest(ctx *context.APIContext, form api.CreatePullRequestOption } return } - // Check if the passed assignees is assignable - for _, aID := range assigneeIDs { - assignee, err := models.GetUserByID(aID) - if err != nil { - ctx.Error(500, "GetUserByID", err) - return - } - valid, err := models.CanBeAssigned(assignee, repo, true) - if err != nil { - ctx.Error(500, "canBeAssigned", err) - return - } - if !valid { - ctx.Error(422, "canBeAssigned", models.ErrUserDoesNotHaveAccessToRepo{UserID: aID, RepoName: repo.Name}) - return + if assigneeIDs != nil { + for _, aID := range assigneeIDs { + assignee, err := models.GetUserByID(aID) + if err != nil { + ctx.Error(500, "GetUserByID", err) + return + } + + // Check if the passed assignees is assignable + valid, err := models.CanBeAssigned(assignee, repo, true) + if err != nil { + ctx.Error(500, "canBeAssigned", err) + return + } + if !valid { + ctx.Error(422, "canBeAssigned", models.ErrUserDoesNotHaveAccessToRepo{UserID: aID, RepoName: repo.Name}) + return + } } }