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