Skip to content

Commit

Permalink
Explicitly add active projects filtering in manager layer (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
katrogan authored Feb 12, 2024
1 parent f76850f commit 047b109
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
8 changes: 7 additions & 1 deletion flyteadmin/pkg/manager/impl/project_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package impl

import (
"context"
"fmt"
"strconv"

"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -55,9 +56,14 @@ func (m *ProjectManager) getDomains() []*admin.Domain {
}

func (m *ProjectManager) ListProjects(ctx context.Context, request admin.ProjectListRequest) (*admin.Projects, error) {
var requestFilters = request.Filters
if len(requestFilters) == 0 {
// Add implicit active filters ordinarily added by database.
requestFilters = fmt.Sprintf("eq(state,%d)", admin.Project_ACTIVE)
}
spec := util.FilterSpec{
Org: request.Org,
RequestFilters: request.Filters,
RequestFilters: requestFilters,
}
filters, err := util.GetDbFilters(spec, common.Project)
if err != nil {
Expand Down
24 changes: 16 additions & 8 deletions flyteadmin/pkg/manager/impl/project_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,17 @@ func getMockApplicationConfigForProjectManagerTest() runtimeInterfaces.Applicati
return &mockApplicationConfig
}

func expectedOrgQueryExpr() *common.GormQueryExpr {
return &common.GormQueryExpr{
Query: "org = ?",
Args: "",
func expectedDefaultQueryExpr() []*common.GormQueryExpr {
return []*common.GormQueryExpr{
{
Query: "org = ?",
Args: "",
},
{

Query: "state = ?",
Args: "0",
},
}
}

Expand Down Expand Up @@ -92,7 +99,7 @@ func TestListProjects_NoFilters_LimitOne(t *testing.T) {
testListProjects(admin.ProjectListRequest{
Token: "1",
Limit: 1,
}, "2", "identifier asc", []*common.GormQueryExpr{expectedOrgQueryExpr()}, t)
}, "2", "identifier asc", expectedDefaultQueryExpr(), t)
}

func TestListProjects_HighLimit_SortBy_Filter(t *testing.T) {
Expand All @@ -105,16 +112,17 @@ func TestListProjects_HighLimit_SortBy_Filter(t *testing.T) {
Direction: admin.Sort_DESCENDING,
},
}, "", "name desc", []*common.GormQueryExpr{
expectedOrgQueryExpr(),
{
expectedDefaultQueryExpr()[0],
&common.GormQueryExpr{
Query: "name = ?",
Args: "foo",
},
expectedDefaultQueryExpr()[1],
}, t)
}

func TestListProjects_NoToken_NoLimit(t *testing.T) {
testListProjects(admin.ProjectListRequest{}, "", "identifier asc", []*common.GormQueryExpr{expectedOrgQueryExpr()}, t)
testListProjects(admin.ProjectListRequest{}, "", "identifier asc", expectedDefaultQueryExpr(), t)
}

func TestProjectManager_CreateProject(t *testing.T) {
Expand Down

0 comments on commit 047b109

Please sign in to comment.