summaryrefslogtreecommitdiffstats
path: root/models/access.go
diff options
context:
space:
mode:
authorEthan Koenig <etk39@cornell.edu>2017-03-14 20:51:46 -0400
committerLunny Xiao <xiaolunwen@gmail.com>2017-03-15 08:51:46 +0800
commitec0ae5d50c59315a3c597b1cf24d4c5508c718e5 (patch)
tree6f4d6f826dd9866f9b39b66522ec629555700de2 /models/access.go
parent7d8f9d1c46e38681f2a4033a7da811ab7562d953 (diff)
downloadgitea-ec0ae5d50c59315a3c597b1cf24d4c5508c718e5.tar.gz
gitea-ec0ae5d50c59315a3c597b1cf24d4c5508c718e5.zip
Refactor and fix incorrect comment (#1247)
Diffstat (limited to 'models/access.go')
-rw-r--r--models/access.go24
1 files changed, 12 insertions, 12 deletions
diff --git a/models/access.go b/models/access.go
index 49a8838ea6..98ead19a0b 100644
--- a/models/access.go
+++ b/models/access.go
@@ -59,21 +59,21 @@ type Access struct {
Mode AccessMode
}
-func accessLevel(e Engine, user *User, repo *Repository) (AccessMode, error) {
+func accessLevel(e Engine, userID int64, repo *Repository) (AccessMode, error) {
mode := AccessModeNone
if !repo.IsPrivate {
mode = AccessModeRead
}
- if user == nil {
+ if userID == 0 {
return mode, nil
}
- if user.ID == repo.OwnerID {
+ if userID == repo.OwnerID {
return AccessModeOwner, nil
}
- a := &Access{UserID: user.ID, RepoID: repo.ID}
+ a := &Access{UserID: userID, RepoID: repo.ID}
if has, err := e.Get(a); !has || err != nil {
return mode, err
}
@@ -81,19 +81,19 @@ func accessLevel(e Engine, user *User, repo *Repository) (AccessMode, error) {
}
// AccessLevel returns the Access a user has to a repository. Will return NoneAccess if the
-// user does not have access. User can be nil!
-func AccessLevel(user *User, repo *Repository) (AccessMode, error) {
- return accessLevel(x, user, repo)
+// user does not have access.
+func AccessLevel(userID int64, repo *Repository) (AccessMode, error) {
+ return accessLevel(x, userID, repo)
}
-func hasAccess(e Engine, user *User, repo *Repository, testMode AccessMode) (bool, error) {
- mode, err := accessLevel(e, user, repo)
+func hasAccess(e Engine, userID int64, repo *Repository, testMode AccessMode) (bool, error) {
+ mode, err := accessLevel(e, userID, repo)
return testMode <= mode, err
}
-// HasAccess returns true if someone has the request access level. User can be nil!
-func HasAccess(user *User, repo *Repository, testMode AccessMode) (bool, error) {
- return hasAccess(x, user, repo, testMode)
+// HasAccess returns true if user has access to repo
+func HasAccess(userID int64, repo *Repository, testMode AccessMode) (bool, error) {
+ return hasAccess(x, userID, repo, testMode)
}
type repoAccess struct {