mirror of
https://github.com/go-gitea/gitea
synced 2024-11-18 16:01:36 +01:00
eabbddcd98
* fix units permission problems * fix some bugs and merge LoadUnits to repoAssignment * refactor permission struct and add some copyright heads * remove unused codes * fix routes units check * improve permission check * add unit tests for permission * fix typo * fix tests * fix some routes * fix api permission check * improve permission check * fix some permission check * fix tests * fix tests * improve some permission check * fix some permission check * refactor AccessLevel * fix bug * fix tests * fix tests * fix tests * fix AccessLevel * rename CanAccess * fix tests * fix comment * fix bug * add missing unit for test repos * fix bug * rename some functions * fix routes check
41 lines
958 B
Go
41 lines
958 B
Go
// 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.
|
|
|
|
package repo
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"code.gitea.io/gitea/models"
|
|
"code.gitea.io/gitea/modules/context"
|
|
)
|
|
|
|
// IssueWatch sets issue watching
|
|
func IssueWatch(ctx *context.Context) {
|
|
issue := GetActionIssue(ctx)
|
|
if ctx.Written() {
|
|
return
|
|
}
|
|
|
|
if !ctx.IsSigned || (ctx.User.ID != issue.PosterID && !ctx.Repo.CanReadIssuesOrPulls(issue.IsPull)) {
|
|
ctx.Error(403)
|
|
return
|
|
}
|
|
|
|
watch, err := strconv.ParseBool(ctx.Req.PostForm.Get("watch"))
|
|
if err != nil {
|
|
ctx.ServerError("watch is not bool", err)
|
|
return
|
|
}
|
|
|
|
if err := models.CreateOrUpdateIssueWatch(ctx.User.ID, issue.ID, watch); err != nil {
|
|
ctx.ServerError("CreateOrUpdateIssueWatch", err)
|
|
return
|
|
}
|
|
|
|
url := fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index)
|
|
ctx.Redirect(url, http.StatusSeeOther)
|
|
}
|