diff --git a/flyteadmin/pkg/manager/impl/project_manager.go b/flyteadmin/pkg/manager/impl/project_manager.go index 123293b4ea..d60ea26456 100644 --- a/flyteadmin/pkg/manager/impl/project_manager.go +++ b/flyteadmin/pkg/manager/impl/project_manager.go @@ -2,6 +2,7 @@ package impl import ( "context" + "fmt" "strconv" "google.golang.org/grpc/codes" @@ -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 { diff --git a/flyteadmin/pkg/manager/impl/project_manager_test.go b/flyteadmin/pkg/manager/impl/project_manager_test.go index 31523a05f8..dc6c539c61 100644 --- a/flyteadmin/pkg/manager/impl/project_manager_test.go +++ b/flyteadmin/pkg/manager/impl/project_manager_test.go @@ -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", + }, } } @@ -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) { @@ -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) {