summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorSandro Santilli <strk@kbt.io>2016-11-07 17:20:37 +0100
committerSandro Santilli <strk@kbt.io>2016-11-07 17:20:37 +0100
commitf388661bda8097b5ff01548e6153c566690c9b5e (patch)
treed0bdf0785474f50eb42b6b4852922201620221cf /models
parent0b62aeb495c9c1daf816a754a0e4abbf8c62c2c0 (diff)
downloadgitea-f388661bda8097b5ff01548e6153c566690c9b5e.tar.gz
gitea-f388661bda8097b5ff01548e6153c566690c9b5e.zip
ACCESS_MODE_* -> AccessMode*
Diffstat (limited to 'models')
-rw-r--r--models/access.go38
-rw-r--r--models/issue.go2
-rw-r--r--models/org.go2
-rw-r--r--models/org_team.go2
-rw-r--r--models/repo.go4
-rw-r--r--models/repo_collaboration.go10
-rw-r--r--models/ssh_key.go6
-rw-r--r--models/user.go6
8 files changed, 35 insertions, 35 deletions
diff --git a/models/access.go b/models/access.go
index e46819f2d4..fa3642cf53 100644
--- a/models/access.go
+++ b/models/access.go
@@ -13,22 +13,22 @@ import (
type AccessMode int
const (
- ACCESS_MODE_NONE AccessMode = iota // 0
- ACCESS_MODE_READ // 1
- ACCESS_MODE_WRITE // 2
- ACCESS_MODE_ADMIN // 3
- ACCESS_MODE_OWNER // 4
+ AccessModeNone AccessMode = iota // 0
+ AccessModeRead // 1
+ AccessModeWrite // 2
+ AccessModeAdmin // 3
+ AccessModeOwner // 4
)
func (mode AccessMode) String() string {
switch mode {
- case ACCESS_MODE_READ:
+ case AccessModeRead:
return "read"
- case ACCESS_MODE_WRITE:
+ case AccessModeWrite:
return "write"
- case ACCESS_MODE_ADMIN:
+ case AccessModeAdmin:
return "admin"
- case ACCESS_MODE_OWNER:
+ case AccessModeOwner:
return "owner"
default:
return "none"
@@ -39,11 +39,11 @@ func (mode AccessMode) String() string {
func ParseAccessMode(permission string) AccessMode {
switch permission {
case "write":
- return ACCESS_MODE_WRITE
+ return AccessModeWrite
case "admin":
- return ACCESS_MODE_ADMIN
+ return AccessModeAdmin
default:
- return ACCESS_MODE_READ
+ return AccessModeRead
}
}
@@ -58,9 +58,9 @@ type Access struct {
}
func accessLevel(e Engine, u *User, repo *Repository) (AccessMode, error) {
- mode := ACCESS_MODE_NONE
+ mode := AccessModeNone
if !repo.IsPrivate {
- mode = ACCESS_MODE_READ
+ mode = AccessModeRead
}
if u == nil {
@@ -68,7 +68,7 @@ func accessLevel(e Engine, u *User, repo *Repository) (AccessMode, error) {
}
if u.ID == repo.OwnerID {
- return ACCESS_MODE_OWNER, nil
+ return AccessModeOwner, nil
}
a := &Access{UserID: u.ID, RepoID: repo.ID}
@@ -135,7 +135,7 @@ func (user *User) GetAccessibleRepositories(limit int) (repos []*Repository, _ e
}
func maxAccessMode(modes ...AccessMode) AccessMode {
- max := ACCESS_MODE_NONE
+ max := AccessModeNone
for _, mode := range modes {
if mode > max {
max = mode
@@ -146,9 +146,9 @@ func maxAccessMode(modes ...AccessMode) AccessMode {
// FIXME: do corss-comparison so reduce deletions and additions to the minimum?
func (repo *Repository) refreshAccesses(e Engine, accessMap map[int64]AccessMode) (err error) {
- minMode := ACCESS_MODE_READ
+ minMode := AccessModeRead
if !repo.IsPrivate {
- minMode = ACCESS_MODE_WRITE
+ minMode = AccessModeWrite
}
newAccesses := make([]Access, 0, len(accessMap))
@@ -212,7 +212,7 @@ func (repo *Repository) recalculateTeamAccesses(e Engine, ignTeamID int64) (err
// Owner team gets owner access, and skip for teams that do not
// have relations with repository.
if t.IsOwnerTeam() {
- t.Authorize = ACCESS_MODE_OWNER
+ t.Authorize = AccessModeOwner
} else if !t.hasRepository(e, repo.ID) {
continue
}
diff --git a/models/issue.go b/models/issue.go
index 06b8183a47..a331883c4f 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -624,7 +624,7 @@ func newIssue(e *xorm.Session, opts NewIssueOptions) (err error) {
// Assume assignee is invalid and drop silently.
opts.Issue.AssigneeID = 0
if assignee != nil {
- valid, err := hasAccess(e, assignee, opts.Repo, ACCESS_MODE_WRITE)
+ valid, err := hasAccess(e, assignee, opts.Repo, AccessModeWrite)
if err != nil {
return fmt.Errorf("hasAccess [user_id: %d, repo_id: %d]: %v", assignee.ID, opts.Repo.ID, err)
}
diff --git a/models/org.go b/models/org.go
index ec54081857..42470dce70 100644
--- a/models/org.go
+++ b/models/org.go
@@ -141,7 +141,7 @@ func CreateOrganization(org, owner *User) (err error) {
OrgID: org.ID,
LowerName: strings.ToLower(OWNER_TEAM),
Name: OWNER_TEAM,
- Authorize: ACCESS_MODE_OWNER,
+ Authorize: AccessModeOwner,
NumMembers: 1,
}
if _, err = sess.Insert(t); err != nil {
diff --git a/models/org_team.go b/models/org_team.go
index 07a90e08f1..b0796248a5 100644
--- a/models/org_team.go
+++ b/models/org_team.go
@@ -155,7 +155,7 @@ func (t *Team) removeRepository(e Engine, repo *Repository, recalculate bool) (e
return fmt.Errorf("get team members: %v", err)
}
for _, u := range t.Members {
- has, err := hasAccess(e, u, repo, ACCESS_MODE_READ)
+ has, err := hasAccess(e, u, repo, AccessModeRead)
if err != nil {
return err
} else if has {
diff --git a/models/repo.go b/models/repo.go
index 6ae7d9a25b..bf34e97d09 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -334,7 +334,7 @@ func (repo *Repository) getAssignees(e Engine) (_ []*User, err error) {
}
accesses := make([]*Access, 0, 10)
- if err = e.Where("repo_id = ? AND mode >= ?", repo.ID, ACCESS_MODE_WRITE).Find(&accesses); err != nil {
+ if err = e.Where("repo_id = ? AND mode >= ?", repo.ID, AccessModeWrite).Find(&accesses); err != nil {
return nil, err
}
@@ -418,7 +418,7 @@ func (repo *Repository) ComposeCompareURL(oldCommitID, newCommitID string) strin
}
func (repo *Repository) HasAccess(u *User) bool {
- has, _ := HasAccess(u, repo, ACCESS_MODE_READ)
+ has, _ := HasAccess(u, repo, AccessModeRead)
return has
}
diff --git a/models/repo_collaboration.go b/models/repo_collaboration.go
index f4b23f9ebe..214aa2a015 100644
--- a/models/repo_collaboration.go
+++ b/models/repo_collaboration.go
@@ -18,11 +18,11 @@ type Collaboration struct {
func (c *Collaboration) ModeI18nKey() string {
switch c.Mode {
- case ACCESS_MODE_READ:
+ case AccessModeRead:
return "repo.settings.collaboration.read"
- case ACCESS_MODE_WRITE:
+ case AccessModeWrite:
return "repo.settings.collaboration.write"
- case ACCESS_MODE_ADMIN:
+ case AccessModeAdmin:
return "repo.settings.collaboration.admin"
default:
return "repo.settings.collaboration.undefined"
@@ -42,7 +42,7 @@ func (repo *Repository) AddCollaborator(u *User) error {
} else if has {
return nil
}
- collaboration.Mode = ACCESS_MODE_WRITE
+ collaboration.Mode = AccessModeWrite
sess := x.NewSession()
defer sessionRelease(sess)
@@ -105,7 +105,7 @@ func (repo *Repository) GetCollaborators() ([]*Collaborator, error) {
// ChangeCollaborationAccessMode sets new access mode for the collaboration.
func (repo *Repository) ChangeCollaborationAccessMode(uid int64, mode AccessMode) error {
// Discard invalid input
- if mode <= ACCESS_MODE_NONE || mode > ACCESS_MODE_OWNER {
+ if mode <= AccessModeNone || mode > AccessModeOwner {
return nil
}
diff --git a/models/ssh_key.go b/models/ssh_key.go
index 77adce9f3b..08483b83d2 100644
--- a/models/ssh_key.go
+++ b/models/ssh_key.go
@@ -415,7 +415,7 @@ func AddPublicKey(ownerID int64, name, content string) (*PublicKey, error) {
OwnerID: ownerID,
Name: name,
Content: content,
- Mode: ACCESS_MODE_WRITE,
+ Mode: AccessModeWrite,
Type: KEY_TYPE_USER,
}
if err = addKey(sess, key); err != nil {
@@ -642,7 +642,7 @@ func AddDeployKey(repoID int64, name, content string) (*DeployKey, error) {
pkey := &PublicKey{
Content: content,
- Mode: ACCESS_MODE_READ,
+ Mode: AccessModeRead,
Type: KEY_TYPE_DEPLOY,
}
has, err := x.Get(pkey)
@@ -720,7 +720,7 @@ func DeleteDeployKey(doer *User, id int64) error {
if err != nil {
return fmt.Errorf("GetRepositoryByID: %v", err)
}
- yes, err := HasAccess(doer, repo, ACCESS_MODE_ADMIN)
+ yes, err := HasAccess(doer, repo, AccessModeAdmin)
if err != nil {
return fmt.Errorf("HasAccess: %v", err)
} else if !yes {
diff --git a/models/user.go b/models/user.go
index ffa2f6440f..dcb2311cf6 100644
--- a/models/user.go
+++ b/models/user.go
@@ -375,7 +375,7 @@ func (u *User) DeleteAvatar() error {
// IsAdminOfRepo returns true if user has admin or higher access of repository.
func (u *User) IsAdminOfRepo(repo *Repository) bool {
- has, err := HasAccess(u, repo, ACCESS_MODE_ADMIN)
+ has, err := HasAccess(u, repo, AccessModeAdmin)
if err != nil {
log.Error(3, "HasAccess: %v", err)
}
@@ -384,7 +384,7 @@ func (u *User) IsAdminOfRepo(repo *Repository) bool {
// IsWriterOfRepo returns true if user has write access to given repository.
func (u *User) IsWriterOfRepo(repo *Repository) bool {
- has, err := HasAccess(u, repo, ACCESS_MODE_WRITE)
+ has, err := HasAccess(u, repo, AccessModeWrite)
if err != nil {
log.Error(3, "HasAccess: %v", err)
}
@@ -886,7 +886,7 @@ func GetUserByID(id int64) (*User, error) {
// GetAssigneeByID returns the user with write access of repository by given ID.
func GetAssigneeByID(repo *Repository, userID int64) (*User, error) {
- has, err := HasAccess(&User{ID: userID}, repo, ACCESS_MODE_WRITE)
+ has, err := HasAccess(&User{ID: userID}, repo, AccessModeWrite)
if err != nil {
return nil, err
} else if !has {