Move some functions from issue.go to standalone files (#32468)
Just functions move, no code change. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
43c252dfea
commit
a1892cf7e3
File diff suppressed because it is too large
Load Diff
472
routers/web/repo/issue_comment.go
Normal file
472
routers/web/repo/issue_comment.go
Normal file
File diff suppressed because it is too large
Load Diff
882
routers/web/repo/issue_list.go
Normal file
882
routers/web/repo/issue_list.go
Normal file
File diff suppressed because it is too large
Load Diff
403
routers/web/repo/issue_new.go
Normal file
403
routers/web/repo/issue_new.go
Normal file
File diff suppressed because it is too large
Load Diff
444
routers/web/repo/issue_page_meta.go
Normal file
444
routers/web/repo/issue_page_meta.go
Normal file
File diff suppressed because it is too large
Load Diff
66
routers/web/repo/issue_poster.go
Normal file
66
routers/web/repo/issue_poster.go
Normal file
@ -0,0 +1,66 @@
|
||||
// Copyright 2024 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package repo
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
shared_user "code.gitea.io/gitea/routers/web/shared/user"
|
||||
"code.gitea.io/gitea/services/context"
|
||||
)
|
||||
|
||||
type userSearchInfo struct {
|
||||
UserID int64 `json:"user_id"`
|
||||
UserName string `json:"username"`
|
||||
AvatarLink string `json:"avatar_link"`
|
||||
FullName string `json:"full_name"`
|
||||
}
|
||||
|
||||
type userSearchResponse struct {
|
||||
Results []*userSearchInfo `json:"results"`
|
||||
}
|
||||
|
||||
// IssuePosters get posters for current repo's issues/pull requests
|
||||
func IssuePosters(ctx *context.Context) {
|
||||
issuePosters(ctx, false)
|
||||
}
|
||||
|
||||
func PullPosters(ctx *context.Context) {
|
||||
issuePosters(ctx, true)
|
||||
}
|
||||
|
||||
func issuePosters(ctx *context.Context, isPullList bool) {
|
||||
repo := ctx.Repo.Repository
|
||||
search := strings.TrimSpace(ctx.FormString("q"))
|
||||
posters, err := repo_model.GetIssuePostersWithSearch(ctx, repo, isPullList, search, setting.UI.DefaultShowFullName)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
if search == "" && ctx.Doer != nil {
|
||||
// the returned posters slice only contains limited number of users,
|
||||
// to make the current user (doer) can quickly filter their own issues, always add doer to the posters slice
|
||||
if !slices.ContainsFunc(posters, func(user *user_model.User) bool { return user.ID == ctx.Doer.ID }) {
|
||||
posters = append(posters, ctx.Doer)
|
||||
}
|
||||
}
|
||||
|
||||
posters = shared_user.MakeSelfOnTop(ctx.Doer, posters)
|
||||
|
||||
resp := &userSearchResponse{}
|
||||
resp.Results = make([]*userSearchInfo, len(posters))
|
||||
for i, user := range posters {
|
||||
resp.Results[i] = &userSearchInfo{UserID: user.ID, UserName: user.Name, AvatarLink: user.AvatarLink(ctx)}
|
||||
if setting.UI.DefaultShowFullName {
|
||||
resp.Results[i].FullName = user.FullName
|
||||
}
|
||||
}
|
||||
ctx.JSON(http.StatusOK, resp)
|
||||
}
|
914
routers/web/repo/issue_view.go
Normal file
914
routers/web/repo/issue_view.go
Normal file
File diff suppressed because it is too large
Load Diff
@ -9,6 +9,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
"code.gitea.io/gitea/models/organization"
|
||||
pull_model "code.gitea.io/gitea/models/pull"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
@ -19,6 +20,7 @@ import (
|
||||
"code.gitea.io/gitea/services/context"
|
||||
"code.gitea.io/gitea/services/context/upload"
|
||||
"code.gitea.io/gitea/services/forms"
|
||||
issue_service "code.gitea.io/gitea/services/issue"
|
||||
pull_service "code.gitea.io/gitea/services/pull"
|
||||
user_service "code.gitea.io/gitea/services/user"
|
||||
)
|
||||
@ -332,3 +334,118 @@ func UpdateViewedFiles(ctx *context.Context) {
|
||||
ctx.ServerError("UpdateReview", err)
|
||||
}
|
||||
}
|
||||
|
||||
// UpdatePullReviewRequest add or remove review request
|
||||
func UpdatePullReviewRequest(ctx *context.Context) {
|
||||
issues := getActionIssues(ctx)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
|
||||
reviewID := ctx.FormInt64("id")
|
||||
action := ctx.FormString("action")
|
||||
|
||||
// TODO: Not support 'clear' now
|
||||
if action != "attach" && action != "detach" {
|
||||
ctx.Status(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
for _, issue := range issues {
|
||||
if err := issue.LoadRepo(ctx); err != nil {
|
||||
ctx.ServerError("issue.LoadRepo", err)
|
||||
return
|
||||
}
|
||||
|
||||
if !issue.IsPull {
|
||||
log.Warn(
|
||||
"UpdatePullReviewRequest: refusing to add review request for non-PR issue %-v#%d",
|
||||
issue.Repo, issue.Index,
|
||||
)
|
||||
ctx.Status(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
if reviewID < 0 {
|
||||
// negative reviewIDs represent team requests
|
||||
if err := issue.Repo.LoadOwner(ctx); err != nil {
|
||||
ctx.ServerError("issue.Repo.LoadOwner", err)
|
||||
return
|
||||
}
|
||||
|
||||
if !issue.Repo.Owner.IsOrganization() {
|
||||
log.Warn(
|
||||
"UpdatePullReviewRequest: refusing to add team review request for %s#%d owned by non organization UID[%d]",
|
||||
issue.Repo.FullName(), issue.Index, issue.Repo.ID,
|
||||
)
|
||||
ctx.Status(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
team, err := organization.GetTeamByID(ctx, -reviewID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetTeamByID", err)
|
||||
return
|
||||
}
|
||||
|
||||
if team.OrgID != issue.Repo.OwnerID {
|
||||
log.Warn(
|
||||
"UpdatePullReviewRequest: refusing to add team review request for UID[%d] team %s to %s#%d owned by UID[%d]",
|
||||
team.OrgID, team.Name, issue.Repo.FullName(), issue.Index, issue.Repo.ID)
|
||||
ctx.Status(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = issue_service.TeamReviewRequest(ctx, issue, ctx.Doer, team, action == "attach")
|
||||
if err != nil {
|
||||
if issues_model.IsErrNotValidReviewRequest(err) {
|
||||
log.Warn(
|
||||
"UpdatePullReviewRequest: refusing to add invalid team review request for UID[%d] team %s to %s#%d owned by UID[%d]: Error: %v",
|
||||
team.OrgID, team.Name, issue.Repo.FullName(), issue.Index, issue.Repo.ID,
|
||||
err,
|
||||
)
|
||||
ctx.Status(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
ctx.ServerError("TeamReviewRequest", err)
|
||||
return
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
reviewer, err := user_model.GetUserByID(ctx, reviewID)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
log.Warn(
|
||||
"UpdatePullReviewRequest: requested reviewer [%d] for %-v to %-v#%d is not exist: Error: %v",
|
||||
reviewID, issue.Repo, issue.Index,
|
||||
err,
|
||||
)
|
||||
ctx.Status(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
ctx.ServerError("GetUserByID", err)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = issue_service.ReviewRequest(ctx, issue, ctx.Doer, &ctx.Repo.Permission, reviewer, action == "attach")
|
||||
if err != nil {
|
||||
if issues_model.IsErrNotValidReviewRequest(err) {
|
||||
log.Warn(
|
||||
"UpdatePullReviewRequest: refusing to add invalid review request for %-v to %-v#%d: Error: %v",
|
||||
reviewer, issue.Repo, issue.Index,
|
||||
err,
|
||||
)
|
||||
ctx.Status(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
if issues_model.IsErrReviewRequestOnClosedPR(err) {
|
||||
ctx.Status(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
ctx.ServerError("ReviewRequest", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
ctx.JSONOK()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user