gitea源码

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package repo
  4. import (
  5. "net/http"
  6. "strconv"
  7. issues_model "code.gitea.io/gitea/models/issues"
  8. "code.gitea.io/gitea/modules/log"
  9. "code.gitea.io/gitea/modules/templates"
  10. "code.gitea.io/gitea/services/context"
  11. )
  12. const (
  13. tplWatching templates.TplName = "repo/issue/view_content/watching"
  14. )
  15. // IssueWatch sets issue watching
  16. func IssueWatch(ctx *context.Context) {
  17. issue := GetActionIssue(ctx)
  18. if ctx.Written() {
  19. return
  20. }
  21. if !ctx.IsSigned || (ctx.Doer.ID != issue.PosterID && !ctx.Repo.CanReadIssuesOrPulls(issue.IsPull)) {
  22. if log.IsTrace() {
  23. if ctx.IsSigned {
  24. issueType := "issues"
  25. if issue.IsPull {
  26. issueType = "pulls"
  27. }
  28. log.Trace("Permission Denied: User %-v not the Poster (ID: %d) and cannot read %s in Repo %-v.\n"+
  29. "User in Repo has Permissions: %-+v",
  30. ctx.Doer,
  31. issue.PosterID,
  32. issueType,
  33. ctx.Repo.Repository,
  34. ctx.Repo.Permission)
  35. } else {
  36. log.Trace("Permission Denied: Not logged in")
  37. }
  38. }
  39. ctx.HTTPError(http.StatusForbidden)
  40. return
  41. }
  42. watch, err := strconv.ParseBool(ctx.Req.PostFormValue("watch"))
  43. if err != nil {
  44. ctx.ServerError("watch is not bool", err)
  45. return
  46. }
  47. if err := issues_model.CreateOrUpdateIssueWatch(ctx, ctx.Doer.ID, issue.ID, watch); err != nil {
  48. ctx.ServerError("CreateOrUpdateIssueWatch", err)
  49. return
  50. }
  51. ctx.Data["Issue"] = issue
  52. ctx.Data["IssueWatch"] = &issues_model.IssueWatch{IsWatching: watch}
  53. ctx.HTML(http.StatusOK, tplWatching)
  54. }