1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-11-29 09:31:11 -05:00

Prevent panic in stopwatch (#10670)

Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
zeripath 2020-03-08 17:46:24 +00:00 committed by GitHub
parent 1966f421b3
commit 33c5e5e7fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,6 +5,7 @@
package repo package repo
import ( import (
"errors"
"net/http" "net/http"
"code.gitea.io/gitea/models" "code.gitea.io/gitea/models"
@ -173,19 +174,21 @@ func prepareIssueStopwatch(ctx *context.APIContext, shouldExist bool) (*models.I
if !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) { if !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) {
ctx.Status(http.StatusForbidden) ctx.Status(http.StatusForbidden)
return nil, err return nil, errors.New("Unable to write to PRs")
} }
if !ctx.Repo.CanUseTimetracker(issue, ctx.User) { if !ctx.Repo.CanUseTimetracker(issue, ctx.User) {
ctx.Status(http.StatusForbidden) ctx.Status(http.StatusForbidden)
return nil, err return nil, errors.New("Cannot use time tracker")
} }
if models.StopwatchExists(ctx.User.ID, issue.ID) != shouldExist { if models.StopwatchExists(ctx.User.ID, issue.ID) != shouldExist {
if shouldExist { if shouldExist {
ctx.Error(http.StatusConflict, "StopwatchExists", "cannot stop/cancel a non existent stopwatch") ctx.Error(http.StatusConflict, "StopwatchExists", "cannot stop/cancel a non existent stopwatch")
err = errors.New("cannot stop/cancel a non existent stopwatch")
} else { } else {
ctx.Error(http.StatusConflict, "StopwatchExists", "cannot start a stopwatch again if it already exists") ctx.Error(http.StatusConflict, "StopwatchExists", "cannot start a stopwatch again if it already exists")
err = errors.New("cannot start a stopwatch again if it already exists")
} }
return nil, err return nil, err
} }