summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2022-04-28 13:48:48 +0200
committerGitHub <noreply@github.com>2022-04-28 13:48:48 +0200
commit06e4687cecaed41500b653e5b8685f48b8b18310 (patch)
treea98dd6d0139ba5d89c7e08d3c52930d66a77119b /routers
parent332b2ecd214a79b49f3798f4f27fe02b23a17bf8 (diff)
downloadgitea-06e4687cecaed41500b653e5b8685f48b8b18310.tar.gz
gitea-06e4687cecaed41500b653e5b8685f48b8b18310.zip
more context for models (#19511)
make more usage of context, to have more db transaction in one session (make diff of #9307 smaller)
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/api.go2
-rw-r--r--routers/api/v1/repo/branch.go4
-rw-r--r--routers/api/v1/repo/issue_comment.go9
-rw-r--r--routers/api/v1/repo/pull.go22
-rw-r--r--routers/api/v1/repo/pull_review.go6
-rw-r--r--routers/api/v1/repo/repo.go2
-rw-r--r--routers/private/hook_pre_receive.go4
-rw-r--r--routers/private/serv.go2
-rw-r--r--routers/web/repo/attachment.go2
-rw-r--r--routers/web/repo/branch.go2
-rw-r--r--routers/web/repo/compare.go4
-rw-r--r--routers/web/repo/http.go2
-rw-r--r--routers/web/repo/issue.go25
-rw-r--r--routers/web/repo/pull.go22
-rw-r--r--routers/web/repo/setting_protected_branch.go2
15 files changed, 56 insertions, 54 deletions
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go
index aec2a6d7b2..cca0f37ba1 100644
--- a/routers/api/v1/api.go
+++ b/routers/api/v1/api.go
@@ -183,7 +183,7 @@ func repoAssignment() func(ctx *context.APIContext) {
repo.Owner = owner
ctx.Repo.Repository = repo
- ctx.Repo.Permission, err = models.GetUserRepoPermission(repo, ctx.Doer)
+ ctx.Repo.Permission, err = models.GetUserRepoPermission(ctx, repo, ctx.Doer)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
return
diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go
index f22bed813e..794d367b53 100644
--- a/routers/api/v1/repo/branch.go
+++ b/routers/api/v1/repo/branch.go
@@ -498,7 +498,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
BlockOnOutdatedBranch: form.BlockOnOutdatedBranch,
}
- err = models.UpdateProtectBranch(ctx.Repo.Repository, protectBranch, models.WhitelistOptions{
+ err = models.UpdateProtectBranch(ctx, ctx.Repo.Repository, protectBranch, models.WhitelistOptions{
UserIDs: whitelistUsers,
TeamIDs: whitelistTeams,
MergeUserIDs: mergeWhitelistUsers,
@@ -733,7 +733,7 @@ func EditBranchProtection(ctx *context.APIContext) {
}
}
- err = models.UpdateProtectBranch(ctx.Repo.Repository, protectBranch, models.WhitelistOptions{
+ err = models.UpdateProtectBranch(ctx, ctx.Repo.Repository, protectBranch, models.WhitelistOptions{
UserIDs: whitelistUsers,
TeamIDs: whitelistTeams,
MergeUserIDs: mergeWhitelistUsers,
diff --git a/routers/api/v1/repo/issue_comment.go b/routers/api/v1/repo/issue_comment.go
index ef91a2481c..bc68cb396b 100644
--- a/routers/api/v1/repo/issue_comment.go
+++ b/routers/api/v1/repo/issue_comment.go
@@ -6,6 +6,7 @@
package repo
import (
+ stdCtx "context"
"errors"
"net/http"
@@ -183,7 +184,7 @@ func ListIssueCommentsAndTimeline(ctx *context.APIContext) {
var apiComments []*api.TimelineComment
for _, comment := range comments {
- if comment.Type != models.CommentTypeCode && isXRefCommentAccessible(ctx.Doer, comment, issue.RepoID) {
+ if comment.Type != models.CommentTypeCode && isXRefCommentAccessible(ctx, ctx.Doer, comment, issue.RepoID) {
comment.Issue = issue
apiComments = append(apiComments, convert.ToTimelineComment(comment, ctx.Doer))
}
@@ -193,16 +194,16 @@ func ListIssueCommentsAndTimeline(ctx *context.APIContext) {
ctx.JSON(http.StatusOK, &apiComments)
}
-func isXRefCommentAccessible(user *user_model.User, c *models.Comment, issueRepoID int64) bool {
+func isXRefCommentAccessible(ctx stdCtx.Context, user *user_model.User, c *models.Comment, issueRepoID int64) bool {
// Remove comments that the user has no permissions to see
if models.CommentTypeIsRef(c.Type) && c.RefRepoID != issueRepoID && c.RefRepoID != 0 {
var err error
// Set RefRepo for description in template
- c.RefRepo, err = repo_model.GetRepositoryByID(c.RefRepoID)
+ c.RefRepo, err = repo_model.GetRepositoryByIDCtx(ctx, c.RefRepoID)
if err != nil {
return false
}
- perm, err := models.GetUserRepoPermission(c.RefRepo, user)
+ perm, err := models.GetUserRepoPermission(ctx, c.RefRepo, user)
if err != nil {
return false
}
diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go
index 94262f81d1..6b076eff8f 100644
--- a/routers/api/v1/repo/pull.go
+++ b/routers/api/v1/repo/pull.go
@@ -111,11 +111,11 @@ func ListPullRequests(ctx *context.APIContext) {
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
return
}
- if err = prs[i].LoadBaseRepo(); err != nil {
+ if err = prs[i].LoadBaseRepoCtx(ctx); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadBaseRepo", err)
return
}
- if err = prs[i].LoadHeadRepo(); err != nil {
+ if err = prs[i].LoadHeadRepoCtx(ctx); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadHeadRepo", err)
return
}
@@ -167,11 +167,11 @@ func GetPullRequest(ctx *context.APIContext) {
return
}
- if err = pr.LoadBaseRepo(); err != nil {
+ if err = pr.LoadBaseRepoCtx(ctx); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadBaseRepo", err)
return
}
- if err = pr.LoadHeadRepo(); err != nil {
+ if err = pr.LoadHeadRepoCtx(ctx); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadHeadRepo", err)
return
}
@@ -724,7 +724,7 @@ func MergePullRequest(ctx *context.APIContext) {
return
}
- if err := pr.LoadHeadRepo(); err != nil {
+ if err := pr.LoadHeadRepoCtx(ctx); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadHeadRepo", err)
return
}
@@ -943,7 +943,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
}
// user should have permission to read baseRepo's codes and pulls, NOT headRepo's
- permBase, err := models.GetUserRepoPermission(baseRepo, ctx.Doer)
+ permBase, err := models.GetUserRepoPermission(ctx, baseRepo, ctx.Doer)
if err != nil {
headGitRepo.Close()
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
@@ -962,7 +962,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
}
// user should have permission to read headrepo's codes
- permHead, err := models.GetUserRepoPermission(headRepo, ctx.Doer)
+ permHead, err := models.GetUserRepoPermission(ctx, headRepo, ctx.Doer)
if err != nil {
headGitRepo.Close()
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
@@ -1063,18 +1063,18 @@ func UpdatePullRequest(ctx *context.APIContext) {
return
}
- if err = pr.LoadBaseRepo(); err != nil {
+ if err = pr.LoadBaseRepoCtx(ctx); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadBaseRepo", err)
return
}
- if err = pr.LoadHeadRepo(); err != nil {
+ if err = pr.LoadHeadRepoCtx(ctx); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadHeadRepo", err)
return
}
rebase := ctx.FormString("style") == "rebase"
- allowedUpdateByMerge, allowedUpdateByRebase, err := pull_service.IsUserAllowedToUpdate(pr, ctx.Doer)
+ allowedUpdateByMerge, allowedUpdateByRebase, err := pull_service.IsUserAllowedToUpdate(ctx, pr, ctx.Doer)
if err != nil {
ctx.Error(http.StatusInternalServerError, "IsUserAllowedToMerge", err)
return
@@ -1151,7 +1151,7 @@ func GetPullRequestCommits(ctx *context.APIContext) {
return
}
- if err := pr.LoadBaseRepo(); err != nil {
+ if err := pr.LoadBaseRepoCtx(ctx); err != nil {
ctx.InternalServerError(err)
return
}
diff --git a/routers/api/v1/repo/pull_review.go b/routers/api/v1/repo/pull_review.go
index 3b36f28326..b3ebe49bf5 100644
--- a/routers/api/v1/repo/pull_review.go
+++ b/routers/api/v1/repo/pull_review.go
@@ -664,7 +664,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
reviewers := make([]*user_model.User, 0, len(opts.Reviewers))
- permDoer, err := models.GetUserRepoPermission(pr.Issue.Repo, ctx.Doer)
+ permDoer, err := models.GetUserRepoPermission(ctx, pr.Issue.Repo, ctx.Doer)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
return
@@ -687,7 +687,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
return
}
- err = issue_service.IsValidReviewRequest(reviewer, ctx.Doer, isAdd, pr.Issue, &permDoer)
+ err = issue_service.IsValidReviewRequest(ctx, reviewer, ctx.Doer, isAdd, pr.Issue, &permDoer)
if err != nil {
if models.IsErrNotValidReviewRequest(err) {
ctx.Error(http.StatusUnprocessableEntity, "NotValidReviewRequest", err)
@@ -736,7 +736,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
return
}
- err = issue_service.IsValidTeamReviewRequest(teamReviewer, ctx.Doer, isAdd, pr.Issue)
+ err = issue_service.IsValidTeamReviewRequest(ctx, teamReviewer, ctx.Doer, isAdd, pr.Issue)
if err != nil {
if models.IsErrNotValidReviewRequest(err) {
ctx.Error(http.StatusUnprocessableEntity, "NotValidReviewRequest", err)
diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go
index cec4c93d19..29e8352142 100644
--- a/routers/api/v1/repo/repo.go
+++ b/routers/api/v1/repo/repo.go
@@ -555,7 +555,7 @@ func GetByID(ctx *context.APIContext) {
return
}
- perm, err := models.GetUserRepoPermission(repo, ctx.Doer)
+ perm, err := models.GetUserRepoPermission(ctx, repo, ctx.Doer)
if err != nil {
ctx.Error(http.StatusInternalServerError, "AccessLevel", err)
return
diff --git a/routers/private/hook_pre_receive.go b/routers/private/hook_pre_receive.go
index 763fe1cf1c..ccb6933787 100644
--- a/routers/private/hook_pre_receive.go
+++ b/routers/private/hook_pre_receive.go
@@ -290,7 +290,7 @@ func preReceiveBranch(ctx *preReceiveContext, oldCommitID, newCommitID, refFullN
// 6b. Merge (from UI or API)
// Get the PR, user and permissions for the user in the repository
- pr, err := models.GetPullRequestByID(ctx.opts.PullRequestID)
+ pr, err := models.GetPullRequestByID(ctx, ctx.opts.PullRequestID)
if err != nil {
log.Error("Unable to get PullRequest %d Error: %v", ctx.opts.PullRequestID, err)
ctx.JSON(http.StatusInternalServerError, private.Response{
@@ -468,7 +468,7 @@ func (ctx *preReceiveContext) loadPusherAndPermission() bool {
}
ctx.user = user
- userPerm, err := models.GetUserRepoPermission(ctx.Repo.Repository, user)
+ userPerm, err := models.GetUserRepoPermission(ctx, ctx.Repo.Repository, user)
if err != nil {
log.Error("Unable to get Repo permission of repo %s/%s of User %s", ctx.Repo.Repository.OwnerName, ctx.Repo.Repository.Name, user.Name, err)
ctx.JSON(http.StatusInternalServerError, private.Response{
diff --git a/routers/private/serv.go b/routers/private/serv.go
index b0451df5d8..6ef0079a2b 100644
--- a/routers/private/serv.go
+++ b/routers/private/serv.go
@@ -320,7 +320,7 @@ func ServCommand(ctx *context.PrivateContext) {
mode = perm.AccessModeRead
}
- perm, err := models.GetUserRepoPermission(repo, user)
+ perm, err := models.GetUserRepoPermission(ctx, repo, user)
if err != nil {
log.Error("Unable to get permissions for %-v with key %d in %-v Error: %v", user, key.ID, repo, err)
ctx.JSON(http.StatusInternalServerError, private.ErrServCommand{
diff --git a/routers/web/repo/attachment.go b/routers/web/repo/attachment.go
index be5b5812d3..c930311f70 100644
--- a/routers/web/repo/attachment.go
+++ b/routers/web/repo/attachment.go
@@ -106,7 +106,7 @@ func GetAttachment(ctx *context.Context) {
return
}
} else { // If we have the repository we check access
- perm, err := models.GetUserRepoPermission(repository, ctx.Doer)
+ perm, err := models.GetUserRepoPermission(ctx, repository, ctx.Doer)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err.Error())
return
diff --git a/routers/web/repo/branch.go b/routers/web/repo/branch.go
index 0d139ec79c..732b9c9d54 100644
--- a/routers/web/repo/branch.go
+++ b/routers/web/repo/branch.go
@@ -279,7 +279,7 @@ func loadOneBranch(ctx *context.Context, rawBranch, defaultBranch *git.Branch, p
}
if repo, ok := repoIDToRepo[pr.BaseRepoID]; ok {
pr.BaseRepo = repo
- } else if err := pr.LoadBaseRepo(); err != nil {
+ } else if err := pr.LoadBaseRepoCtx(ctx); err != nil {
ctx.ServerError("pr.LoadBaseRepo", err)
return nil
} else {
diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go
index 60c6ae0298..9f7bef43ef 100644
--- a/routers/web/repo/compare.go
+++ b/routers/web/repo/compare.go
@@ -402,7 +402,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
// Now we need to assert that the ctx.Doer has permission to read
// the baseRepo's code and pulls
// (NOT headRepo's)
- permBase, err := models.GetUserRepoPermission(baseRepo, ctx.Doer)
+ permBase, err := models.GetUserRepoPermission(ctx, baseRepo, ctx.Doer)
if err != nil {
ctx.ServerError("GetUserRepoPermission", err)
return nil
@@ -421,7 +421,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
// If we're not merging from the same repo:
if !isSameRepo {
// Assert ctx.Doer has permission to read headRepo's codes
- permHead, err := models.GetUserRepoPermission(ci.HeadRepo, ctx.Doer)
+ permHead, err := models.GetUserRepoPermission(ctx, ci.HeadRepo, ctx.Doer)
if err != nil {
ctx.ServerError("GetUserRepoPermission", err)
return nil
diff --git a/routers/web/repo/http.go b/routers/web/repo/http.go
index 1306a54369..cc44c8e7e4 100644
--- a/routers/web/repo/http.go
+++ b/routers/web/repo/http.go
@@ -181,7 +181,7 @@ func httpBase(ctx *context.Context) (h *serviceHandler) {
}
if repoExist {
- p, err := models.GetUserRepoPermission(repo, ctx.Doer)
+ p, err := models.GetUserRepoPermission(ctx, repo, ctx.Doer)
if err != nil {
ctx.ServerError("GetUserRepoPermission", err)
return
diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go
index ee36216d9f..8e865e448f 100644
--- a/routers/web/repo/issue.go
+++ b/routers/web/repo/issue.go
@@ -7,6 +7,7 @@ package repo
import (
"bytes"
+ stdCtx "context"
"errors"
"fmt"
"io"
@@ -1052,8 +1053,8 @@ func NewIssuePost(ctx *context.Context) {
}
// roleDescriptor returns the Role Descriptor for a comment in/with the given repo, poster and issue
-func roleDescriptor(repo *repo_model.Repository, poster *user_model.User, issue *models.Issue) (models.RoleDescriptor, error) {
- perm, err := models.GetUserRepoPermission(repo, poster)
+func roleDescriptor(ctx stdCtx.Context, repo *repo_model.Repository, poster *user_model.User, issue *models.Issue) (models.RoleDescriptor, error) {
+ perm, err := models.GetUserRepoPermission(ctx, repo, poster)
if err != nil {
return models.RoleDescriptorNone, err
}
@@ -1350,7 +1351,7 @@ func ViewIssue(ctx *context.Context) {
// check if dependencies can be created across repositories
ctx.Data["AllowCrossRepositoryDependencies"] = setting.Service.AllowCrossRepositoryDependencies
- if issue.ShowRole, err = roleDescriptor(repo, issue.Poster, issue); err != nil {
+ if issue.ShowRole, err = roleDescriptor(ctx, repo, issue.Poster, issue); err != nil {
ctx.ServerError("roleDescriptor", err)
return
}
@@ -1389,7 +1390,7 @@ func ViewIssue(ctx *context.Context) {
continue
}
- comment.ShowRole, err = roleDescriptor(repo, comment.Poster, issue)
+ comment.ShowRole, err = roleDescriptor(ctx, repo, comment.Poster, issue)
if err != nil {
ctx.ServerError("roleDescriptor", err)
return
@@ -1488,7 +1489,7 @@ func ViewIssue(ctx *context.Context) {
continue
}
- c.ShowRole, err = roleDescriptor(repo, c.Poster, issue)
+ c.ShowRole, err = roleDescriptor(ctx, repo, c.Poster, issue)
if err != nil {
ctx.ServerError("roleDescriptor", err)
return
@@ -1526,10 +1527,10 @@ func ViewIssue(ctx *context.Context) {
ctx.Data["AllowMerge"] = false
if ctx.IsSigned {
- if err := pull.LoadHeadRepo(); err != nil {
+ if err := pull.LoadHeadRepoCtx(ctx); err != nil {
log.Error("LoadHeadRepo: %v", err)
} else if pull.HeadRepo != nil && pull.HeadBranch != pull.HeadRepo.DefaultBranch {
- perm, err := models.GetUserRepoPermission(pull.HeadRepo, ctx.Doer)
+ perm, err := models.GetUserRepoPermission(ctx, pull.HeadRepo, ctx.Doer)
if err != nil {
ctx.ServerError("GetUserRepoPermission", err)
return
@@ -1545,10 +1546,10 @@ func ViewIssue(ctx *context.Context) {
}
}
- if err := pull.LoadBaseRepo(); err != nil {
+ if err := pull.LoadBaseRepoCtx(ctx); err != nil {
log.Error("LoadBaseRepo: %v", err)
}
- perm, err := models.GetUserRepoPermission(pull.BaseRepo, ctx.Doer)
+ perm, err := models.GetUserRepoPermission(ctx, pull.BaseRepo, ctx.Doer)
if err != nil {
ctx.ServerError("GetUserRepoPermission", err)
return
@@ -2038,7 +2039,7 @@ func UpdatePullReviewRequest(ctx *context.Context) {
return
}
- err = issue_service.IsValidTeamReviewRequest(team, ctx.Doer, action == "attach", issue)
+ err = issue_service.IsValidTeamReviewRequest(ctx, team, ctx.Doer, action == "attach", issue)
if err != nil {
if models.IsErrNotValidReviewRequest(err) {
log.Warn(
@@ -2076,7 +2077,7 @@ func UpdatePullReviewRequest(ctx *context.Context) {
return
}
- err = issue_service.IsValidReviewRequest(reviewer, ctx.Doer, action == "attach", issue, nil)
+ err = issue_service.IsValidReviewRequest(ctx, reviewer, ctx.Doer, action == "attach", issue, nil)
if err != nil {
if models.IsErrNotValidReviewRequest(err) {
log.Warn(
@@ -2919,7 +2920,7 @@ func filterXRefComments(ctx *context.Context, issue *models.Issue) error {
if err != nil {
return err
}
- perm, err := models.GetUserRepoPermission(c.RefRepo, ctx.Doer)
+ perm, err := models.GetUserRepoPermission(ctx, c.RefRepo, ctx.Doer)
if err != nil {
return err
}
diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go
index 113e2d8421..a03e16f39a 100644
--- a/routers/web/repo/pull.go
+++ b/routers/web/repo/pull.go
@@ -70,7 +70,7 @@ func getRepository(ctx *context.Context, repoID int64) *repo_model.Repository {
return nil
}
- perm, err := models.GetUserRepoPermission(repo, ctx.Doer)
+ perm, err := models.GetUserRepoPermission(ctx, repo, ctx.Doer)
if err != nil {
ctx.ServerError("GetUserRepoPermission", err)
return nil
@@ -283,7 +283,7 @@ func checkPullInfo(ctx *context.Context) *models.Issue {
return nil
}
- if err = issue.PullRequest.LoadHeadRepo(); err != nil {
+ if err = issue.PullRequest.LoadHeadRepoCtx(ctx); err != nil {
ctx.ServerError("LoadHeadRepo", err)
return nil
}
@@ -397,12 +397,12 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare
repo := ctx.Repo.Repository
pull := issue.PullRequest
- if err := pull.LoadHeadRepo(); err != nil {
+ if err := pull.LoadHeadRepoCtx(ctx); err != nil {
ctx.ServerError("LoadHeadRepo", err)
return nil
}
- if err := pull.LoadBaseRepo(); err != nil {
+ if err := pull.LoadBaseRepoCtx(ctx); err != nil {
ctx.ServerError("LoadBaseRepo", err)
return nil
}
@@ -499,7 +499,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare
if headBranchExist {
var err error
- ctx.Data["UpdateAllowed"], ctx.Data["UpdateByRebaseAllowed"], err = pull_service.IsUserAllowedToUpdate(pull, ctx.Doer)
+ ctx.Data["UpdateAllowed"], ctx.Data["UpdateByRebaseAllowed"], err = pull_service.IsUserAllowedToUpdate(ctx, pull, ctx.Doer)
if err != nil {
ctx.ServerError("IsUserAllowedToUpdate", err)
return nil
@@ -785,16 +785,16 @@ func UpdatePullRequest(ctx *context.Context) {
rebase := ctx.FormString("style") == "rebase"
- if err := issue.PullRequest.LoadBaseRepo(); err != nil {
+ if err := issue.PullRequest.LoadBaseRepoCtx(ctx); err != nil {
ctx.ServerError("LoadBaseRepo", err)
return
}
- if err := issue.PullRequest.LoadHeadRepo(); err != nil {
+ if err := issue.PullRequest.LoadHeadRepoCtx(ctx); err != nil {
ctx.ServerError("LoadHeadRepo", err)
return
}
- allowedUpdateByMerge, allowedUpdateByRebase, err := pull_service.IsUserAllowedToUpdate(issue.PullRequest, ctx.Doer)
+ allowedUpdateByMerge, allowedUpdateByRebase, err := pull_service.IsUserAllowedToUpdate(ctx, issue.PullRequest, ctx.Doer)
if err != nil {
ctx.ServerError("IsUserAllowedToMerge", err)
return
@@ -1202,14 +1202,14 @@ func CleanUpPullRequest(ctx *context.Context) {
return
}
- if err := pr.LoadHeadRepo(); err != nil {
+ if err := pr.LoadHeadRepoCtx(ctx); err != nil {
ctx.ServerError("LoadHeadRepo", err)
return
} else if pr.HeadRepo == nil {
// Forked repository has already been deleted
ctx.NotFound("CleanUpPullRequest", nil)
return
- } else if err = pr.LoadBaseRepo(); err != nil {
+ } else if err = pr.LoadBaseRepoCtx(ctx); err != nil {
ctx.ServerError("LoadBaseRepo", err)
return
} else if err = pr.HeadRepo.GetOwner(ctx); err != nil {
@@ -1217,7 +1217,7 @@ func CleanUpPullRequest(ctx *context.Context) {
return
}
- perm, err := models.GetUserRepoPermission(pr.HeadRepo, ctx.Doer)
+ perm, err := models.GetUserRepoPermission(ctx, pr.HeadRepo, ctx.Doer)
if err != nil {
ctx.ServerError("GetUserRepoPermission", err)
return
diff --git a/routers/web/repo/setting_protected_branch.go b/routers/web/repo/setting_protected_branch.go
index a26a0a620a..1f6e2316e7 100644
--- a/routers/web/repo/setting_protected_branch.go
+++ b/routers/web/repo/setting_protected_branch.go
@@ -261,7 +261,7 @@ func SettingsProtectedBranchPost(ctx *context.Context) {
protectBranch.UnprotectedFilePatterns = f.UnprotectedFilePatterns
protectBranch.BlockOnOutdatedBranch = f.BlockOnOutdatedBranch
- err = models.UpdateProtectBranch(ctx.Repo.Repository, protectBranch, models.WhitelistOptions{
+ err = models.UpdateProtectBranch(ctx, ctx.Repo.Repository, protectBranch, models.WhitelistOptions{
UserIDs: whitelistUsers,
TeamIDs: whitelistTeams,
MergeUserIDs: mergeWhitelistUsers,