You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

issue_stopwatch.go 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package repo
  5. import (
  6. "net/http"
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/context"
  9. )
  10. // IssueStopwatch creates or stops a stopwatch for the given issue.
  11. func IssueStopwatch(c *context.Context) {
  12. issue := GetActionIssue(c)
  13. if c.Written() {
  14. return
  15. }
  16. if !c.Repo.CanUseTimetracker(issue, c.User) {
  17. c.NotFound("CanUseTimetracker", nil)
  18. return
  19. }
  20. if err := models.CreateOrStopIssueStopwatch(c.User, issue); err != nil {
  21. c.ServerError("CreateOrStopIssueStopwatch", err)
  22. return
  23. }
  24. url := issue.HTMLURL()
  25. c.Redirect(url, http.StatusSeeOther)
  26. }
  27. // CancelStopwatch cancel the stopwatch
  28. func CancelStopwatch(c *context.Context) {
  29. issue := GetActionIssue(c)
  30. if c.Written() {
  31. return
  32. }
  33. if !c.Repo.CanUseTimetracker(issue, c.User) {
  34. c.NotFound("CanUseTimetracker", nil)
  35. return
  36. }
  37. if err := models.CancelStopwatch(c.User, issue); err != nil {
  38. c.ServerError("CancelStopwatch", err)
  39. return
  40. }
  41. url := issue.HTMLURL()
  42. c.Redirect(url, http.StatusSeeOther)
  43. }