Skip to content

Commit

Permalink
Fixes 4292: filtering templates by repo uuids lists dups (#711)
Browse files Browse the repository at this point in the history
* Fixes 4292: filtering templates by multiple repo uuids returns duplicates

* add test
  • Loading branch information
xbhouse authored Jun 20, 2024
1 parent 33cd4f1 commit dadfd64
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pkg/dao/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,13 @@ func (t templateDaoImpl) List(ctx context.Context, orgID string, paginationData
// Get count
if filteredDB.
Model(&templates).
Distinct("uuid").
Count(&totalTemplates).Error != nil {
return api.TemplateCollectionResponse{}, totalTemplates, t.DBToApiError(filteredDB.Error)
}

if filteredDB.
Distinct("templates.*").
Preload("RepositoryConfigurations").
Order(order).
Limit(paginationData.Limit).
Expand Down
4 changes: 3 additions & 1 deletion pkg/dao/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,14 @@ func (s *TemplateSuite) TestListFilters() {

// Test Filter by RepositoryUUIDs
template, rcUUIDs := s.seedWithRepoConfig(orgIDTest, 2)
filterData = api.TemplateFilterData{RepositoryUUIDs: []string{rcUUIDs[0]}}
filterData = api.TemplateFilterData{RepositoryUUIDs: []string{rcUUIDs[0], rcUUIDs[1]}}
responses, total, err = templateDao.List(context.Background(), orgIDTest, api.PaginationData{Limit: -1}, filterData)
assert.NoError(s.T(), err)
assert.Equal(s.T(), int64(2), total)
assert.Len(s.T(), responses.Data, 2)
assert.True(s.T(), template.UUID == responses.Data[0].UUID || template.UUID == responses.Data[1].UUID)
assert.True(s.T(), rcUUIDs[0] == responses.Data[0].RepositoryUUIDS[0] || rcUUIDs[0] == responses.Data[1].RepositoryUUIDS[0])
assert.True(s.T(), rcUUIDs[1] == responses.Data[0].RepositoryUUIDS[1] || rcUUIDs[1] == responses.Data[1].RepositoryUUIDS[1])
}

func (s *TemplateSuite) TestListFilterSearch() {
Expand Down

0 comments on commit dadfd64

Please sign in to comment.