From b167f35113e643ccdb17a2dde55bdec5960b284b Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 22 Jul 2023 22:14:27 +0800 Subject: Add context parameter to some database functions (#26055) To avoid deadlock problem, almost database related functions should be have ctx as the first parameter. This PR do a refactor for some of these functions. --- modules/context/permission.go | 2 +- modules/context/repo.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'modules') diff --git a/modules/context/permission.go b/modules/context/permission.go index 09343b8b50..14a9801dcc 100644 --- a/modules/context/permission.go +++ b/modules/context/permission.go @@ -35,7 +35,7 @@ func RequireRepoWriter(unitType unit.Type) func(ctx *Context) { // CanEnableEditor checks if the user is allowed to write to the branch of the repo func CanEnableEditor() func(ctx *Context) { return func(ctx *Context) { - if !ctx.Repo.CanWriteToBranch(ctx.Doer, ctx.Repo.BranchName) { + if !ctx.Repo.CanWriteToBranch(ctx, ctx.Doer, ctx.Repo.BranchName) { ctx.NotFound("CanWriteToBranch denies permission", nil) return } diff --git a/modules/context/repo.go b/modules/context/repo.go index 2c67735c93..f5c56cf833 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -66,13 +66,13 @@ type Repository struct { } // CanWriteToBranch checks if the branch is writable by the user -func (r *Repository) CanWriteToBranch(user *user_model.User, branch string) bool { - return issues_model.CanMaintainerWriteToBranch(r.Permission, branch, user) +func (r *Repository) CanWriteToBranch(ctx context.Context, user *user_model.User, branch string) bool { + return issues_model.CanMaintainerWriteToBranch(ctx, r.Permission, branch, user) } // CanEnableEditor returns true if repository is editable and user has proper access level. -func (r *Repository) CanEnableEditor(user *user_model.User) bool { - return r.IsViewBranch && r.CanWriteToBranch(user, r.BranchName) && r.Repository.CanEnableEditor() && !r.Repository.IsArchived +func (r *Repository) CanEnableEditor(ctx context.Context, user *user_model.User) bool { + return r.IsViewBranch && r.CanWriteToBranch(ctx, user, r.BranchName) && r.Repository.CanEnableEditor() && !r.Repository.IsArchived } // CanCreateBranch returns true if repository is editable and user has proper access level. @@ -118,7 +118,7 @@ func (r *Repository) CanCommitToBranch(ctx context.Context, doer *user_model.Use sign, keyID, _, err := asymkey_service.SignCRUDAction(ctx, r.Repository.RepoPath(), doer, r.Repository.RepoPath(), git.BranchPrefix+r.BranchName) - canCommit := r.CanEnableEditor(doer) && userCanPush + canCommit := r.CanEnableEditor(ctx, doer) && userCanPush if requireSigned { canCommit = canCommit && sign } @@ -134,7 +134,7 @@ func (r *Repository) CanCommitToBranch(ctx context.Context, doer *user_model.Use return CanCommitToBranchResults{ CanCommitToBranch: canCommit, - EditorEnabled: r.CanEnableEditor(doer), + EditorEnabled: r.CanEnableEditor(ctx, doer), UserCanPush: userCanPush, RequireSigned: requireSigned, WillSign: sign, -- cgit v1.2.3