From 0c7e44fcf7dbfa14287c0fd9903b09f614dcc9e3 Mon Sep 17 00:00:00 2001 From: Giteabot Date: Wed, 11 Dec 2024 09:22:03 +0800 Subject: [PATCH] Fix internal server error when updating labels without write permission (#32776) (#32785) --- routers/api/v1/repo/issue_label.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/routers/api/v1/repo/issue_label.go b/routers/api/v1/repo/issue_label.go index 413693c5ed..9516f52591 100644 --- a/routers/api/v1/repo/issue_label.go +++ b/routers/api/v1/repo/issue_label.go @@ -319,6 +319,11 @@ func prepareForReplaceOrAdd(ctx *context.APIContext, form api.IssueLabelsOption) return nil, nil, err } + if !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) { + ctx.Error(http.StatusForbidden, "CanWriteIssuesOrPulls", "write permission is required") + return nil, nil, fmt.Errorf("permission denied") + } + var ( labelIDs []int64 labelNames []string @@ -350,10 +355,5 @@ func prepareForReplaceOrAdd(ctx *context.APIContext, form api.IssueLabelsOption) return nil, nil, err } - if !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) { - ctx.Status(http.StatusForbidden) - return nil, nil, nil - } - return issue, labels, err }