mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-09 19:31:21 +01:00
5390791224
* Don't display buttons if there are no notices * clear stopwatch on merging a PR * remove redundant gt check * use ctx.Flash as per @bkcsoft comment * stop timer on closing issues/PRs too * updated translation as per review * redirect to login page after successfully activating account * remove unrelated changes * stop timer for issues that are closed via commits too..Not just the 'close' UI button
63 lines
1.3 KiB
Go
63 lines
1.3 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
|
|
}
|
|
|
|
var showSuccessMessage bool
|
|
|
|
if !models.StopwatchExists(c.User.ID, issue.ID) {
|
|
showSuccessMessage = true
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
if showSuccessMessage {
|
|
c.Flash.Success(c.Tr("repo.issues.tracker_auto_close"))
|
|
}
|
|
|
|
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)
|
|
}
|