From eedca2adc38a1cffae7eab76eb06f591ad8e8b2a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 20 Oct 2023 14:37:37 +0000 Subject: [PATCH] Allow patch on allowedRoles (#1143) * Allow patch on allowedRoles Signed-off-by: Derek Ho * Change for patch Signed-off-by: Derek Ho * Address PR comments Signed-off-by: Derek Ho --------- Signed-off-by: Derek Ho (cherry picked from commit cccfebf957b57841e18d274efa9bf1877cae0b4f) Signed-off-by: github-actions[bot] --- common/constants/shared.ts | 2 + .../data_connection.test.tsx.snap | 38 ++++++++++ .../components/manage/access_control_tab.tsx | 76 ++++++++++++++++++- .../components/new/configure_datasource.tsx | 4 +- .../components/new/query_permissions.tsx | 7 +- server/adaptors/ppl_plugin.ts | 2 +- .../data_connections_router.ts | 10 +-- 7 files changed, 125 insertions(+), 14 deletions(-) diff --git a/common/constants/shared.ts b/common/constants/shared.ts index cc7a5147b0..8175f33801 100644 --- a/common/constants/shared.ts +++ b/common/constants/shared.ts @@ -15,6 +15,8 @@ export const OBSERVABILITY_BASE = '/api/observability'; export const INTEGRATIONS_BASE = '/api/integrations'; export const JOBS_BASE = '/query/jobs'; export const DATACONNECTIONS_BASE = '/api/dataconnections'; +export const EDIT = '/edit'; +export const SECURITY_ROLES = '/api/v1/configuration/roles'; export const EVENT_ANALYTICS = '/event_analytics'; export const SAVED_OBJECTS = '/saved_objects'; export const SAVED_QUERY = '/query'; diff --git a/public/components/datasources/components/__tests__/__snapshots__/data_connection.test.tsx.snap b/public/components/datasources/components/__tests__/__snapshots__/data_connection.test.tsx.snap index da46504aac..17da726043 100644 --- a/public/components/datasources/components/__tests__/__snapshots__/data_connection.test.tsx.snap +++ b/public/components/datasources/components/__tests__/__snapshots__/data_connection.test.tsx.snap @@ -297,6 +297,25 @@ exports[`Data Connection Page test Renders Prometheus data connection page with Control which OpenSearch users have access to this data source. +
+ +

+
+ +

{ + const [mode, setMode] = useState<'view' | 'edit'>('view'); + const [roles, setRoles] = useState([]); + const [hasSecurityAccess, setHasSecurityAccess] = useState(true); + const { http } = coreRefs; + + useEffect(() => { + http! + .get(SECURITY_ROLES) + .then((data) => + setRoles( + Object.keys(data.data).map((key) => { + return { label: key }; + }) + ) + ) + .catch((err) => setHasSecurityAccess(false)); + }, []); + const [selectedQueryPermissionRoles, setSelectedQueryPermissionRoles] = useState( props.allowedRoles.map((role) => { return { label: role }; @@ -44,6 +73,30 @@ export const AccessControlTab = (props: AccessControlTabProps) => { ); }; + const EditAccessControlDetails = () => { + return ( + + + + ); + }; + + const saveChanges = () => { + http!.post(`${DATACONNECTIONS_BASE}${EDIT}`, { + body: JSON.stringify({ + name: props.dataConnection, + allowedRoles: selectedQueryPermissionRoles.map((role) => role.label), + }), + }); + setMode('view'); + }; + const AccessControlHeader = () => { return ( @@ -53,6 +106,15 @@ export const AccessControlTab = (props: AccessControlTabProps) => { Control which OpenSearch users have access to this data source. + + setMode(mode === 'view' ? 'edit' : 'view')} + fill={mode === 'view' ? true : false} + > + {mode === 'view' ? 'Edit' : 'Cancel'} + + ); }; @@ -65,9 +127,17 @@ export const AccessControlTab = (props: AccessControlTabProps) => { - + {mode === 'view' ? : } + {mode === 'edit' && ( + { + setMode('view'); + }} + onSave={saveChanges} + /> + )} ); diff --git a/public/components/datasources/components/new/configure_datasource.tsx b/public/components/datasources/components/new/configure_datasource.tsx index 244ab0c4be..fcd435b1b5 100644 --- a/public/components/datasources/components/new/configure_datasource.tsx +++ b/public/components/datasources/components/new/configure_datasource.tsx @@ -18,7 +18,7 @@ import { import React, { useCallback, useEffect, useState } from 'react'; import { ConfigureS3Datasource } from './configure_s3_datasource'; import { coreRefs } from '../../../../../public/framework/core_refs'; -import { DATACONNECTIONS_BASE } from '../../../../../common/constants/shared'; +import { DATACONNECTIONS_BASE, SECURITY_ROLES } from '../../../../../common/constants/shared'; import { ReviewS3Datasource } from './review_s3_datasource_configuration'; import { useToast } from '../../../../../public/components/common/toast'; import { DatasourceType, Role } from '../../../../../common/types/data_connections'; @@ -67,7 +67,7 @@ export function Configure(props: ConfigureDatasourceProps) { useEffect(() => { http! - .get('/api/v1/configuration/roles') + .get(SECURITY_ROLES) .then((data) => setRoles( Object.keys(data.data).map((key) => { diff --git a/public/components/datasources/components/new/query_permissions.tsx b/public/components/datasources/components/new/query_permissions.tsx index d5a899c08a..1a66ae1987 100644 --- a/public/components/datasources/components/new/query_permissions.tsx +++ b/public/components/datasources/components/new/query_permissions.tsx @@ -82,7 +82,12 @@ export const QueryPermissionsConfiguration = (props: PermissionsConfigurationPro setSelectedAccessLevel(id)} + onChange={(id) => { + if (id === QUERY_ALL) { + setSelectedRoles([]); + } + setSelectedAccessLevel(id); + }} name="query-radio-group" legend={{ children: Query access level, diff --git a/server/adaptors/ppl_plugin.ts b/server/adaptors/ppl_plugin.ts index 6007f913f1..00e2445911 100644 --- a/server/adaptors/ppl_plugin.ts +++ b/server/adaptors/ppl_plugin.ts @@ -81,7 +81,7 @@ export const PPLPlugin = function (Client, config, components) { fmt: `${OPENSEARCH_DATACONNECTIONS_API.DATACONNECTION}`, }, needBody: true, - method: 'PUT', + method: 'PATCH', }); ppl.getDataConnections = ca({ diff --git a/server/routes/data_connections/data_connections_router.ts b/server/routes/data_connections/data_connections_router.ts index b75b53c439..66c0d3b6e6 100644 --- a/server/routes/data_connections/data_connections_router.ts +++ b/server/routes/data_connections/data_connections_router.ts @@ -9,7 +9,7 @@ import { IRouter, ResponseError, } from '../../../../../src/core/server'; -import { DATACONNECTIONS_BASE } from '../../../common/constants/shared'; +import { DATACONNECTIONS_BASE, EDIT } from '../../../common/constants/shared'; export function registerDataConnectionsRoute(router: IRouter) { router.get( @@ -70,15 +70,13 @@ export function registerDataConnectionsRoute(router: IRouter) { } ); - router.put( + router.post( { - path: `${DATACONNECTIONS_BASE}`, + path: `${DATACONNECTIONS_BASE}${EDIT}`, validate: { body: schema.object({ name: schema.string(), - connector: schema.string(), allowedRoles: schema.arrayOf(schema.string()), - properties: schema.any(), }), }, }, @@ -89,9 +87,7 @@ export function registerDataConnectionsRoute(router: IRouter) { .callAsCurrentUser('ppl.modifyDataConnection', { body: { name: request.body.name, - connector: request.body.connector, allowedRoles: request.body.allowedRoles, - properties: request.body.properties, }, }); return response.ok({