Skip to content

Commit

Permalink
SVR-331: Respect org if present in ListProjects requests (#96)
Browse files Browse the repository at this point in the history
Signed-off-by: Katrina Rogan <[email protected]>
  • Loading branch information
katrogan authored Feb 27, 2024
1 parent e37d3c0 commit ad72426
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
17 changes: 12 additions & 5 deletions flyteadmin/pkg/manager/impl/project_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/flyteorg/flyte/flyteadmin/pkg/common"
"github.com/flyteorg/flyte/flyteadmin/pkg/errors"
"github.com/flyteorg/flyte/flyteadmin/pkg/manager/impl/shared"
"github.com/flyteorg/flyte/flyteadmin/pkg/manager/impl/util"
"github.com/flyteorg/flyte/flyteadmin/pkg/manager/impl/validation"
"github.com/flyteorg/flyte/flyteadmin/pkg/manager/interfaces"
Expand All @@ -17,10 +18,7 @@ import (
"github.com/flyteorg/flyte/flyteadmin/pkg/repositories/transformers"
runtimeInterfaces "github.com/flyteorg/flyte/flyteadmin/pkg/runtime/interfaces"
"github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin"
)

var (
emptyListProjectFilters []common.InlineFilter
"github.com/flyteorg/flyte/flytestdlib/logger"
)

type ProjectManager struct {
Expand Down Expand Up @@ -65,7 +63,16 @@ func (m *ProjectManager) ListProjects(ctx context.Context, request admin.Project
// Add implicit active filters ordinarily added by database.
requestFilters = fmt.Sprintf("eq(state,%d)", admin.Project_ACTIVE)
}
filters, err := util.AddRequestFilters(requestFilters, common.Project, emptyListProjectFilters)
var listProjectFilters []common.InlineFilter
// Only explicitly add an org filter if it is included in the request.
if len(request.Org) > 0 {
orgFilter, err := util.GetSingleValueEqualityFilter(common.Project, shared.Org, request.GetOrg())
if err != nil {
logger.Error(ctx, "failed to add org filter to list projects request for org: %s and err: %v", request.GetOrg(), err)
}
listProjectFilters = append(listProjectFilters, orgFilter)
}
filters, err := util.AddRequestFilters(requestFilters, common.Project, listProjectFilters)
if err != nil {
return nil, err
}
Expand Down
13 changes: 13 additions & 0 deletions flyteadmin/pkg/manager/impl/project_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,19 @@ func TestListProjects_HighLimit_SortBy_Filter(t *testing.T) {
}, t)
}

func TestListProjects_HighLimit_WithOrgFilter(t *testing.T) {
testListProjects(admin.ProjectListRequest{
Token: "1",
Limit: 999,
Filters: "eq(org,foo)",
}, "", "identifier asc", []*common.GormQueryExpr{
&common.GormQueryExpr{
Query: "org = ?",
Args: "foo",
},
}, t)
}

func TestListProjects_NoToken_NoLimit(t *testing.T) {
testListProjects(admin.ProjectListRequest{}, "", "identifier asc", expectedDefaultQueryExpr(), t)
}
Expand Down

0 comments on commit ad72426

Please sign in to comment.