diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-11-28 19:58:28 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-28 12:58:28 +0100 |
commit | 1fee11d69a437ec7e68b3f6b645827592fe77292 (patch) | |
tree | 1fca452f96746d9f7cc8c31723e3c365155cf96d /modules/convert | |
parent | 24a8d54bfb908a2371cb808a5243b3290dd0664a (diff) | |
download | gitea-1fee11d69a437ec7e68b3f6b645827592fe77292.tar.gz gitea-1fee11d69a437ec7e68b3f6b645827592fe77292.zip |
Move accessmode into models/perm (#17828)
Diffstat (limited to 'modules/convert')
-rw-r--r-- | modules/convert/convert.go | 5 | ||||
-rw-r--r-- | modules/convert/notification.go | 3 | ||||
-rw-r--r-- | modules/convert/pull.go | 13 | ||||
-rw-r--r-- | modules/convert/pull_test.go | 3 | ||||
-rw-r--r-- | modules/convert/repository.go | 11 | ||||
-rw-r--r-- | modules/convert/user.go | 6 |
6 files changed, 23 insertions, 18 deletions
diff --git a/modules/convert/convert.go b/modules/convert/convert.go index f08a62588e..8c6a610625 100644 --- a/modules/convert/convert.go +++ b/modules/convert/convert.go @@ -13,6 +13,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/login" + "code.gitea.io/gitea/models/perm" "code.gitea.io/gitea/models/unit" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/models/webhook" @@ -38,7 +39,7 @@ func ToBranch(repo *models.Repository, b *git.Branch, c *git.Commit, bp *models. var hasPerm bool var err error if user != nil { - hasPerm, err = models.HasAccessUnit(user, repo, unit.TypeCode, models.AccessModeWrite) + hasPerm, err = models.HasAccessUnit(user, repo, unit.TypeCode, perm.AccessModeWrite) if err != nil { return nil, err } @@ -272,7 +273,7 @@ func ToDeployKey(apiLink string, key *models.DeployKey) *api.DeployKey { URL: fmt.Sprintf("%s%d", apiLink, key.ID), Title: key.Name, Created: key.CreatedUnix.AsTime(), - ReadOnly: key.Mode == models.AccessModeRead, // All deploy keys are read-only. + ReadOnly: key.Mode == perm.AccessModeRead, // All deploy keys are read-only. } } diff --git a/modules/convert/notification.go b/modules/convert/notification.go index 5f4fef02b9..a0bd4cdc27 100644 --- a/modules/convert/notification.go +++ b/modules/convert/notification.go @@ -8,6 +8,7 @@ import ( "net/url" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/perm" api "code.gitea.io/gitea/modules/structs" ) @@ -23,7 +24,7 @@ func ToNotificationThread(n *models.Notification) *api.NotificationThread { //since user only get notifications when he has access to use minimal access mode if n.Repository != nil { - result.Repository = ToRepo(n.Repository, models.AccessModeRead) + result.Repository = ToRepo(n.Repository, perm.AccessModeRead) } //handle Subject diff --git a/modules/convert/pull.go b/modules/convert/pull.go index f892107f4b..ea1e4bb3c2 100644 --- a/modules/convert/pull.go +++ b/modules/convert/pull.go @@ -8,6 +8,7 @@ import ( "fmt" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/perm" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" @@ -41,10 +42,10 @@ func ToAPIPullRequest(pr *models.PullRequest, doer *user_model.User) *api.PullRe return nil } - perm, err := models.GetUserRepoPermission(pr.BaseRepo, doer) + p, err := models.GetUserRepoPermission(pr.BaseRepo, doer) if err != nil { log.Error("GetUserRepoPermission[%d]: %v", pr.BaseRepoID, err) - perm.AccessMode = models.AccessModeNone + p.AccessMode = perm.AccessModeNone } apiPullRequest := &api.PullRequest{ @@ -74,7 +75,7 @@ func ToAPIPullRequest(pr *models.PullRequest, doer *user_model.User) *api.PullRe Name: pr.BaseBranch, Ref: pr.BaseBranch, RepoID: pr.BaseRepoID, - Repository: ToRepo(pr.BaseRepo, perm.AccessMode), + Repository: ToRepo(pr.BaseRepo, p.AccessMode), }, Head: &api.PRBranchInfo{ Name: pr.HeadBranch, @@ -127,14 +128,14 @@ func ToAPIPullRequest(pr *models.PullRequest, doer *user_model.User) *api.PullRe } if pr.HeadRepo != nil && pr.Flow == models.PullRequestFlowGithub { - perm, err := models.GetUserRepoPermission(pr.HeadRepo, doer) + p, err := models.GetUserRepoPermission(pr.HeadRepo, doer) if err != nil { log.Error("GetUserRepoPermission[%d]: %v", pr.HeadRepoID, err) - perm.AccessMode = models.AccessModeNone + p.AccessMode = perm.AccessModeNone } apiPullRequest.Head.RepoID = pr.HeadRepo.ID - apiPullRequest.Head.Repository = ToRepo(pr.HeadRepo, perm.AccessMode) + apiPullRequest.Head.Repository = ToRepo(pr.HeadRepo, p.AccessMode) headGitRepo, err := git.OpenRepository(pr.HeadRepo.RepoPath()) if err != nil { diff --git a/modules/convert/pull_test.go b/modules/convert/pull_test.go index 844011b8cc..1bac5d3a4a 100644 --- a/modules/convert/pull_test.go +++ b/modules/convert/pull_test.go @@ -8,6 +8,7 @@ import ( "testing" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/perm" "code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/modules/structs" @@ -28,7 +29,7 @@ func TestPullRequest_APIFormat(t *testing.T) { Ref: "refs/pull/2/head", Sha: "4a357436d925b5c974181ff12a994538ddc5a269", RepoID: 1, - Repository: ToRepo(headRepo, models.AccessModeRead), + Repository: ToRepo(headRepo, perm.AccessModeRead), }, apiPullRequest.Head) //withOut HeadRepo diff --git a/modules/convert/repository.go b/modules/convert/repository.go index bb8217908d..46b2745b34 100644 --- a/modules/convert/repository.go +++ b/modules/convert/repository.go @@ -6,23 +6,24 @@ package convert import ( "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/perm" unit_model "code.gitea.io/gitea/models/unit" api "code.gitea.io/gitea/modules/structs" ) // ToRepo converts a Repository to api.Repository -func ToRepo(repo *models.Repository, mode models.AccessMode) *api.Repository { +func ToRepo(repo *models.Repository, mode perm.AccessMode) *api.Repository { return innerToRepo(repo, mode, false) } -func innerToRepo(repo *models.Repository, mode models.AccessMode, isParent bool) *api.Repository { +func innerToRepo(repo *models.Repository, mode perm.AccessMode, isParent bool) *api.Repository { var parent *api.Repository cloneLink := repo.CloneLink() permission := &api.Permission{ - Admin: mode >= models.AccessModeAdmin, - Push: mode >= models.AccessModeWrite, - Pull: mode >= models.AccessModeRead, + Admin: mode >= perm.AccessModeAdmin, + Push: mode >= perm.AccessModeWrite, + Pull: mode >= perm.AccessModeRead, } if !isParent { err := repo.GetBaseRepo() diff --git a/modules/convert/user.go b/modules/convert/user.go index ebe2f06460..dc4a8c49c7 100644 --- a/modules/convert/user.go +++ b/modules/convert/user.go @@ -5,7 +5,7 @@ package convert import ( - "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/perm" user_model "code.gitea.io/gitea/models/user" api "code.gitea.io/gitea/modules/structs" ) @@ -36,11 +36,11 @@ func ToUsers(doer *user_model.User, users []*user_model.User) []*api.User { // ToUserWithAccessMode convert user_model.User to api.User // AccessMode is not none show add some more information -func ToUserWithAccessMode(user *user_model.User, accessMode models.AccessMode) *api.User { +func ToUserWithAccessMode(user *user_model.User, accessMode perm.AccessMode) *api.User { if user == nil { return nil } - return toUser(user, accessMode != models.AccessModeNone, false) + return toUser(user, accessMode != perm.AccessModeNone, false) } // toUser convert user_model.User to api.User |