2017-09-12 12:18:13 +05:30
|
|
|
// 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) {
|
2017-10-16 13:25:43 +05:30
|
|
|
issue := GetActionIssue(c)
|
|
|
|
if c.Written() {
|
|
|
|
return
|
|
|
|
}
|
2019-02-05 17:08:11 +05:30
|
|
|
|
|
|
|
var showSuccessMessage bool
|
|
|
|
|
|
|
|
if !models.StopwatchExists(c.User.ID, issue.ID) {
|
|
|
|
showSuccessMessage = true
|
|
|
|
}
|
|
|
|
|
2017-10-16 13:25:43 +05:30
|
|
|
if !c.Repo.CanUseTimetracker(issue, c.User) {
|
2018-01-11 03:04:17 +05:30
|
|
|
c.NotFound("CanUseTimetracker", nil)
|
2017-09-12 12:18:13 +05:30
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := models.CreateOrStopIssueStopwatch(c.User, issue); err != nil {
|
2018-01-11 03:04:17 +05:30
|
|
|
c.ServerError("CreateOrStopIssueStopwatch", err)
|
2017-09-12 12:18:13 +05:30
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-02-05 17:08:11 +05:30
|
|
|
if showSuccessMessage {
|
|
|
|
c.Flash.Success(c.Tr("repo.issues.tracker_auto_close"))
|
|
|
|
}
|
|
|
|
|
2017-09-12 12:18:13 +05:30
|
|
|
url := issue.HTMLURL()
|
|
|
|
c.Redirect(url, http.StatusSeeOther)
|
|
|
|
}
|
|
|
|
|
|
|
|
// CancelStopwatch cancel the stopwatch
|
|
|
|
func CancelStopwatch(c *context.Context) {
|
2017-10-16 13:25:43 +05:30
|
|
|
issue := GetActionIssue(c)
|
|
|
|
if c.Written() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if !c.Repo.CanUseTimetracker(issue, c.User) {
|
2018-01-11 03:04:17 +05:30
|
|
|
c.NotFound("CanUseTimetracker", nil)
|
2017-09-12 12:18:13 +05:30
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := models.CancelStopwatch(c.User, issue); err != nil {
|
2018-01-11 03:04:17 +05:30
|
|
|
c.ServerError("CancelStopwatch", err)
|
2017-09-12 12:18:13 +05:30
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
url := issue.HTMLURL()
|
|
|
|
c.Redirect(url, http.StatusSeeOther)
|
|
|
|
}
|