aboutsummaryrefslogtreecommitdiffstats
path: root/models/perm/access/repo_permission.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-05-20 22:08:52 +0800
committerGitHub <noreply@github.com>2022-05-20 22:08:52 +0800
commitfd7d83ace60258acf7139c4c787aa8af75b7ba8c (patch)
tree50038348ec10485f72344f3ac80324e04abc1283 /models/perm/access/repo_permission.go
parentd81e31ad7826a81fc7139f329f250594610a274b (diff)
downloadgitea-fd7d83ace60258acf7139c4c787aa8af75b7ba8c.tar.gz
gitea-fd7d83ace60258acf7139c4c787aa8af75b7ba8c.zip
Move almost all functions' parameter db.Engine to context.Context (#19748)
* Move almost all functions' parameter db.Engine to context.Context * remove some unnecessary wrap functions
Diffstat (limited to 'models/perm/access/repo_permission.go')
-rw-r--r--models/perm/access/repo_permission.go18
1 files changed, 5 insertions, 13 deletions
diff --git a/models/perm/access/repo_permission.go b/models/perm/access/repo_permission.go
index 090c78ff2c..6bc1c82703 100644
--- a/models/perm/access/repo_permission.go
+++ b/models/perm/access/repo_permission.go
@@ -168,8 +168,6 @@ func GetUserRepoPermission(ctx context.Context, repo *repo_model.Repository, use
return
}
- e := db.GetEngine(ctx)
-
var is bool
if user != nil {
is, err = repo_model.IsCollaborator(ctx, repo.ID, user.ID)
@@ -208,7 +206,7 @@ func GetUserRepoPermission(ctx context.Context, repo *repo_model.Repository, use
}
// plain user
- perm.AccessMode, err = accessLevel(e, user, repo)
+ perm.AccessMode, err = accessLevel(ctx, user, repo)
if err != nil {
return
}
@@ -288,7 +286,7 @@ func IsUserRealRepoAdmin(repo *repo_model.Repository, user *user_model.User) (bo
return false, err
}
- accessMode, err := accessLevel(db.GetEngine(db.DefaultContext), user, repo)
+ accessMode, err := accessLevel(db.DefaultContext, user, repo)
if err != nil {
return false, err
}
@@ -297,12 +295,7 @@ func IsUserRealRepoAdmin(repo *repo_model.Repository, user *user_model.User) (bo
}
// IsUserRepoAdmin return true if user has admin right of a repo
-func IsUserRepoAdmin(repo *repo_model.Repository, user *user_model.User) (bool, error) {
- return IsUserRepoAdminCtx(db.DefaultContext, repo, user)
-}
-
-// IsUserRepoAdminCtx return true if user has admin right of a repo
-func IsUserRepoAdminCtx(ctx context.Context, repo *repo_model.Repository, user *user_model.User) (bool, error) {
+func IsUserRepoAdmin(ctx context.Context, repo *repo_model.Repository, user *user_model.User) (bool, error) {
if user == nil || repo == nil {
return false, nil
}
@@ -310,8 +303,7 @@ func IsUserRepoAdminCtx(ctx context.Context, repo *repo_model.Repository, user *
return true, nil
}
- e := db.GetEngine(ctx)
- mode, err := accessLevel(e, user, repo)
+ mode, err := accessLevel(ctx, user, repo)
if err != nil {
return false, err
}
@@ -377,7 +369,7 @@ func HasAccess(ctx context.Context, userID int64, repo *repo_model.Repository) (
var user *user_model.User
var err error
if userID > 0 {
- user, err = user_model.GetUserByIDEngine(db.GetEngine(ctx), userID)
+ user, err = user_model.GetUserByIDCtx(ctx, userID)
if err != nil {
return false, err
}