-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
filter high level groups and action groups by cluster and index #1482
Merged
cwperks
merged 11 commits into
opensearch-project:main
from
derek-ho:filter-in-dropdown
Jul 11, 2023
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9c11750
filter high level groups and action groups by cluster and index
derek-ho 38c151a
remove unecessary console
derek-ho 8c0fbe3
add semicolon back
derek-ho 974f02f
use map instead of flat map
derek-ho 62220bb
fix lint
derek-ho 2485ca6
Merge branch 'main' into filter-in-dropdown
derek-ho a8f27ce
fix tests
derek-ho 1d98208
revert file
derek-ho f66725a
fix up tests
derek-ho e692169
lint
derek-ho cfa7907
Merge branch 'main' into filter-in-dropdown
derek-ho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 161 additions & 0 deletions
161
public/apps/configuration/panels/role-edit/test/role-edit-filtering.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
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'; | ||
|
||
import { act } from 'react-dom/test-utils'; | ||
import { IndexPermissionPanel } from '../index-permission-panel'; | ||
import { CLUSTER_PERMISSIONS, INDEX_PERMISSIONS } from '../../../constants'; | ||
|
||
jest.mock('../../../utils/role-detail-utils', () => ({ | ||
getRoleDetail: jest.fn().mockReturnValue({ | ||
cluster_permissions: [], | ||
index_permissions: [], | ||
tenant_permissions: [], | ||
reserved: false, | ||
}), | ||
updateRole: jest.fn(), | ||
})); | ||
jest.mock('../../../utils/action-groups-utils'); | ||
|
||
jest.mock('../cluster-permission-panel', () => ({ | ||
ClusterPermissionPanel: jest.fn(() => null) as jest.Mock, | ||
})); | ||
|
||
jest.mock('../index-permission-panel', () => ({ | ||
IndexPermissionPanel: jest.fn(() => null) as jest.Mock, | ||
})); | ||
|
||
describe('Role edit filtering', () => { | ||
const sampleSourceRole = 'role'; | ||
const mockCoreStart = { | ||
http: 1, | ||
}; | ||
|
||
(fetchActionGroups as jest.Mock).mockResolvedValue({ | ||
data_access: { | ||
reserved: true, | ||
hidden: false, | ||
allowed_actions: ['indices:data/*', 'crud'], | ||
type: 'index', | ||
description: 'Allow all read/write operations on data', | ||
static: true, | ||
}, | ||
cluster_manage_pipelines: { | ||
reserved: true, | ||
hidden: false, | ||
allowed_actions: ['cluster:admin/ingest/pipeline/*'], | ||
type: 'cluster', | ||
description: 'Manage pipelines', | ||
static: true, | ||
}, | ||
}); | ||
|
||
it('basic cluster permission panel rendering', async () => { | ||
const action = 'create'; | ||
const buildBreadcrumbs = jest.fn(); | ||
|
||
render( | ||
<RoleEdit | ||
action={action} | ||
sourceRoleName={sampleSourceRole} | ||
buildBreadcrumbs={buildBreadcrumbs} | ||
coreStart={mockCoreStart as any} | ||
navigation={{} as any} | ||
params={{} as any} | ||
config={{} as any} | ||
/> | ||
); | ||
|
||
await act(async () => { | ||
await waitFor(() => { | ||
expect(ClusterPermissionPanel).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
const lastCallArgs = | ||
ClusterPermissionPanel.mock.calls[ClusterPermissionPanel.mock.calls.length - 1]; | ||
const [props] = lastCallArgs; | ||
|
||
// 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', | ||
options: [ | ||
{ | ||
label: 'cluster_manage_pipelines', | ||
}, | ||
], | ||
}, | ||
{ | ||
label: 'Cluster permissions', | ||
options: CLUSTER_PERMISSIONS.map((x) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Much more robust and less lines of code :) |
||
return { label: x }; | ||
}), | ||
}, | ||
]); | ||
}); | ||
|
||
it('basic index permission panel rendering', async () => { | ||
const action = 'create'; | ||
const buildBreadcrumbs = jest.fn(); | ||
|
||
render( | ||
<RoleEdit | ||
action={action} | ||
sourceRoleName={sampleSourceRole} | ||
buildBreadcrumbs={buildBreadcrumbs} | ||
coreStart={mockCoreStart as any} | ||
navigation={{} as any} | ||
params={{} as any} | ||
config={{} as any} | ||
/> | ||
); | ||
|
||
await act(async () => { | ||
await waitFor(() => { | ||
expect(IndexPermissionPanel).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
const lastCallArgs = | ||
IndexPermissionPanel.mock.calls[IndexPermissionPanel.mock.calls.length - 1]; | ||
const [props] = lastCallArgs; | ||
|
||
// 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', | ||
options: [ | ||
{ | ||
label: 'data_access', | ||
}, | ||
], | ||
}, | ||
{ | ||
label: 'Index permissions', | ||
options: INDEX_PERMISSIONS.map((x) => { | ||
return { label: x }; | ||
}), | ||
}, | ||
]); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for my understanding, why are we needing this
ActionGroupItem
, or can we use the originalAction
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If i'm understanding your question correctly I need the whole item here in order to tell whether it is a cluster/index one later on in order to filter them accordingly