Skip to content

Commit

Permalink
Adds API version option to requests in the roles client and edit role…
Browse files Browse the repository at this point in the history
… page
  • Loading branch information
jeramysoucy committed Sep 30, 2024
1 parent a8217e0 commit 7e17054
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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<Space[]>('/api/spaces/space').then(
http.get<Space[]>('/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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Role[]>('/api/security/role');
return await this.http.get<Role[]>('/api/security/role', { version });
};

public getRole = async (roleName: string) => {
return await this.http.get<Role>(`/api/security/role/${encodeURIComponent(roleName)}`);
return await this.http.get<Role>(`/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 },
});
Expand All @@ -37,6 +43,7 @@ export class RolesAPIClient {
rolesUpdate,
}: BulkUpdatePayload): Promise<BulkUpdateRoleResponse> => {
return await this.http.post('/api/security/roles', {
version,
body: JSON.stringify({
roles: Object.fromEntries(
rolesUpdate.map((role) => [role.name, this.transformRoleForSave(copyRole(role))])
Expand Down

0 comments on commit 7e17054

Please sign in to comment.