diff --git a/eslint-suppressions.json b/eslint-suppressions.json index f90a21cb7c5..96fa771540d 100644 --- a/eslint-suppressions.json +++ b/eslint-suppressions.json @@ -4677,4 +4677,4 @@ "count": 1 } } -} +} \ No newline at end of file diff --git a/packages/grafana-api-clients/src/clients/rtkq/dashboard/v0alpha1/endpoints.gen.ts b/packages/grafana-api-clients/src/clients/rtkq/dashboard/v0alpha1/endpoints.gen.ts index 5d3e72b13aa..8df8025f16c 100644 --- a/packages/grafana-api-clients/src/clients/rtkq/dashboard/v0alpha1/endpoints.gen.ts +++ b/packages/grafana-api-clients/src/clients/rtkq/dashboard/v0alpha1/endpoints.gen.ts @@ -248,6 +248,7 @@ const injectedRtkApi = api permission: queryArg.permission, sort: queryArg.sort, limit: queryArg.limit, + ownerReference: queryArg.ownerReference, explain: queryArg.explain, }, }), @@ -673,6 +674,8 @@ export type SearchDashboardsAndFoldersApiArg = { sort?: string; /** number of results to return */ limit?: number; + /** filter by owner reference in the format {Group}/{Kind}/{Name} */ + ownerReference?: string; /** add debugging info that may help explain why the result matched */ explain?: boolean; }; diff --git a/pkg/registry/apis/dashboard/search.go b/pkg/registry/apis/dashboard/search.go index e28eeedcecc..a438b9650ea 100644 --- a/pkg/registry/apis/dashboard/search.go +++ b/pkg/registry/apis/dashboard/search.go @@ -181,6 +181,32 @@ func (s *SearchHandler) GetAPIRoutes(defs map[string]common.OpenAPIDefinition) * Schema: spec.Int64Property(), }, }, + { + ParameterProps: spec3.ParameterProps{ + Name: "ownerReference", // singular + In: "query", + Description: "filter by owner reference in the format {Group}/{Kind}/{Name}", + Required: false, + Schema: spec.StringProperty(), + Examples: map[string]*spec3.Example{ + "": { + ExampleProps: spec3.ExampleProps{}, + }, + "team": { + ExampleProps: spec3.ExampleProps{ + Summary: "Team owner reference", + Value: "iam.grafana.app/Team/xyz", + }, + }, + "user": { + ExampleProps: spec3.ExampleProps{ + Summary: "User owner reference", + Value: "iam.grafana.app/User/abc", + }, + }, + }, + }, + }, { ParameterProps: spec3.ParameterProps{ Name: "explain", @@ -440,6 +466,15 @@ func convertHttpSearchRequestToResourceSearchRequest(queryParams url.Values, use }) } + // The ownerReferences filter + if vals, ok := queryParams["ownerReference"]; ok { + searchRequest.Options.Fields = append(searchRequest.Options.Fields, &resourcepb.Requirement{ + Key: resource.SEARCH_FIELD_OWNER_REFERENCES, + Operator: "=", + Values: vals, + }) + } + // The libraryPanel filter if libraryPanel, ok := queryParams["libraryPanel"]; ok { searchRequest.Options.Fields = append(searchRequest.Options.Fields, &resourcepb.Requirement{ diff --git a/pkg/tests/apis/openapi_snapshots/dashboard.grafana.app-v0alpha1.json b/pkg/tests/apis/openapi_snapshots/dashboard.grafana.app-v0alpha1.json index b65fa2ad0d7..80c23d2e053 100644 --- a/pkg/tests/apis/openapi_snapshots/dashboard.grafana.app-v0alpha1.json +++ b/pkg/tests/apis/openapi_snapshots/dashboard.grafana.app-v0alpha1.json @@ -1864,6 +1864,25 @@ "format": "int64" } }, + { + "name": "ownerReference", + "in": "query", + "description": "filter by owner reference in the format {Group}/{Kind}/{Name}", + "schema": { + "type": "string" + }, + "examples": { + "": {}, + "team": { + "summary": "Team owner reference", + "value": "iam.grafana.app/Team/xyz" + }, + "user": { + "summary": "User owner reference", + "value": "iam.grafana.app/User/abc" + } + } + }, { "name": "explain", "in": "query",