summaryrefslogtreecommitdiffstats
path: root/models/access.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-11-13 17:37:02 -0500
committerUnknwon <u@gogs.io>2015-11-13 17:37:02 -0500
commitf8ae161c743f3249e4b580cddc46da41b98652a9 (patch)
tree1bb44bd477ab0a23313c68bd1309b2a68bfffd67 /models/access.go
parent1d57f0d64fcd9aec16b4003d5664f31ea748da03 (diff)
downloadgitea-f8ae161c743f3249e4b580cddc46da41b98652a9.tar.gz
gitea-f8ae161c743f3249e4b580cddc46da41b98652a9.zip
fix #1302
Diffstat (limited to 'models/access.go')
-rw-r--r--models/access.go24
1 files changed, 18 insertions, 6 deletions
diff --git a/models/access.go b/models/access.go
index fe8bf2c17e..9e8c2dfe69 100644
--- a/models/access.go
+++ b/models/access.go
@@ -67,9 +67,8 @@ func HasAccess(u *User, repo *Repository, testMode AccessMode) (bool, error) {
return hasAccess(x, u, repo, testMode)
}
-// GetAccessibleRepositories finds all repositories where a user has access to,
-// besides he/she owns.
-func (u *User) GetAccessibleRepositories() (map[*Repository]AccessMode, error) {
+// GetRepositoryAccesses finds all repositories with their access mode where a user has access but does not own.
+func (u *User) GetRepositoryAccesses() (map[*Repository]AccessMode, error) {
accesses := make([]*Access, 0, 10)
if err := x.Find(&accesses, &Access{UserID: u.Id}); err != nil {
return nil, err
@@ -80,7 +79,7 @@ func (u *User) GetAccessibleRepositories() (map[*Repository]AccessMode, error) {
repo, err := GetRepositoryByID(access.RepoID)
if err != nil {
if IsErrRepoNotExist(err) {
- log.Error(4, "%v", err)
+ log.Error(4, "GetRepositoryByID: %v", err)
continue
}
return nil, err
@@ -92,11 +91,24 @@ func (u *User) GetAccessibleRepositories() (map[*Repository]AccessMode, error) {
}
repos[repo] = access.Mode
}
-
- // FIXME: should we generate an ordered list here? Random looks weird.
return repos, nil
}
+// GetAccessibleRepositories finds all repositories where a user has access but does not own.
+func (u *User) GetAccessibleRepositories() ([]*Repository, error) {
+ accesses := make([]*Access, 0, 10)
+ if err := x.Find(&accesses, &Access{UserID: u.Id}); err != nil {
+ return nil, err
+ }
+
+ repoIDs := make([]int64, 0, len(accesses))
+ for _, access := range accesses {
+ repoIDs = append(repoIDs, access.RepoID)
+ }
+ repos := make([]*Repository, 0, len(repoIDs))
+ return repos, x.Where("owner_id != ?", u.Id).In("id", repoIDs).Desc("updated").Find(&repos)
+}
+
func maxAccessMode(modes ...AccessMode) AccessMode {
max := ACCESS_MODE_NONE
for _, mode := range modes {