From 7e17054cb587bbee1d4f6d2c49a34d80ca8863c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cjeramysoucy=E2=80=9D?= Date: Mon, 30 Sep 2024 12:45:46 +0200 Subject: [PATCH] Adds API version option to requests in the roles client and edit role page --- .../management/roles/edit_role/edit_role_page.tsx | 3 ++- .../public/management/roles/roles_api_client.ts | 13 ++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/security/public/management/roles/edit_role/edit_role_page.tsx b/x-pack/plugins/security/public/management/roles/edit_role/edit_role_page.tsx index 02812eda34c7b..58d1e0f8c87f5 100644 --- a/x-pack/plugins/security/public/management/roles/edit_role/edit_role_page.tsx +++ b/x-pack/plugins/security/public/management/roles/edit_role/edit_role_page.tsx @@ -46,6 +46,7 @@ import { toMountPoint } from '@kbn/react-kibana-mount'; import type { Cluster } from '@kbn/remote-clusters-plugin/public'; import { REMOTE_CLUSTERS_PATH } from '@kbn/remote-clusters-plugin/public'; import { KibanaPrivileges } from '@kbn/security-role-management-model'; +import { API_VERSIONS as SPACES_API_VERSIONS } from '@kbn/spaces-plugin/common'; import type { Space, SpacesApiUi } from '@kbn/spaces-plugin/public'; import type { PublicMethodsOf } from '@kbn/utility-types'; @@ -272,7 +273,7 @@ function useRole( function useSpaces(http: HttpStart, fatalErrors: FatalErrorsSetup) { const [spaces, setSpaces] = useState<{ enabled: boolean; list: Space[] } | null>(null); useEffect(() => { - http.get('/api/spaces/space').then( + http.get('/api/spaces/space', { version: SPACES_API_VERSIONS.public.v1 }).then( (fetchedSpaces) => setSpaces({ enabled: true, list: fetchedSpaces }), (err: IHttpFetchError) => { // Spaces plugin can be disabled and hence this endpoint can be unavailable. diff --git a/x-pack/plugins/security/public/management/roles/roles_api_client.ts b/x-pack/plugins/security/public/management/roles/roles_api_client.ts index d6dcab658d21c..5c3970e82c516 100644 --- a/x-pack/plugins/security/public/management/roles/roles_api_client.ts +++ b/x-pack/plugins/security/public/management/roles/roles_api_client.ts @@ -9,25 +9,31 @@ import type { HttpStart } from '@kbn/core/public'; import type { BulkUpdatePayload, BulkUpdateRoleResponse } from '@kbn/security-plugin-types-public'; import type { Role, RoleIndexPrivilege, RoleRemoteIndexPrivilege } from '../../../common'; +import { API_VERSIONS } from '../../../common/constants'; import { copyRole } from '../../../common/model'; +const version = API_VERSIONS.roles.public.v1; + export class RolesAPIClient { constructor(private readonly http: HttpStart) {} public getRoles = async () => { - return await this.http.get('/api/security/role'); + return await this.http.get('/api/security/role', { version }); }; public getRole = async (roleName: string) => { - return await this.http.get(`/api/security/role/${encodeURIComponent(roleName)}`); + return await this.http.get(`/api/security/role/${encodeURIComponent(roleName)}`, { + version, + }); }; public deleteRole = async (roleName: string) => { - await this.http.delete(`/api/security/role/${encodeURIComponent(roleName)}`); + await this.http.delete(`/api/security/role/${encodeURIComponent(roleName)}`, { version }); }; public saveRole = async ({ role, createOnly = false }: { role: Role; createOnly?: boolean }) => { await this.http.put(`/api/security/role/${encodeURIComponent(role.name)}`, { + version, body: JSON.stringify(this.transformRoleForSave(copyRole(role))), query: { createOnly }, }); @@ -37,6 +43,7 @@ export class RolesAPIClient { rolesUpdate, }: BulkUpdatePayload): Promise => { return await this.http.post('/api/security/roles', { + version, body: JSON.stringify({ roles: Object.fromEntries( rolesUpdate.map((role) => [role.name, this.transformRoleForSave(copyRole(role))])