aboutsummaryrefslogtreecommitdiffstats
path: root/models/access.go
diff options
context:
space:
mode:
authorPeter Smit <peter@smitmail.eu>2015-01-23 09:54:16 +0200
committerPeter Smit <peter@smitmail.eu>2015-01-23 09:54:16 +0200
commit76f89047183fc70a077ac37b4168d90539f12e09 (patch)
tree4d57f8e0fa667a3a08f1ee55c49b9c0f95085844 /models/access.go
parentc6b87aaf02b711d8b1ee7a40f57ba23f560e2a63 (diff)
downloadgitea-76f89047183fc70a077ac37b4168d90539f12e09.tar.gz
gitea-76f89047183fc70a077ac37b4168d90539f12e09.zip
Introducing Collaboration Struct
Diffstat (limited to 'models/access.go')
-rw-r--r--models/access.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/models/access.go b/models/access.go
index 81aa43dc78..65f1d00323 100644
--- a/models/access.go
+++ b/models/access.go
@@ -78,3 +78,23 @@ func HasAccess(uname, repoName string, mode AccessType) (bool, error) {
}
return true, nil
}
+
+// GetAccessibleRepositories finds all repositories where a user has access to,
+// besides his own.
+func (u *User) GetAccessibleRepositories() (map[*Repository]AccessType, error) {
+ accesses := make([]*Access, 0, 10)
+ if err := x.Find(&accesses, &Access{UserName: u.LowerName}); err != nil {
+ return nil, err
+ }
+
+ repos := make(map[*Repository]AccessType, len(accesses))
+ for _, access := range accesses {
+ repo, err := GetRepositoryByRef(access.RepoName)
+ if err != nil {
+ return nil, err
+ }
+ repos[repo] = access.Mode
+ }
+
+ return repos, nil
+}