本站源代码
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.

64 lines
1.3KB

  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. var showSuccessMessage bool
  17. if !models.StopwatchExists(c.User.ID, issue.ID) {
  18. showSuccessMessage = true
  19. }
  20. if !c.Repo.CanUseTimetracker(issue, c.User) {
  21. c.NotFound("CanUseTimetracker", nil)
  22. return
  23. }
  24. if err := models.CreateOrStopIssueStopwatch(c.User, issue); err != nil {
  25. c.ServerError("CreateOrStopIssueStopwatch", err)
  26. return
  27. }
  28. if showSuccessMessage {
  29. c.Flash.Success(c.Tr("repo.issues.tracker_auto_close"))
  30. }
  31. url := issue.HTMLURL()
  32. c.Redirect(url, http.StatusSeeOther)
  33. }
  34. // CancelStopwatch cancel the stopwatch
  35. func CancelStopwatch(c *context.Context) {
  36. issue := GetActionIssue(c)
  37. if c.Written() {
  38. return
  39. }
  40. if !c.Repo.CanUseTimetracker(issue, c.User) {
  41. c.NotFound("CanUseTimetracker", nil)
  42. return
  43. }
  44. if err := models.CancelStopwatch(c.User, issue); err != nil {
  45. c.ServerError("CancelStopwatch", err)
  46. return
  47. }
  48. url := issue.HTMLURL()
  49. c.Redirect(url, http.StatusSeeOther)
  50. }
上海开阖软件有限公司 沪ICP备12045867号-1