From 279343b87bed51da35ef339869eb952b19de6673 Mon Sep 17 00:00:00 2001 From: Derek Ho Date: Wed, 1 Nov 2023 14:57:53 -0400 Subject: [PATCH 1/2] Fix bug where custom/non cluster/index permission groups were being lost from the dropdown Signed-off-by: Derek Ho --- .../panels/role-edit/role-edit.tsx | 18 ++++++++++-- .../test/role-edit-filtering.test.tsx | 29 +++++++++++++++++-- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/public/apps/configuration/panels/role-edit/role-edit.tsx b/public/apps/configuration/panels/role-edit/role-edit.tsx index 142cba1b3..46f5b3e36 100644 --- a/public/apps/configuration/panels/role-edit/role-edit.tsx +++ b/public/apps/configuration/panels/role-edit/role-edit.tsx @@ -166,12 +166,19 @@ export function RoleEdit(props: RoleEditDeps) { const clusterWisePermissionOptions = [ { - label: 'Permission groups', + label: 'Cluster permission groups', options: actionGroups .filter((actionGroup) => actionGroup[1].type === 'cluster') .map((actionGroup) => actionGroup[0]) .map(stringToComboBoxOption), }, + { + label: 'Other permission groups', + options: actionGroups + .filter((actionGroup) => (actionGroup[1].type !== 'index' && actionGroup[1].type !== 'cluster')) + .map((actionGroup) => actionGroup[0]) + .map(stringToComboBoxOption), + }, { label: 'Cluster permissions', options: CLUSTER_PERMISSIONS.map(stringToComboBoxOption), @@ -180,12 +187,19 @@ export function RoleEdit(props: RoleEditDeps) { const indexWisePermissionOptions = [ { - label: 'Permission groups', + label: 'Index permission groups', options: actionGroups .filter((actionGroup) => actionGroup[1].type === 'index') .map((actionGroup) => actionGroup[0]) .map(stringToComboBoxOption), }, + { + label: 'Other permission groups', + options: actionGroups + .filter((actionGroup) => (actionGroup[1].type !== 'index' && actionGroup[1].type !== 'cluster')) + .map((actionGroup) => actionGroup[0]) + .map(stringToComboBoxOption), + }, { label: 'Index permissions', options: INDEX_PERMISSIONS.map(stringToComboBoxOption), diff --git a/public/apps/configuration/panels/role-edit/test/role-edit-filtering.test.tsx b/public/apps/configuration/panels/role-edit/test/role-edit-filtering.test.tsx index 7142db663..4f3a4f909 100644 --- a/public/apps/configuration/panels/role-edit/test/role-edit-filtering.test.tsx +++ b/public/apps/configuration/panels/role-edit/test/role-edit-filtering.test.tsx @@ -16,7 +16,6 @@ import React from 'react'; import { ClusterPermissionPanel } from '../cluster-permission-panel'; import { RoleEdit } from '../role-edit'; -import { ActionGroupItem } from '../../../types'; import { fetchActionGroups } from '../../../utils/action-groups-utils'; import { render, waitFor } from '@testing-library/react'; @@ -67,6 +66,14 @@ describe('Role edit filtering', () => { description: 'Manage pipelines', static: true, }, + custom: { + reserved: false, + hidden: false, + allowed_actions: ['cluster:admin/ingest/pipeline/*'], + type: undefined, + description: 'Custom group', + static: true, + }, }); it('basic cluster permission panel rendering', async () => { @@ -98,13 +105,21 @@ describe('Role edit filtering', () => { // Cluster Permission Panel props is filtered to action groups with type cluster, and only the cluster permission constants expect(props.optionUniverse).toEqual([ { - label: 'Permission groups', + label: 'Cluster permission groups', options: [ { label: 'cluster_manage_pipelines', }, ], }, + { + label: 'Other permission groups', + options: [ + { + label: 'custom', + }, + ], + }, { label: 'Cluster permissions', options: CLUSTER_PERMISSIONS.map((x) => { @@ -143,13 +158,21 @@ describe('Role edit filtering', () => { // Index Permission Panel props is filtered to action groups with type index, and only the index permission constants expect(props.optionUniverse).toEqual([ { - label: 'Permission groups', + label: 'Index permission groups', options: [ { label: 'data_access', }, ], }, + { + label: 'Other permission groups', + options: [ + { + label: 'custom', + }, + ], + }, { label: 'Index permissions', options: INDEX_PERMISSIONS.map((x) => { From 95a083e0d7efc01612a402aa748245b211ec8b70 Mon Sep 17 00:00:00 2001 From: Derek Ho Date: Wed, 1 Nov 2023 16:03:22 -0400 Subject: [PATCH 2/2] Only use undefined type in other section Signed-off-by: Derek Ho --- public/apps/configuration/panels/role-edit/role-edit.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/apps/configuration/panels/role-edit/role-edit.tsx b/public/apps/configuration/panels/role-edit/role-edit.tsx index 46f5b3e36..e5b3c832a 100644 --- a/public/apps/configuration/panels/role-edit/role-edit.tsx +++ b/public/apps/configuration/panels/role-edit/role-edit.tsx @@ -175,7 +175,7 @@ export function RoleEdit(props: RoleEditDeps) { { label: 'Other permission groups', options: actionGroups - .filter((actionGroup) => (actionGroup[1].type !== 'index' && actionGroup[1].type !== 'cluster')) + .filter((actionGroup) => actionGroup[1].type === undefined) .map((actionGroup) => actionGroup[0]) .map(stringToComboBoxOption), }, @@ -196,7 +196,7 @@ export function RoleEdit(props: RoleEditDeps) { { label: 'Other permission groups', options: actionGroups - .filter((actionGroup) => (actionGroup[1].type !== 'index' && actionGroup[1].type !== 'cluster')) + .filter((actionGroup) => actionGroup[1].type === undefined) .map((actionGroup) => actionGroup[0]) .map(stringToComboBoxOption), },