Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SQL bug in models/access #583

Merged
merged 1 commit into from
Jan 5, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions models/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down