Browse Source

Prevent panic in stopwatch (#10670) (#10673)

Signed-off-by: Andrew Thornton <art27@cantab.net>
tags/v1.11.3
zeripath 4 years ago
parent
commit
66b31786d3
No account linked to committer's email address
1 changed files with 5 additions and 2 deletions
  1. 5
    2
      routers/api/v1/repo/issue_stopwatch.go

+ 5
- 2
routers/api/v1/repo/issue_stopwatch.go View File

package repo package repo


import ( import (
"errors"
"net/http" "net/http"


"code.gitea.io/gitea/models" "code.gitea.io/gitea/models"


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
} }

Loading…
Cancel
Save