Browse Source

Fix SQL bug in models/access (#583)

Previously got a 'relation repo_access does not exist' error in User_GetRepositoryAccesses
Ethan Koenig 3 years ago
parent
commit
c5f0d4b1a0
1 changed files with 14 additions and 11 deletions
  1. 14 11
      models/access.go

+ 14 - 11
models/access.go

@@ -96,28 +96,31 @@ func HasAccess(user *User, repo *Repository, testMode AccessMode) (bool, error)
96 96
 	return hasAccess(x, user, repo, testMode)
97 97
 }
98 98
 
99
+type repoAccess struct {
100
+	Access     `xorm:"extends"`
101
+	Repository `xorm:"extends"`
102
+}
103
+
104
+func (repoAccess) TableName() string {
105
+	return "access"
106
+}
107
+
99 108
 // GetRepositoryAccesses finds all repositories with their access mode where a user has access but does not own.
100 109
 func (user *User) GetRepositoryAccesses() (map[*Repository]AccessMode, error) {
101
-	accesses := make([]*Access, 0, 10)
102
-	type RepoAccess struct {
103
-		Access     `xorm:"extends"`
104
-		Repository `xorm:"extends"`
105
-	}
106
-
107 110
 	rows, err := x.
108
-		Join("INNER", "repository", "respository.id = access.repo_id").
111
+		Join("INNER", "repository", "repository.id = access.repo_id").
109 112
 		Where("access.user_id = ?", user.ID).
110 113
 		And("repository.owner_id <> ?", user.ID).
111
-		Rows(new(RepoAccess))
114
+		Rows(new(repoAccess))
112 115
 	if err != nil {
113 116
 		return nil, err
114 117
 	}
115 118
 	defer rows.Close()
116 119
 
117
-	var repos = make(map[*Repository]AccessMode, len(accesses))
118
-	var ownerCache = make(map[int64]*User, len(accesses))
120
+	var repos = make(map[*Repository]AccessMode, 10)
121
+	var ownerCache = make(map[int64]*User, 10)
119 122
 	for rows.Next() {
120
-		var repo RepoAccess
123
+		var repo repoAccess
121 124
 		err = rows.Scan(&repo)
122 125
 		if err != nil {
123 126
 			return nil, err