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.

41 lines
958 B

  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. )
  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. ctx.Error(403)
  20. return
  21. }
  22. watch, err := strconv.ParseBool(ctx.Req.PostForm.Get("watch"))
  23. if err != nil {
  24. ctx.ServerError("watch is not bool", err)
  25. return
  26. }
  27. if err := models.CreateOrUpdateIssueWatch(ctx.User.ID, issue.ID, watch); err != nil {
  28. ctx.ServerError("CreateOrUpdateIssueWatch", err)
  29. return
  30. }
  31. url := fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index)
  32. ctx.Redirect(url, http.StatusSeeOther)
  33. }