summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-11-28 19:58:28 +0800
committerGitHub <noreply@github.com>2021-11-28 12:58:28 +0100
commit1fee11d69a437ec7e68b3f6b645827592fe77292 (patch)
tree1fca452f96746d9f7cc8c31723e3c365155cf96d /services
parent24a8d54bfb908a2371cb808a5243b3290dd0664a (diff)
downloadgitea-1fee11d69a437ec7e68b3f6b645827592fe77292.tar.gz
gitea-1fee11d69a437ec7e68b3f6b645827592fe77292.zip
Move accessmode into models/perm (#17828)
Diffstat (limited to 'services')
-rw-r--r--services/issue/assignee.go7
-rw-r--r--services/lfs/server.go11
-rw-r--r--services/repository/transfer.go3
3 files changed, 12 insertions, 9 deletions
diff --git a/services/issue/assignee.go b/services/issue/assignee.go
index 62d274a65f..14c040ad7a 100644
--- a/services/issue/assignee.go
+++ b/services/issue/assignee.go
@@ -6,6 +6,7 @@ package issue
import (
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/perm"
"code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/log"
@@ -111,7 +112,7 @@ func IsValidReviewRequest(reviewer, doer *user_model.User, isAdd bool, issue *mo
var pemResult bool
if isAdd {
- pemResult = permReviewer.CanAccessAny(models.AccessModeRead, unit.TypePullRequests)
+ pemResult = permReviewer.CanAccessAny(perm.AccessModeRead, unit.TypePullRequests)
if !pemResult {
return models.ErrNotValidReviewRequest{
Reason: "Reviewer can't read",
@@ -124,7 +125,7 @@ func IsValidReviewRequest(reviewer, doer *user_model.User, isAdd bool, issue *mo
return nil
}
- pemResult = permDoer.CanAccessAny(models.AccessModeWrite, unit.TypePullRequests)
+ pemResult = permDoer.CanAccessAny(perm.AccessModeWrite, unit.TypePullRequests)
if !pemResult {
pemResult, err = models.IsOfficialReviewer(issue, doer)
if err != nil {
@@ -201,7 +202,7 @@ func IsValidTeamReviewRequest(reviewer *models.Team, doer *user_model.User, isAd
}
}
- doerCanWrite := permission.CanAccessAny(models.AccessModeWrite, unit.TypePullRequests)
+ doerCanWrite := permission.CanAccessAny(perm.AccessModeWrite, unit.TypePullRequests)
if !doerCanWrite {
official, err := models.IsOfficialReviewer(issue, doer)
if err != nil {
diff --git a/services/lfs/server.go b/services/lfs/server.go
index 28756e4f19..2b0c8265c0 100644
--- a/services/lfs/server.go
+++ b/services/lfs/server.go
@@ -19,6 +19,7 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/perm"
"code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
@@ -480,9 +481,9 @@ func writeStatusMessage(ctx *context.Context, status int, message string) {
// authenticate uses the authorization string to determine whether
// or not to proceed. This server assumes an HTTP Basic auth format.
func authenticate(ctx *context.Context, repository *models.Repository, authorization string, requireSigned, requireWrite bool) bool {
- accessMode := models.AccessModeRead
+ accessMode := perm.AccessModeRead
if requireWrite {
- accessMode = models.AccessModeWrite
+ accessMode = perm.AccessModeWrite
}
// ctx.IsSigned is unnecessary here, this will be checked in perm.CanAccess
@@ -507,7 +508,7 @@ func authenticate(ctx *context.Context, repository *models.Repository, authoriza
return true
}
-func handleLFSToken(tokenSHA string, target *models.Repository, mode models.AccessMode) (*user_model.User, error) {
+func handleLFSToken(tokenSHA string, target *models.Repository, mode perm.AccessMode) (*user_model.User, error) {
if !strings.Contains(tokenSHA, ".") {
return nil, nil
}
@@ -530,7 +531,7 @@ func handleLFSToken(tokenSHA string, target *models.Repository, mode models.Acce
return nil, fmt.Errorf("invalid token claim")
}
- if mode == models.AccessModeWrite && claims.Op != "upload" {
+ if mode == perm.AccessModeWrite && claims.Op != "upload" {
return nil, fmt.Errorf("invalid token claim")
}
@@ -542,7 +543,7 @@ func handleLFSToken(tokenSHA string, target *models.Repository, mode models.Acce
return u, nil
}
-func parseToken(authorization string, target *models.Repository, mode models.AccessMode) (*user_model.User, error) {
+func parseToken(authorization string, target *models.Repository, mode perm.AccessMode) (*user_model.User, error) {
if authorization == "" {
return nil, fmt.Errorf("no token")
}
diff --git a/services/repository/transfer.go b/services/repository/transfer.go
index e6b73fc9e0..d6aea70ffd 100644
--- a/services/repository/transfer.go
+++ b/services/repository/transfer.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/notification"
"code.gitea.io/gitea/modules/sync"
@@ -104,7 +105,7 @@ func StartRepositoryTransfer(doer, newOwner *user_model.User, repo *models.Repos
if err := repo.AddCollaborator(newOwner); err != nil {
return err
}
- if err := repo.ChangeCollaborationAccessMode(newOwner.ID, models.AccessModeRead); err != nil {
+ if err := repo.ChangeCollaborationAccessMode(newOwner.ID, perm.AccessModeRead); err != nil {
return err
}
}