Skip to content

Commit

Permalink
fix(workflow): Move description filter for workflows (#1589)
Browse files Browse the repository at this point in the history
Signed-off-by: Javier Rodriguez <javier@chainloop.dev>
  • Loading branch information
javirln authored Nov 26, 2024
1 parent a98686c commit 9bb547f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
22 changes: 22 additions & 0 deletions app/controlplane/pkg/biz/workflow_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,28 @@ func (s *workflowListIntegrationTestSuite) TestList() {
s.Len(workflows, 1)
})

s.Run("list workflows with description filter", func() {
_, err := s.Workflow.Create(ctx, &biz.WorkflowCreateOpts{OrgID: s.org.ID, Name: "name1", Project: project, Team: team, Description: description})
require.NoError(s.T(), err)
_, err = s.Workflow.Create(ctx, &biz.WorkflowCreateOpts{OrgID: s.org.ID, Name: "name2", Project: project, Team: team, Description: "this is a different description"})
require.NoError(s.T(), err)

workflows, _, err := s.Workflow.List(ctx, s.org.ID, &biz.WorkflowListOpts{WorkflowDescription: "different"}, nil)
s.NoError(err)
s.Len(workflows, 1)
})

s.Run("list workflows with description and workflow name filter", func() {
_, err := s.Workflow.Create(ctx, &biz.WorkflowCreateOpts{OrgID: s.org.ID, Name: "name1", Project: project, Team: team, Description: description})
require.NoError(s.T(), err)
_, err = s.Workflow.Create(ctx, &biz.WorkflowCreateOpts{OrgID: s.org.ID, Name: "name2", Project: project, Team: team, Description: "this is a different description for name2"})
require.NoError(s.T(), err)

workflows, _, err := s.Workflow.List(ctx, s.org.ID, &biz.WorkflowListOpts{WorkflowName: "name2", WorkflowDescription: "name2"}, nil)
s.NoError(err)
s.Len(workflows, 1)
})

s.Run("list workflows with workflow team filter", func() {
_, err := s.Workflow.Create(ctx, &biz.WorkflowCreateOpts{OrgID: s.org.ID, Name: "name1", Project: project, Team: team, Description: description})
require.NoError(s.T(), err)
Expand Down
8 changes: 4 additions & 4 deletions app/controlplane/pkg/data/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,6 @@ func applyWorkflowFilters(wfQuery *ent.WorkflowQuery, opts *biz.WorkflowListOpts
)
}

if opts.WorkflowDescription != "" {
wfQuery = wfQuery.Where(workflow.DescriptionContains(opts.WorkflowDescription))
}

if len(opts.WorkflowProjectNames) != 0 {
wfQuery = wfQuery.Where(workflow.HasProjectWith(project.NameIn(opts.WorkflowProjectNames...)))
}
Expand All @@ -246,6 +242,10 @@ func applyWorkflowFilters(wfQuery *ent.WorkflowQuery, opts *biz.WorkflowListOpts
orConditions = append(orConditions, workflow.NameContains(opts.WorkflowName))
}

if opts.WorkflowDescription != "" {
wfQuery = wfQuery.Where(workflow.DescriptionContains(opts.WorkflowDescription))
}

if len(orConditions) > 0 {
wfQuery = wfQuery.Where(workflow.Or(orConditions...))
}
Expand Down

0 comments on commit 9bb547f

Please sign in to comment.