aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOtto Richter (fnetX)2022-03-04 19:29:12 +0100
committerGitHub2022-03-04 18:29:12 +0000
commite46a8c90ea11a24bbaa1ccaaf6600d5374ec26cf (patch)
treeb1c2a3a1450823da47a0779d520c2cdb94b09aeb
parent5184c83f6b702aeec3ea85263e16ccf5ebe89836 (diff)
Fix potential assignee query for repo (#18994)
* Fix potential assignee query for repo * Add tests for `GetRepoAssignees` - As per https://github.com/go-gitea/gitea/pull/18994#issuecomment-1058506640 Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Gusted <williamzijl7@hotmail.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
-rw-r--r--models/repo.go2
-rw-r--r--models/repo_test.go18
2 files changed, 19 insertions, 1 deletions
diff --git a/models/repo.go b/models/repo.go
index 6a806b7e2..38527c74d 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -153,7 +153,7 @@ func getRepoAssignees(ctx context.Context, repo *repo_model.Repository) (_ []*us
userIDs := make([]int64, 0, 10)
if err = e.Table("access").
Where("repo_id = ? AND mode >= ?", repo.ID, perm.AccessModeWrite).
- Select("id").
+ Select("user_id").
Find(&userIDs); err != nil {
return nil, err
}
diff --git a/models/repo_test.go b/models/repo_test.go
index c0790e532..ea250be97 100644
--- a/models/repo_test.go
+++ b/models/repo_test.go
@@ -167,3 +167,21 @@ func TestLinkedRepository(t *testing.T) {
})
}
}
+
+func TestRepoAssignees(t *testing.T) {
+ assert.NoError(t, unittest.PrepareTestDatabase())
+
+ repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2}).(*repo_model.Repository)
+ users, err := GetRepoAssignees(repo2)
+ assert.NoError(t, err)
+ assert.Len(t, users, 1)
+ assert.Equal(t, users[0].ID, int64(2))
+
+ repo21 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 21}).(*repo_model.Repository)
+ users, err = GetRepoAssignees(repo21)
+ assert.NoError(t, err)
+ assert.Len(t, users, 3)
+ assert.Equal(t, users[0].ID, int64(15))
+ assert.Equal(t, users[1].ID, int64(18))
+ assert.Equal(t, users[2].ID, int64(16))
+}