From 2dd47e03578afd91cea805e89ec8888498dda8a3 Mon Sep 17 00:00:00 2001 From: Ethan Koenig Date: Wed, 4 Jan 2017 11:43:57 -0500 Subject: [PATCH] Fix SQL bug in models/access 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 c77e7f0a16898..6aca6890afb0d 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