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

60 lines
1.4KB

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