Merge pull request #10636 from wy65701436/fix-10579

fix issue on listing robot accounts
This commit is contained in:
Wang Yan 2020-02-05 13:29:30 +08:00 committed by GitHub
commit 88da643420
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -86,6 +86,15 @@ func (s *ControllerTestSuite) TestRobotAccount() {
r2, _ := s.ctr.CreateRobotAccount(robot2) r2, _ := s.ctr.CreateRobotAccount(robot2)
s.robotID = r2.ID 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 := make(map[string]interface{})
keywords["ProjectID"] = int64(1) keywords["ProjectID"] = int64(1)
query := &q.Query{ query := &q.Query{
@ -98,6 +107,8 @@ func (s *ControllerTestSuite) TestRobotAccount() {
err = s.ctr.DeleteRobotAccount(robot.ID) err = s.ctr.DeleteRobotAccount(robot.ID)
s.require.Nil(err) s.require.Nil(err)
err = s.ctr.DeleteRobotAccount(r3.ID)
s.require.Nil(err)
robots, err = s.ctr.ListRobotAccount(query) robots, err = s.ctr.ListRobotAccount(query)
s.require.Equal(len(robots), 1) s.require.Equal(len(robots), 1)

View File

@ -73,9 +73,13 @@ func (r *robotAccountDao) ListRobotAccounts(query *q.Query) ([]*model.Robot, err
if query != nil { if query != nil {
if len(query.Keywords) > 0 { if len(query.Keywords) > 0 {
for k, v := range query.Keywords { for k, v := range query.Keywords {
if k == "ProjectID" {
qt = qt.Filter("ProjectID", v)
} else {
qt = qt.Filter(fmt.Sprintf("%s__icontains", k), v) qt = qt.Filter(fmt.Sprintf("%s__icontains", k), v)
} }
} }
}
if query.PageNumber > 0 && query.PageSize > 0 { if query.PageNumber > 0 && query.PageSize > 0 {
qt = qt.Limit(query.PageSize, (query.PageNumber-1)*query.PageSize) qt = qt.Limit(query.PageSize, (query.PageNumber-1)*query.PageSize)