diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2023-07-22 22:14:27 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-22 22:14:27 +0800 |
commit | b167f35113e643ccdb17a2dde55bdec5960b284b (patch) | |
tree | 99a6e53bf1a9d4c9199c19113650cc48a8c1fd0e /modules | |
parent | c42b71877edb4830b9573101d20853222d66fb3c (diff) | |
download | gitea-b167f35113e643ccdb17a2dde55bdec5960b284b.tar.gz gitea-b167f35113e643ccdb17a2dde55bdec5960b284b.zip |
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.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/context/permission.go | 2 | ||||
-rw-r--r-- | modules/context/repo.go | 12 |
2 files changed, 7 insertions, 7 deletions
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, |