From cbd45471b1100bffcd2f18719b56a5da5468756b Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 11 May 2022 18:09:36 +0800 Subject: Move access and repo permission to models/perm/access (#19350) * Move access and repo permission to models/perm/access * Remove unnecessary code --- routers/private/hook_pre_receive.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'routers/private/hook_pre_receive.go') diff --git a/routers/private/hook_pre_receive.go b/routers/private/hook_pre_receive.go index d2203a1f99..9d3d665264 100644 --- a/routers/private/hook_pre_receive.go +++ b/routers/private/hook_pre_receive.go @@ -14,6 +14,7 @@ import ( "code.gitea.io/gitea/models" asymkey_model "code.gitea.io/gitea/models/asymkey" perm_model "code.gitea.io/gitea/models/perm" + access_model "code.gitea.io/gitea/models/perm/access" "code.gitea.io/gitea/models/unit" user_model "code.gitea.io/gitea/models/user" gitea_context "code.gitea.io/gitea/modules/context" @@ -30,7 +31,7 @@ type preReceiveContext struct { // loadedPusher indicates that where the following information are loaded loadedPusher bool user *user_model.User // it's the org user if a DeployKey is used - userPerm models.Permission + userPerm access_model.Permission deployKeyAccessMode perm_model.AccessMode canCreatePullRequest bool @@ -55,7 +56,7 @@ func (ctx *preReceiveContext) CanWriteCode() bool { if !ctx.loadPusherAndPermission() { return false } - ctx.canWriteCode = ctx.userPerm.CanWriteToBranch(ctx.user, ctx.branchName) || ctx.deployKeyAccessMode >= perm_model.AccessModeWrite + ctx.canWriteCode = models.CanMaintainerWriteToBranch(ctx.userPerm, ctx.branchName, ctx.user) || ctx.deployKeyAccessMode >= perm_model.AccessModeWrite ctx.checkedCanWriteCode = true } return ctx.canWriteCode @@ -472,7 +473,7 @@ func (ctx *preReceiveContext) loadPusherAndPermission() bool { } ctx.user = user - userPerm, err := models.GetUserRepoPermission(ctx, ctx.Repo.Repository, user) + userPerm, err := access_model.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{ -- cgit v1.2.3