Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

issue_watch.go 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. "strconv"
  8. "code.gitea.io/gitea/models"
  9. "code.gitea.io/gitea/modules/context"
  10. "code.gitea.io/gitea/modules/log"
  11. )
  12. // IssueWatch sets issue watching
  13. func IssueWatch(ctx *context.Context) {
  14. issue := GetActionIssue(ctx)
  15. if ctx.Written() {
  16. return
  17. }
  18. if !ctx.IsSigned || (ctx.User.ID != issue.PosterID && !ctx.Repo.CanReadIssuesOrPulls(issue.IsPull)) {
  19. if log.IsTrace() {
  20. if ctx.IsSigned {
  21. issueType := "issues"
  22. if issue.IsPull {
  23. issueType = "pulls"
  24. }
  25. log.Trace("Permission Denied: User %-v not the Poster (ID: %d) and cannot read %s in Repo %-v.\n"+
  26. "User in Repo has Permissions: %-+v",
  27. ctx.User,
  28. log.NewColoredIDValue(issue.PosterID),
  29. issueType,
  30. ctx.Repo.Repository,
  31. ctx.Repo.Permission)
  32. } else {
  33. log.Trace("Permission Denied: Not logged in")
  34. }
  35. }
  36. ctx.Error(403)
  37. return
  38. }
  39. watch, err := strconv.ParseBool(ctx.Req.PostForm.Get("watch"))
  40. if err != nil {
  41. ctx.ServerError("watch is not bool", err)
  42. return
  43. }
  44. if err := models.CreateOrUpdateIssueWatch(ctx.User.ID, issue.ID, watch); err != nil {
  45. ctx.ServerError("CreateOrUpdateIssueWatch", err)
  46. return
  47. }
  48. ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther)
  49. }