summaryrefslogtreecommitdiffstats
path: root/models/access.go
diff options
context:
space:
mode:
authorEthan Koenig <etk39@cornell.edu>2017-01-04 19:57:54 -0500
committerLunny Xiao <xiaolunwen@gmail.com>2017-01-05 08:57:54 +0800
commitc5f0d4b1a0255a87a3f29f88e537701685822f61 (patch)
tree68c524e2eca30b5673cbc8dc61949b8a4d96c9c1 /models/access.go
parentbdad3b259aab7ac78b9def5bf4fafac880d0301f (diff)
downloadgitea-c5f0d4b1a0255a87a3f29f88e537701685822f61.tar.gz
gitea-c5f0d4b1a0255a87a3f29f88e537701685822f61.zip
Fix SQL bug in models/access (#583)
Previously got a 'relation repo_access does not exist' error in User_GetRepositoryAccesses
Diffstat (limited to 'models/access.go')
-rw-r--r--models/access.go25
1 files changed, 14 insertions, 11 deletions
diff --git a/models/access.go b/models/access.go
index 7b139fa3cf..49a8838ea6 100644
--- a/models/access.go
+++ b/models/access.go
@@ -96,28 +96,31 @@ func HasAccess(user *User, repo *Repository, testMode AccessMode) (bool, error)
return hasAccess(x, user, repo, testMode)
}
+type repoAccess struct {
+ Access `xorm:"extends"`
+ Repository `xorm:"extends"`
+}
+
+func (repoAccess) TableName() string {
+ return "access"
+}
+
// GetRepositoryAccesses finds all repositories with their access mode where a user has access but does not own.
func (user *User) GetRepositoryAccesses() (map[*Repository]AccessMode, error) {
- accesses := make([]*Access, 0, 10)
- type RepoAccess struct {
- Access `xorm:"extends"`
- Repository `xorm:"extends"`
- }
-
rows, err := x.
- Join("INNER", "repository", "respository.id = access.repo_id").
+ Join("INNER", "repository", "repository.id = access.repo_id").
Where("access.user_id = ?", user.ID).
And("repository.owner_id <> ?", user.ID).
- Rows(new(RepoAccess))
+ Rows(new(repoAccess))
if err != nil {
return nil, err
}
defer rows.Close()
- var repos = make(map[*Repository]AccessMode, len(accesses))
- var ownerCache = make(map[int64]*User, len(accesses))
+ var repos = make(map[*Repository]AccessMode, 10)
+ var ownerCache = make(map[int64]*User, 10)
for rows.Next() {
- var repo RepoAccess
+ var repo repoAccess
err = rows.Scan(&repo)
if err != nil {
return nil, err