Fix SQL bug in models/access (#583)
Previously got a 'relation repo_access does not exist' error in User_GetRepositoryAccesses
This commit is contained in:
parent
bdad3b259a
commit
c5f0d4b1a0
1 changed files with 14 additions and 11 deletions
|
@ -96,28 +96,31 @@ func HasAccess(user *User, repo *Repository, testMode AccessMode) (bool, error)
|
||||||
return hasAccess(x, user, repo, testMode)
|
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.
|
// 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) {
|
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.
|
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).
|
Where("access.user_id = ?", user.ID).
|
||||||
And("repository.owner_id <> ?", user.ID).
|
And("repository.owner_id <> ?", user.ID).
|
||||||
Rows(new(RepoAccess))
|
Rows(new(repoAccess))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
var repos = make(map[*Repository]AccessMode, len(accesses))
|
var repos = make(map[*Repository]AccessMode, 10)
|
||||||
var ownerCache = make(map[int64]*User, len(accesses))
|
var ownerCache = make(map[int64]*User, 10)
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var repo RepoAccess
|
var repo repoAccess
|
||||||
err = rows.Scan(&repo)
|
err = rows.Scan(&repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Reference in a new issue