2017-03-30 19:11:58 -03:00
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
2022-11-27 13:20:29 -05:00
|
|
|
// 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"
|
|
|
|
|
|
2022-06-13 17:37:59 +08:00
|
|
|
issues_model "code.gitea.io/gitea/models/issues"
|
2019-04-22 21:40:51 +01:00
|
|
|
"code.gitea.io/gitea/modules/log"
|
2024-12-22 23:33:19 +08:00
|
|
|
"code.gitea.io/gitea/modules/templates"
|
2024-02-27 15:12:22 +08:00
|
|
|
"code.gitea.io/gitea/services/context"
|
2017-03-29 20:31:47 -03:00
|
|
|
)
|
|
|
|
|
|
2024-01-30 16:45:54 +02:00
|
|
|
const (
|
2024-12-22 23:33:19 +08:00
|
|
|
tplWatching templates.TplName = "repo/issue/view_content/watching"
|
2024-01-30 16:45:54 +02:00
|
|
|
)
|
|
|
|
|
|
2017-03-29 20:31:47 -03:00
|
|
|
// IssueWatch sets issue watching
|
2018-11-28 19:26:14 +08:00
|
|
|
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)) {
|
2019-04-22 21:40:51 +01:00
|
|
|
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,
|
2019-04-22 21:40:51 +01:00
|
|
|
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)
|
2018-11-28 19:26:14 +08:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-17 16:55:02 +08:00
|
|
|
watch, err := strconv.ParseBool(ctx.Req.PostFormValue("watch"))
|
2018-11-28 19:26:14 +08:00
|
|
|
if err != nil {
|
|
|
|
|
ctx.ServerError("watch is not bool", err)
|
2017-03-29 20:31:47 -03:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-16 16:39:12 +02:00
|
|
|
if err := issues_model.CreateOrUpdateIssueWatch(ctx, ctx.Doer.ID, issue.ID, watch); err != nil {
|
2018-11-28 19:26:14 +08:00
|
|
|
ctx.ServerError("CreateOrUpdateIssueWatch", err)
|
2017-03-29 20:31:47 -03:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-30 16:45:54 +02:00
|
|
|
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
|
|
|
}
|