From 5c657f0216aa08d355338b1052a8a6f55512c0fd Mon Sep 17 00:00:00 2001 From: wang yan Date: Tue, 4 Feb 2020 18:37:42 +0800 Subject: [PATCH] fix issue on listing robot accounts Update the query FuzzyMatch when to list robot accounts per project Signed-off-by: wang yan --- src/pkg/robot/controller_test.go | 11 +++++++++++ src/pkg/robot/dao/robot.go | 6 +++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/pkg/robot/controller_test.go b/src/pkg/robot/controller_test.go index 6b6fdd70a..4f388357a 100644 --- a/src/pkg/robot/controller_test.go +++ b/src/pkg/robot/controller_test.go @@ -80,6 +80,15 @@ func (s *ControllerTestSuite) TestRobotAccount() { r2, _ := s.ctr.CreateRobotAccount(robot2) s.robotID = r2.ID + robot3 := &model.RobotCreate{ + Name: "robot3", + Description: "TestCreateRobotAccount", + ExpiresAt: expiresAt, + ProjectID: int64(11), + Access: policies, + } + r3, _ := s.ctr.CreateRobotAccount(robot3) + keywords := make(map[string]interface{}) keywords["ProjectID"] = int64(1) query := &q.Query{ @@ -92,6 +101,8 @@ func (s *ControllerTestSuite) TestRobotAccount() { err = s.ctr.DeleteRobotAccount(robot.ID) s.require.Nil(err) + err = s.ctr.DeleteRobotAccount(r3.ID) + s.require.Nil(err) robots, err = s.ctr.ListRobotAccount(query) s.require.Equal(len(robots), 1) diff --git a/src/pkg/robot/dao/robot.go b/src/pkg/robot/dao/robot.go index eef25fdf5..b7532a4eb 100644 --- a/src/pkg/robot/dao/robot.go +++ b/src/pkg/robot/dao/robot.go @@ -73,7 +73,11 @@ func (r *robotAccountDao) ListRobotAccounts(query *q.Query) ([]*model.Robot, err if query != nil { if len(query.Keywords) > 0 { for k, v := range query.Keywords { - qt = qt.Filter(fmt.Sprintf("%s__icontains", k), v) + if k == "ProjectID" { + qt = qt.Filter("ProjectID", v) + } else { + qt = qt.Filter(fmt.Sprintf("%s__icontains", k), v) + } } }