mirror of
https://github.com/go-gitea/gitea
synced 2024-11-01 03:39:28 +01:00
65861900cd
* Replace all ctx.Handle with ctx.ServerError or ctx.NotFound * Change Handle(403) to NotFound, avoid using macaron's NotFound
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package repo
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"code.gitea.io/gitea/models"
|
|
"code.gitea.io/gitea/modules/context"
|
|
)
|
|
|
|
// IssueStopwatch creates or stops a stopwatch for the given issue.
|
|
func IssueStopwatch(c *context.Context) {
|
|
issue := GetActionIssue(c)
|
|
if c.Written() {
|
|
return
|
|
}
|
|
if !c.Repo.CanUseTimetracker(issue, c.User) {
|
|
c.NotFound("CanUseTimetracker", nil)
|
|
return
|
|
}
|
|
|
|
if err := models.CreateOrStopIssueStopwatch(c.User, issue); err != nil {
|
|
c.ServerError("CreateOrStopIssueStopwatch", err)
|
|
return
|
|
}
|
|
|
|
url := issue.HTMLURL()
|
|
c.Redirect(url, http.StatusSeeOther)
|
|
}
|
|
|
|
// CancelStopwatch cancel the stopwatch
|
|
func CancelStopwatch(c *context.Context) {
|
|
issue := GetActionIssue(c)
|
|
if c.Written() {
|
|
return
|
|
}
|
|
if !c.Repo.CanUseTimetracker(issue, c.User) {
|
|
c.NotFound("CanUseTimetracker", nil)
|
|
return
|
|
}
|
|
|
|
if err := models.CancelStopwatch(c.User, issue); err != nil {
|
|
c.ServerError("CancelStopwatch", err)
|
|
return
|
|
}
|
|
|
|
url := issue.HTMLURL()
|
|
c.Redirect(url, http.StatusSeeOther)
|
|
}
|