From c5f0d4b1a0255a87a3f29f88e537701685822f61 Mon Sep 17 00:00:00 2001 From: Ethan Koenig Date: Wed, 4 Jan 2017 19:57:54 -0500 Subject: [PATCH] Fix SQL bug in models/access (#583) Previously got a 'relation repo_access does not exist' error in User_GetRepositoryAccesses --- models/access.go | 25 ++++++++++++++----------- 1 file 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