aboutsummaryrefslogtreecommitdiffstats
path: root/modules/convert
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-05-11 18:09:36 +0800
committerGitHub <noreply@github.com>2022-05-11 12:09:36 +0200
commitcbd45471b1100bffcd2f18719b56a5da5468756b (patch)
tree11fcb818fd4e9d7b6bdb97d1b5bfbe2ed3df5747 /modules/convert
parent8e8e936adacea873013b89d534f60207e67f2b05 (diff)
downloadgitea-cbd45471b1100bffcd2f18719b56a5da5468756b.tar.gz
gitea-cbd45471b1100bffcd2f18719b56a5da5468756b.zip
Move access and repo permission to models/perm/access (#19350)
* Move access and repo permission to models/perm/access * Remove unnecessary code
Diffstat (limited to 'modules/convert')
-rw-r--r--modules/convert/convert.go9
-rw-r--r--modules/convert/package.go4
-rw-r--r--modules/convert/pull.go5
3 files changed, 10 insertions, 8 deletions
diff --git a/modules/convert/convert.go b/modules/convert/convert.go
index 3a12ed8f1f..74ede47cef 100644
--- a/modules/convert/convert.go
+++ b/modules/convert/convert.go
@@ -17,6 +17,7 @@ import (
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/organization"
"code.gitea.io/gitea/models/perm"
+ access_model "code.gitea.io/gitea/models/perm/access"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
@@ -44,16 +45,16 @@ func ToBranch(repo *repo_model.Repository, b *git.Branch, c *git.Commit, bp *mod
var canPush bool
var err error
if user != nil {
- hasPerm, err = models.HasAccessUnit(user, repo, unit.TypeCode, perm.AccessModeWrite)
+ hasPerm, err = access_model.HasAccessUnit(db.DefaultContext, user, repo, unit.TypeCode, perm.AccessModeWrite)
if err != nil {
return nil, err
}
- perms, err := models.GetUserRepoPermission(db.DefaultContext, repo, user)
+ perms, err := access_model.GetUserRepoPermission(db.DefaultContext, repo, user)
if err != nil {
return nil, err
}
- canPush = perms.CanWriteToBranch(user, b.Name)
+ canPush = models.CanMaintainerWriteToBranch(perms, b.Name, user)
}
return &api.Branch{
@@ -82,7 +83,7 @@ func ToBranch(repo *repo_model.Repository, b *git.Branch, c *git.Commit, bp *mod
}
if user != nil {
- permission, err := models.GetUserRepoPermission(db.DefaultContext, repo, user)
+ permission, err := access_model.GetUserRepoPermission(db.DefaultContext, repo, user)
if err != nil {
return nil, err
}
diff --git a/modules/convert/package.go b/modules/convert/package.go
index a4ea41d522..9713cda48b 100644
--- a/modules/convert/package.go
+++ b/modules/convert/package.go
@@ -7,8 +7,8 @@ package convert
import (
"context"
- "code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/packages"
+ access_model "code.gitea.io/gitea/models/perm/access"
user_model "code.gitea.io/gitea/models/user"
api "code.gitea.io/gitea/modules/structs"
)
@@ -17,7 +17,7 @@ import (
func ToPackage(ctx context.Context, pd *packages.PackageDescriptor, doer *user_model.User) (*api.Package, error) {
var repo *api.Repository
if pd.Repository != nil {
- permission, err := models.GetUserRepoPermission(ctx, pd.Repository, doer)
+ permission, err := access_model.GetUserRepoPermission(ctx, pd.Repository, doer)
if err != nil {
return nil, err
}
diff --git a/modules/convert/pull.go b/modules/convert/pull.go
index a2f54270e4..310a7626c9 100644
--- a/modules/convert/pull.go
+++ b/modules/convert/pull.go
@@ -10,6 +10,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/perm"
+ access_model "code.gitea.io/gitea/models/perm/access"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
@@ -43,7 +44,7 @@ func ToAPIPullRequest(ctx context.Context, pr *models.PullRequest, doer *user_mo
return nil
}
- p, err := models.GetUserRepoPermission(ctx, pr.BaseRepo, doer)
+ p, err := access_model.GetUserRepoPermission(ctx, pr.BaseRepo, doer)
if err != nil {
log.Error("GetUserRepoPermission[%d]: %v", pr.BaseRepoID, err)
p.AccessMode = perm.AccessModeNone
@@ -132,7 +133,7 @@ func ToAPIPullRequest(ctx context.Context, pr *models.PullRequest, doer *user_mo
}
if pr.HeadRepo != nil && pr.Flow == models.PullRequestFlowGithub {
- p, err := models.GetUserRepoPermission(ctx, pr.HeadRepo, doer)
+ p, err := access_model.GetUserRepoPermission(ctx, pr.HeadRepo, doer)
if err != nil {
log.Error("GetUserRepoPermission[%d]: %v", pr.HeadRepoID, err)
p.AccessMode = perm.AccessModeNone