From f388661bda8097b5ff01548e6153c566690c9b5e Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Mon, 7 Nov 2016 17:20:37 +0100 Subject: [PATCH] ACCESS_MODE_* -> AccessMode* --- cmd/serve.go | 14 ++++++------- models/access.go | 38 ++++++++++++++++++------------------ models/issue.go | 2 +- models/org.go | 2 +- models/org_team.go | 2 +- models/repo.go | 4 ++-- models/repo_collaboration.go | 10 +++++----- models/ssh_key.go | 6 +++--- models/user.go | 6 +++--- modules/context/org.go | 2 +- modules/context/repo.go | 12 ++++++------ routers/api/v1/api.go | 2 +- routers/api/v1/repo/repo.go | 4 ++-- routers/org/teams.go | 6 +++--- routers/repo/http.go | 8 ++++---- 15 files changed, 59 insertions(+), 59 deletions(-) diff --git a/cmd/serve.go b/cmd/serve.go index eaaeeb7bc4dc..4e99ebe5ff85 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -64,9 +64,9 @@ func parseCmd(cmd string) (string, string) { var ( allowedCommands = map[string]models.AccessMode{ - "git-upload-pack": models.ACCESS_MODE_READ, - "git-upload-archive": models.ACCESS_MODE_READ, - "git-receive-pack": models.ACCESS_MODE_WRITE, + "git-upload-pack": models.AccessModeRead, + "git-upload-archive": models.AccessModeRead, + "git-receive-pack": models.AccessModeWrite, } ) @@ -191,7 +191,7 @@ func runServ(c *cli.Context) error { } // Prohibit push to mirror repositories. - if requestedMode > models.ACCESS_MODE_READ && repo.IsMirror { + if requestedMode > models.AccessModeRead && repo.IsMirror { fail("mirror repository is read-only", "") } @@ -200,7 +200,7 @@ func runServ(c *cli.Context) error { keyID int64 user *models.User ) - if requestedMode == models.ACCESS_MODE_WRITE || repo.IsPrivate { + if requestedMode == models.AccessModeWrite || repo.IsPrivate { keys := strings.Split(c.Args()[0], "-") if len(keys) != 2 { fail("Key ID format error", "Invalid key argument: %s", c.Args()[0]) @@ -243,7 +243,7 @@ func runServ(c *cli.Context) error { fail("Internal error", "Fail to check access: %v", err) } else if mode < requestedMode { clientMessage := accessDenied - if mode >= models.ACCESS_MODE_READ { + if mode >= models.AccessModeRead { clientMessage = "You do not have sufficient authorization for this action" } fail(clientMessage, @@ -276,7 +276,7 @@ func runServ(c *cli.Context) error { fail("Internal error", "Failed to execute git command: %v", err) } - if requestedMode == models.ACCESS_MODE_WRITE { + if requestedMode == models.AccessModeWrite { handleUpdateTask(uuid, user, repoUser, reponame, isWiki) } diff --git a/models/access.go b/models/access.go index e46819f2d438..fa3642cf53d2 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 06b8183a47be..a331883c4fd5 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 ec5408185783..42470dce70a1 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 07a90e08f1b5..b0796248a5ee 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 6ae7d9a25b08..bf34e97d09b7 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 f4b23f9ebea3..214aa2a015a5 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 77adce9f3be5..08483b83d241 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 ffa2f6440f90..dcb2311cf69b 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 { diff --git a/modules/context/org.go b/modules/context/org.go index 3804e210e6b9..acf83ff1424a 100644 --- a/modules/context/org.go +++ b/modules/context/org.go @@ -136,7 +136,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) { return } - ctx.Org.IsTeamAdmin = ctx.Org.Team.IsOwnerTeam() || ctx.Org.Team.Authorize >= models.ACCESS_MODE_ADMIN + ctx.Org.IsTeamAdmin = ctx.Org.Team.IsOwnerTeam() || ctx.Org.Team.Authorize >= models.AccessModeAdmin ctx.Data["IsTeamAdmin"] = ctx.Org.IsTeamAdmin if requireTeamAdmin && !ctx.Org.IsTeamAdmin { ctx.Handle(404, "OrgAssignment", err) diff --git a/modules/context/repo.go b/modules/context/repo.go index 8dadf3a1e6a1..0212aece9c87 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -51,22 +51,22 @@ type Repository struct { // IsOwner returns true if current user is the owner of repository. func (r *Repository) IsOwner() bool { - return r.AccessMode >= models.ACCESS_MODE_OWNER + return r.AccessMode >= models.AccessModeOwner } // IsAdmin returns true if current user has admin or higher access of repository. func (r *Repository) IsAdmin() bool { - return r.AccessMode >= models.ACCESS_MODE_ADMIN + return r.AccessMode >= models.AccessModeAdmin } // IsWriter returns true if current user has write or higher access of repository. func (r *Repository) IsWriter() bool { - return r.AccessMode >= models.ACCESS_MODE_WRITE + return r.AccessMode >= models.AccessModeWrite } // HasAccess returns true if the current user has at least read access for this repository func (r *Repository) HasAccess() bool { - return r.AccessMode >= models.ACCESS_MODE_READ + return r.AccessMode >= models.AccessModeRead } // CanEnableEditor returns true if repository is editable and user has proper access level. @@ -192,7 +192,7 @@ func RepoAssignment(args ...bool) macaron.Handler { // Admin has super access. if ctx.IsSigned && ctx.User.IsAdmin { - ctx.Repo.AccessMode = models.ACCESS_MODE_OWNER + ctx.Repo.AccessMode = models.AccessModeOwner } else { mode, err := models.AccessLevel(ctx.User, repo) if err != nil { @@ -203,7 +203,7 @@ func RepoAssignment(args ...bool) macaron.Handler { } // Check access. - if ctx.Repo.AccessMode == models.ACCESS_MODE_NONE { + if ctx.Repo.AccessMode == models.AccessModeNone { if ctx.Query("go-get") == "1" { earlyResponseForGoGetMeta(ctx) return diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 2deafa23c122..e8db9cb8e448 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -63,7 +63,7 @@ func repoAssignment() macaron.Handler { } if ctx.IsSigned && ctx.User.IsAdmin { - ctx.Repo.AccessMode = models.ACCESS_MODE_OWNER + ctx.Repo.AccessMode = models.AccessModeOwner } else { mode, err := models.AccessLevel(ctx.User, repo) if err != nil { diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index 0b28ee0f9291..3aa8995c7636 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -99,8 +99,8 @@ func ListMyRepos(ctx *context.APIContext) { for repo, access := range accessibleRepos { repos[i] = repo.APIFormat(&api.Permission{ - Admin: access >= models.ACCESS_MODE_ADMIN, - Push: access >= models.ACCESS_MODE_WRITE, + Admin: access >= models.AccessModeAdmin, + Push: access >= models.AccessModeWrite, Pull: true, }) i++ diff --git a/routers/org/teams.go b/routers/org/teams.go index c6636aa836dc..c2097935a8ae 100644 --- a/routers/org/teams.go +++ b/routers/org/teams.go @@ -226,11 +226,11 @@ func EditTeamPost(ctx *context.Context, form auth.CreateTeamForm) { var auth models.AccessMode switch form.Permission { case "read": - auth = models.ACCESS_MODE_READ + auth = models.AccessModeRead case "write": - auth = models.ACCESS_MODE_WRITE + auth = models.AccessModeWrite case "admin": - auth = models.ACCESS_MODE_ADMIN + auth = models.AccessModeAdmin default: ctx.Error(401) return diff --git a/routers/repo/http.go b/routers/repo/http.go index 529dc3d348b7..5a3d331fd16f 100644 --- a/routers/repo/http.go +++ b/routers/repo/http.go @@ -133,9 +133,9 @@ func HTTP(ctx *context.Context) { } if !isPublicPull { - var tp = models.ACCESS_MODE_WRITE + var tp = models.AccessModeWrite if isPull { - tp = models.ACCESS_MODE_READ + tp = models.AccessModeRead } has, err := models.HasAccess(authUser, repo, tp) @@ -143,8 +143,8 @@ func HTTP(ctx *context.Context) { ctx.Handle(http.StatusInternalServerError, "HasAccess", err) return } else if !has { - if tp == models.ACCESS_MODE_READ { - has, err = models.HasAccess(authUser, repo, models.ACCESS_MODE_WRITE) + if tp == models.AccessModeRead { + has, err = models.HasAccess(authUser, repo, models.AccessModeWrite) if err != nil { ctx.Handle(http.StatusInternalServerError, "HasAccess2", err) return