fix(ui): hide elasticSearchIndex page for non-admins (#9077)

* fix(ui): hide elasticSearchIndex page for non-admins

* address comments

* remove unwanted field from children
This commit is contained in:
Chirag Madlani 2022-12-02 16:53:20 +05:30 committed by GitHub
parent 1bddfefbcd
commit 0973acc77f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 10 deletions

View File

@ -18,6 +18,7 @@ import React, { useMemo } from 'react';
import { useHistory, useParams } from 'react-router-dom'; import { useHistory, useParams } from 'react-router-dom';
import { GlobalSettingOptions } from '../../constants/GlobalSettings.constants'; import { GlobalSettingOptions } from '../../constants/GlobalSettings.constants';
import { TeamType } from '../../generated/entity/teams/team'; import { TeamType } from '../../generated/entity/teams/team';
import { useAuth } from '../../hooks/authHooks';
import { import {
getGlobalSettingMenuItem, getGlobalSettingMenuItem,
getGlobalSettingsMenuWithPermission, getGlobalSettingsMenuWithPermission,
@ -34,9 +35,11 @@ const GlobalSettingLeftPanel = () => {
const { permissions } = usePermissionProvider(); const { permissions } = usePermissionProvider();
const { isAdminUser } = useAuth();
const menuItems: ItemType[] = useMemo( const menuItems: ItemType[] = useMemo(
() => () =>
getGlobalSettingsMenuWithPermission(permissions).reduce( getGlobalSettingsMenuWithPermission(permissions, isAdminUser).reduce(
(acc: ItemType[], curr: MenuList) => { (acc: ItemType[], curr: MenuList) => {
const menuItem = getGlobalSettingMenuItem( const menuItem = getGlobalSettingMenuItem(
curr.category, curr.category,

View File

@ -234,10 +234,7 @@ const GlobalSettingRouter = () => {
<AdminProtectedRoute <AdminProtectedRoute
exact exact
component={ElasticSearchIndexPage} component={ElasticSearchIndexPage}
hasPermission={userPermissions.hasViewPermissions( hasPermission={false}
ResourceEntity.ALL,
permissions
)}
path={getSettingPath( path={getSettingPath(
GlobalSettingsMenuCategory.EVENT_PUBLISHERS, GlobalSettingsMenuCategory.EVENT_PUBLISHERS,
GlobalSettingOptions.ELASTIC_SEARCH GlobalSettingOptions.ELASTIC_SEARCH

View File

@ -48,7 +48,8 @@ export interface MenuList {
} }
export const getGlobalSettingsMenuWithPermission = ( export const getGlobalSettingsMenuWithPermission = (
permissions: UIPermission permissions: UIPermission,
isAdminUser: boolean | undefined
) => { ) => {
return [ return [
{ {
@ -218,10 +219,7 @@ export const getGlobalSettingsMenuWithPermission = (
items: [ items: [
{ {
label: 'Elasticsearch', label: 'Elasticsearch',
isProtected: userPermissions.hasViewPermissions( isProtected: Boolean(isAdminUser),
ResourceEntity.ALL,
permissions
),
icon: ( icon: (
<ElasticSearchIcon className="tw-w-4 tw-mt-1.5 side-panel-icons" /> <ElasticSearchIcon className="tw-w-4 tw-mt-1.5 side-panel-icons" />
), ),