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_watch.go 1.3KB

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