aboutsummaryrefslogtreecommitdiffstats
path: root/modules
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 /modules
parent24a8d54bfb908a2371cb808a5243b3290dd0664a (diff)
downloadgitea-1fee11d69a437ec7e68b3f6b645827592fe77292.tar.gz
gitea-1fee11d69a437ec7e68b3f6b645827592fe77292.zip
Move accessmode into models/perm (#17828)
Diffstat (limited to 'modules')
-rw-r--r--modules/context/org.go3
-rw-r--r--modules/convert/convert.go5
-rw-r--r--modules/convert/notification.go3
-rw-r--r--modules/convert/pull.go13
-rw-r--r--modules/convert/pull_test.go3
-rw-r--r--modules/convert/repository.go11
-rw-r--r--modules/convert/user.go6
-rw-r--r--modules/notification/webhook/webhook.go21
-rw-r--r--modules/private/serv.go3
-rw-r--r--modules/repository/create_test.go9
10 files changed, 43 insertions, 34 deletions
diff --git a/modules/context/org.go b/modules/context/org.go
index 2a3ebdd1e7..eb81f6644c 100644
--- a/modules/context/org.go
+++ b/modules/context/org.go
@@ -9,6 +9,7 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/perm"
user_model "code.gitea.io/gitea/models/user"
)
@@ -167,7 +168,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
return
}
- ctx.Org.IsTeamAdmin = ctx.Org.Team.IsOwnerTeam() || ctx.Org.Team.Authorize >= models.AccessModeAdmin
+ ctx.Org.IsTeamAdmin = ctx.Org.Team.IsOwnerTeam() || ctx.Org.Team.Authorize >= perm.AccessModeAdmin
ctx.Data["IsTeamAdmin"] = ctx.Org.IsTeamAdmin
if requireTeamAdmin && !ctx.Org.IsTeamAdmin {
ctx.NotFound("OrgAssignment", err)
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
diff --git a/modules/notification/webhook/webhook.go b/modules/notification/webhook/webhook.go
index bae9b78da0..378e7fd202 100644
--- a/modules/notification/webhook/webhook.go
+++ b/modules/notification/webhook/webhook.go
@@ -6,6 +6,7 @@ package webhook
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/models/webhook"
@@ -91,7 +92,7 @@ func (m *webhookNotifier) NotifyForkRepository(doer *user_model.User, oldRepo, r
if u.IsOrganization() {
if err := webhook_services.PrepareWebhooks(repo, webhook.HookEventRepository, &api.RepositoryPayload{
Action: api.HookRepoCreated,
- Repository: convert.ToRepo(repo, models.AccessModeOwner),
+ Repository: convert.ToRepo(repo, perm.AccessModeOwner),
Organization: convert.ToUser(u, nil),
Sender: convert.ToUser(doer, nil),
}); err != nil {
@@ -104,7 +105,7 @@ func (m *webhookNotifier) NotifyCreateRepository(doer *user_model.User, u *user_
// Add to hook queue for created repo after session commit.
if err := webhook_services.PrepareWebhooks(repo, webhook.HookEventRepository, &api.RepositoryPayload{
Action: api.HookRepoCreated,
- Repository: convert.ToRepo(repo, models.AccessModeOwner),
+ Repository: convert.ToRepo(repo, perm.AccessModeOwner),
Organization: convert.ToUser(u, nil),
Sender: convert.ToUser(doer, nil),
}); err != nil {
@@ -117,7 +118,7 @@ func (m *webhookNotifier) NotifyDeleteRepository(doer *user_model.User, repo *mo
if err := webhook_services.PrepareWebhooks(repo, webhook.HookEventRepository, &api.RepositoryPayload{
Action: api.HookRepoDeleted,
- Repository: convert.ToRepo(repo, models.AccessModeOwner),
+ Repository: convert.ToRepo(repo, perm.AccessModeOwner),
Organization: convert.ToUser(u, nil),
Sender: convert.ToUser(doer, nil),
}); err != nil {
@@ -129,7 +130,7 @@ func (m *webhookNotifier) NotifyMigrateRepository(doer *user_model.User, u *user
// Add to hook queue for created repo after session commit.
if err := webhook_services.PrepareWebhooks(repo, webhook.HookEventRepository, &api.RepositoryPayload{
Action: api.HookRepoCreated,
- Repository: convert.ToRepo(repo, models.AccessModeOwner),
+ Repository: convert.ToRepo(repo, perm.AccessModeOwner),
Organization: convert.ToUser(u, nil),
Sender: convert.ToUser(doer, nil),
}); err != nil {
@@ -504,7 +505,7 @@ func (m *webhookNotifier) NotifyIssueChangeLabels(doer *user_model.User, issue *
Action: api.HookIssueLabelUpdated,
Index: issue.Index,
PullRequest: convert.ToAPIPullRequest(issue.PullRequest, nil),
- Repository: convert.ToRepo(issue.Repo, models.AccessModeNone),
+ Repository: convert.ToRepo(issue.Repo, perm.AccessModeNone),
Sender: convert.ToUser(doer, nil),
})
} else {
@@ -578,7 +579,7 @@ func (m *webhookNotifier) NotifyPushCommits(pusher *user_model.User, repo *model
CompareURL: setting.AppURL + commits.CompareURL,
Commits: apiCommits,
HeadCommit: apiHeadCommit,
- Repo: convert.ToRepo(repo, models.AccessModeOwner),
+ Repo: convert.ToRepo(repo, perm.AccessModeOwner),
Pusher: apiPusher,
Sender: apiPusher,
}); err != nil {
@@ -698,7 +699,7 @@ func (m *webhookNotifier) NotifyPullRequestReview(pr *models.PullRequest, review
func (m *webhookNotifier) NotifyCreateRef(pusher *user_model.User, repo *models.Repository, refType, refFullName string) {
apiPusher := convert.ToUser(pusher, nil)
- apiRepo := convert.ToRepo(repo, models.AccessModeNone)
+ apiRepo := convert.ToRepo(repo, perm.AccessModeNone)
refName := git.RefEndName(refFullName)
gitRepo, err := git.OpenRepository(repo.RepoPath())
@@ -740,7 +741,7 @@ func (m *webhookNotifier) NotifyPullRequestSynchronized(doer *user_model.User, p
Action: api.HookIssueSynchronized,
Index: pr.Issue.Index,
PullRequest: convert.ToAPIPullRequest(pr, nil),
- Repository: convert.ToRepo(pr.Issue.Repo, models.AccessModeNone),
+ Repository: convert.ToRepo(pr.Issue.Repo, perm.AccessModeNone),
Sender: convert.ToUser(doer, nil),
}); err != nil {
log.Error("PrepareWebhooks [pull_id: %v]: %v", pr.ID, err)
@@ -749,7 +750,7 @@ func (m *webhookNotifier) NotifyPullRequestSynchronized(doer *user_model.User, p
func (m *webhookNotifier) NotifyDeleteRef(pusher *user_model.User, repo *models.Repository, refType, refFullName string) {
apiPusher := convert.ToUser(pusher, nil)
- apiRepo := convert.ToRepo(repo, models.AccessModeNone)
+ apiRepo := convert.ToRepo(repo, perm.AccessModeNone)
refName := git.RefEndName(refFullName)
if err := webhook_services.PrepareWebhooks(repo, webhook.HookEventDelete, &api.DeletePayload{
@@ -807,7 +808,7 @@ func (m *webhookNotifier) NotifySyncPushCommits(pusher *user_model.User, repo *m
CompareURL: setting.AppURL + commits.CompareURL,
Commits: apiCommits,
HeadCommit: apiHeadCommit,
- Repo: convert.ToRepo(repo, models.AccessModeOwner),
+ Repo: convert.ToRepo(repo, perm.AccessModeOwner),
Pusher: apiPusher,
Sender: apiPusher,
}); err != nil {
diff --git a/modules/private/serv.go b/modules/private/serv.go
index 7e4805d60c..4f5b19c597 100644
--- a/modules/private/serv.go
+++ b/modules/private/serv.go
@@ -11,6 +11,7 @@ import (
"net/url"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/perm"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/setting"
@@ -74,7 +75,7 @@ func IsErrServCommand(err error) bool {
}
// ServCommand preps for a serv call
-func ServCommand(ctx context.Context, keyID int64, ownerName, repoName string, mode models.AccessMode, verbs ...string) (*ServCommandResults, error) {
+func ServCommand(ctx context.Context, keyID int64, ownerName, repoName string, mode perm.AccessMode, verbs ...string) (*ServCommandResults, error) {
reqURL := setting.LocalURL + fmt.Sprintf("api/internal/serv/command/%d/%s/%s?mode=%d",
keyID,
url.PathEscape(ownerName),
diff --git a/modules/repository/create_test.go b/modules/repository/create_test.go
index d7d3281872..18995f4ecd 100644
--- a/modules/repository/create_test.go
+++ b/modules/repository/create_test.go
@@ -10,6 +10,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/perm"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/structs"
@@ -69,25 +70,25 @@ func TestIncludesAllRepositoriesTeams(t *testing.T) {
{
OrgID: org.ID,
Name: "team one",
- Authorize: models.AccessModeRead,
+ Authorize: perm.AccessModeRead,
IncludesAllRepositories: true,
},
{
OrgID: org.ID,
Name: "team 2",
- Authorize: models.AccessModeRead,
+ Authorize: perm.AccessModeRead,
IncludesAllRepositories: false,
},
{
OrgID: org.ID,
Name: "team three",
- Authorize: models.AccessModeWrite,
+ Authorize: perm.AccessModeWrite,
IncludesAllRepositories: true,
},
{
OrgID: org.ID,
Name: "team 4",
- Authorize: models.AccessModeWrite,
+ Authorize: perm.AccessModeWrite,
IncludesAllRepositories: false,
},
}