Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions app/controlplane/pkg/biz/group_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,40 @@ func (s *groupListIntegrationTestSuite) TestList() {
s.Contains(groups[0].Description, "A team")
})

s.Run("list groups with name OR description filter", func() {
// Clear existing groups
_, _ = s.Data.DB.Group.Delete().Exec(ctx)

// Create groups with different names and descriptions
_, err := s.Group.Create(ctx, uuid.MustParse(s.org.ID), "frontend-team", "Frontend development team", uuid.MustParse(s.user.ID))
require.NoError(s.T(), err)
_, err = s.Group.Create(ctx, uuid.MustParse(s.org.ID), "backend-team", "Backend development team", uuid.MustParse(s.user.ID))
require.NoError(s.T(), err)
_, err = s.Group.Create(ctx, uuid.MustParse(s.org.ID), "qa-team", "Quality Assurance team", uuid.MustParse(s.user.ID))
require.NoError(s.T(), err)
_, err = s.Group.Create(ctx, uuid.MustParse(s.org.ID), "devops-team", "Team responsible for infrastructure", uuid.MustParse(s.user.ID))
require.NoError(s.T(), err)

// Filter with a term that appears in one group's name and another group's description
// Should match both the "frontend-team" (name contains "front") and "backend-team" (description contains "development")
filterOpts := &biz.ListGroupOpts{
Name: "front",
Description: "development",
}

groups, count, err := s.Group.List(ctx, uuid.MustParse(s.org.ID), filterOpts, nil)
s.NoError(err)

// Should match 2 groups due to OR filtering
s.Equal(2, count)
s.Equal(2, len(groups))

// Verify that both expected groups are in the results
groupNames := []string{groups[0].Name, groups[1].Name}
s.Contains(groupNames, "frontend-team")
s.Contains(groupNames, "backend-team")
})

s.Run("list groups with member email filter", func() {
// Create a second user
user2, err := s.User.UpsertByEmail(ctx, "user2@example.com", nil)
Expand Down
14 changes: 11 additions & 3 deletions app/controlplane/pkg/data/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/membership"
"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/organization"
"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/orginvitation"
"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/predicate"
"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/user"
"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/workflow"
"github.com/chainloop-dev/chainloop/app/controlplane/pkg/pagination"
Expand Down Expand Up @@ -60,16 +61,23 @@ func (g GroupRepo) List(ctx context.Context, orgID uuid.UUID, filterOpts *biz.Li
Where(group.DeletedAtIsNil(), group.OrganizationIDEQ(orgID)).
WithMembers().WithOrganization()

// Apply filters as ORs if any filter is provided
var predicates []predicate.Group
if filterOpts.Name != "" {
query.Where(group.NameContains(filterOpts.Name))
predicates = append(predicates, group.NameContains(filterOpts.Name))
}

if filterOpts.Description != "" {
query.Where(group.DescriptionContains(filterOpts.Description))
predicates = append(predicates, group.DescriptionContains(filterOpts.Description))
}

if filterOpts.MemberEmail != "" {
query.Where(group.HasMembersWith(user.EmailContains(filterOpts.MemberEmail)))
predicates = append(predicates, group.HasMembersWith(user.EmailContains(filterOpts.MemberEmail)))
}

// Apply OR predicates if any exist
if len(predicates) > 0 {
query.Where(group.Or(predicates...))
}

// Get the count of all filtered rows without the limit and offset
Expand Down
Loading