You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.4 KiB
Go
58 lines
1.4 KiB
Go
8 years ago
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
8 years ago
|
package repo
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
"strconv"
|
||
|
|
||
|
"code.gitea.io/gitea/models"
|
||
|
"code.gitea.io/gitea/modules/context"
|
||
5 years ago
|
"code.gitea.io/gitea/modules/log"
|
||
8 years ago
|
)
|
||
|
|
||
|
// IssueWatch sets issue watching
|
||
6 years ago
|
func IssueWatch(ctx *context.Context) {
|
||
|
issue := GetActionIssue(ctx)
|
||
|
if ctx.Written() {
|
||
8 years ago
|
return
|
||
|
}
|
||
|
|
||
6 years ago
|
if !ctx.IsSigned || (ctx.User.ID != issue.PosterID && !ctx.Repo.CanReadIssuesOrPulls(issue.IsPull)) {
|
||
5 years ago
|
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",
|
||
|
ctx.User,
|
||
|
log.NewColoredIDValue(issue.PosterID),
|
||
|
issueType,
|
||
|
ctx.Repo.Repository,
|
||
|
ctx.Repo.Permission)
|
||
|
} else {
|
||
|
log.Trace("Permission Denied: Not logged in")
|
||
|
}
|
||
|
}
|
||
3 years ago
|
ctx.Error(http.StatusForbidden)
|
||
6 years ago
|
return
|
||
|
}
|
||
|
|
||
|
watch, err := strconv.ParseBool(ctx.Req.PostForm.Get("watch"))
|
||
|
if err != nil {
|
||
|
ctx.ServerError("watch is not bool", err)
|
||
8 years ago
|
return
|
||
|
}
|
||
|
|
||
6 years ago
|
if err := models.CreateOrUpdateIssueWatch(ctx.User.ID, issue.ID, watch); err != nil {
|
||
|
ctx.ServerError("CreateOrUpdateIssueWatch", err)
|
||
8 years ago
|
return
|
||
|
}
|
||
|
|
||
5 years ago
|
ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther)
|
||
8 years ago
|
}
|