Incorrect table name was used - user instead of auth_user.
Add test.

Signed-off-by: Franciszek Stachura <[email protected]>
---
 pkg/api/bundle_test.go | 13 +++++++++++++
 pkg/api/bundles.go     |  2 +-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/pkg/api/bundle_test.go b/pkg/api/bundle_test.go
index c297b60..df2d2e2 100644
--- a/pkg/api/bundle_test.go
+++ b/pkg/api/bundle_test.go
@@ -140,6 +140,19 @@ func TestBundleFilterOwner(t *testing.T) {
        assert.Len(t, items, 0)
 }
 
+func TestBundleFilterOwnerByName(t *testing.T) {
+       s := newTestServer(t)
+       projID := s.insertProject(t)
+       userID := s.insertUser(t, "bfo", "bfo@test")
+       s.exec(t, `INSERT INTO bundle (owner_id, project_id, name, public)
+               VALUES (?, ?, 'b', true)`, userID, projID)
+
+       items := getList(t, s, "/api/1.4/bundles/?owner=bfo")
+       assert.Len(t, items, 1)
+       items = getList(t, s, "/api/1.4/bundles/?owner=test")
+       assert.Len(t, items, 0)
+}
+
 func TestBundleFilterProject(t *testing.T) {
        s := newTestServer(t)
        projID := s.insertProject(t)
diff --git a/pkg/api/bundles.go b/pkg/api/bundles.go
index f011f6c..2105a3c 100644
--- a/pkg/api/bundles.go
+++ b/pkg/api/bundles.go
@@ -335,7 +335,7 @@ func applyBundleFilters(q *bun.SelectQuery, input 
*ListBundlesInput) *bun.Select
                if id, err := strconv.Atoi(input.Owner); err == nil {
                        q = q.Where("bundle.owner_id = ?", id)
                } else {
-                       q = q.Where("bundle.owner_id IN (SELECT id FROM user 
WHERE username = ?)", input.Owner)
+                       q = q.Where("bundle.owner_id IN (SELECT id FROM 
auth_user WHERE username = ?)", input.Owner)
                }
        }
        if input.Public != "" {
-- 
2.56.0

_______________________________________________
Patchwork mailing list
[email protected]
https://lists.ozlabs.org/listinfo/patchwork

Reply via email to