Files

64 lines
1.5 KiB
Go
Raw Permalink Normal View History

2017-03-30 19:11:58 -03:00
// Copyright 2017 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
2017-03-30 19:11:58 -03:00
2017-03-29 20:31:47 -03:00
package repo
import (
"net/http"
"strconv"
issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/templates"
"code.gitea.io/gitea/services/context"
2017-03-29 20:31:47 -03:00
)
const (
tplWatching templates.TplName = "repo/issue/view_content/watching"
)
2017-03-29 20:31:47 -03:00
// IssueWatch sets issue watching
func IssueWatch(ctx *context.Context) {
issue := GetActionIssue(ctx)
if ctx.Written() {
2017-03-29 20:31:47 -03:00
return
}
2022-03-22 08:03:22 +01:00
if !ctx.IsSigned || (ctx.Doer.ID != issue.PosterID && !ctx.Repo.CanReadIssuesOrPulls(issue.IsPull)) {
if log.IsTrace() {
if ctx.IsSigned {
issueType := "issues"
if issue.IsPull {
issueType = "pulls"
}
log.Trace("Permission Denied: User %-v not the Poster (ID: %d) and cannot read %s in Repo %-v.\n"+
"User in Repo has Permissions: %-+v",
2022-03-22 08:03:22 +01:00
ctx.Doer,
2023-05-22 06:35:11 +08:00
issue.PosterID,
issueType,
ctx.Repo.Repository,
ctx.Repo.Permission)
} else {
log.Trace("Permission Denied: Not logged in")
}
}
2025-02-17 14:13:17 +08:00
ctx.HTTPError(http.StatusForbidden)
return
}
2025-01-17 16:55:02 +08:00
watch, err := strconv.ParseBool(ctx.Req.PostFormValue("watch"))
if err != nil {
ctx.ServerError("watch is not bool", err)
2017-03-29 20:31:47 -03:00
return
}
if err := issues_model.CreateOrUpdateIssueWatch(ctx, ctx.Doer.ID, issue.ID, watch); err != nil {
ctx.ServerError("CreateOrUpdateIssueWatch", err)
2017-03-29 20:31:47 -03:00
return
}
ctx.Data["Issue"] = issue
ctx.Data["IssueWatch"] = &issues_model.IssueWatch{IsWatching: watch}
ctx.HTML(http.StatusOK, tplWatching)
2017-03-29 20:31:47 -03:00
}