Skip to content

Commit

Permalink
fix: hide dev ui links for users with viewer rights
Browse files Browse the repository at this point in the history
  • Loading branch information
artemmufazalov committed Jan 15, 2025
1 parent 1b74502 commit 793ae34
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/components/BasicNodeViewer/BasicNodeViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import React from 'react';
import {ArrowUpRightFromSquare} from '@gravity-ui/icons';
import {Icon} from '@gravity-ui/uikit';

import {selectIsUserAllowedToMakeChanges} from '../../store/reducers/authentication/authentication';
import type {PreparedNode} from '../../store/reducers/node/types';
import type {AdditionalNodesProps} from '../../types/additionalProps';
import {cn} from '../../utils/cn';
import {
createDeveloperUIInternalPageHref,
createDeveloperUILinkWithNodeId,
} from '../../utils/developerUI/developerUI';
import {useTypedSelector} from '../../utils/hooks';
import {EntityStatus} from '../EntityStatus/EntityStatus';
import {Tags} from '../Tags';

Expand All @@ -24,6 +26,8 @@ interface BasicNodeViewerProps {
}

export const BasicNodeViewer = ({node, additionalNodesProps, className}: BasicNodeViewerProps) => {
const isUserAllowedToMakeChanges = useTypedSelector(selectIsUserAllowedToMakeChanges);

let developerUIInternalHref: string | undefined;

if (additionalNodesProps?.getNodeRef) {
Expand All @@ -42,7 +46,7 @@ export const BasicNodeViewer = ({node, additionalNodesProps, className}: BasicNo
<React.Fragment>
<div className={b('title')}>Node</div>
<EntityStatus status={node.SystemState} name={node.Host} />
{developerUIInternalHref && (
{developerUIInternalHref && isUserAllowedToMakeChanges ? (
<a
rel="noopener noreferrer"
className={b('link', {external: true})}
Expand All @@ -51,7 +55,7 @@ export const BasicNodeViewer = ({node, additionalNodesProps, className}: BasicNo
>
<Icon data={ArrowUpRightFromSquare} />
</a>
)}
) : null}

<div className={b('id')}>
<label className={b('label')}>NodeID</label>
Expand Down
12 changes: 8 additions & 4 deletions src/containers/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {Breadcrumbs} from '@gravity-ui/uikit';

import {InternalLink} from '../../components/InternalLink';
import {LinkWithIcon} from '../../components/LinkWithIcon/LinkWithIcon';
import {selectIsUserAllowedToMakeChanges} from '../../store/reducers/authentication/authentication';
import {useClusterBaseInfo} from '../../store/reducers/cluster/cluster';
import {cn} from '../../utils/cn';
import {DEVELOPER_UI_TITLE} from '../../utils/constants';
Expand All @@ -23,6 +24,7 @@ interface HeaderProps {

function Header({mainPage}: HeaderProps) {
const {page, pageBreadcrumbsOptions} = useTypedSelector((state) => state.header);
const isUserAllowedToMakeChanges = useTypedSelector(selectIsUserAllowedToMakeChanges);

const clusterInfo = useClusterBaseInfo();

Expand Down Expand Up @@ -78,10 +80,12 @@ function Header({mainPage}: HeaderProps) {
}}
/>

<LinkWithIcon
title={DEVELOPER_UI_TITLE}
url={createDeveloperUIInternalPageHref()}
/>
{isUserAllowedToMakeChanges ? (
<LinkWithIcon
title={DEVELOPER_UI_TITLE}
url={createDeveloperUIInternalPageHref()}
/>
) : null}
</header>
);
};
Expand Down
17 changes: 14 additions & 3 deletions src/containers/Node/NodeStructure/Pdisk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {PDiskInfo} from '../../../components/PDiskInfo/PDiskInfo';
import {ProgressViewer} from '../../../components/ProgressViewer/ProgressViewer';
import {StatusIcon} from '../../../components/StatusIcon/StatusIcon';
import {VDiskInfo} from '../../../components/VDiskInfo/VDiskInfo';
import {selectIsUserAllowedToMakeChanges} from '../../../store/reducers/authentication/authentication';
import type {
PreparedStructurePDisk,
PreparedStructureVDisk,
Expand All @@ -22,6 +23,7 @@ import {cn} from '../../../utils/cn';
import {DEFAULT_TABLE_SETTINGS} from '../../../utils/constants';
import {formatStorageValuesToGb} from '../../../utils/dataFormatters/dataFormatters';
import {createVDiskDeveloperUILink} from '../../../utils/developerUI/developerUI';
import {useTypedSelector} from '../../../utils/hooks';
import i18n from '../i18n';

import {PDiskTitleBadge} from './PDiskTitleBadge';
Expand Down Expand Up @@ -56,10 +58,12 @@ function getColumns({
pDiskId,
selectedVdiskId,
nodeId,
withDeveloperUILink,
}: {
pDiskId: number | undefined;
selectedVdiskId?: string;
nodeId?: string | number;
withDeveloperUILink?: boolean;
}) {
const columns: Column<PreparedStructureVDisk>[] = [
{
Expand All @@ -85,7 +89,7 @@ function getColumns({
return (
<div className={b('vdisk-id', {selected: row.id === selectedVdiskId})}>
<span>{vDiskSlotId}</span>
{vdiskInternalViewerLink && (
{vdiskInternalViewerLink && withDeveloperUILink ? (
<Button
size="s"
className={b('external-button', {hidden: true})}
Expand All @@ -95,7 +99,7 @@ function getColumns({
>
<Icon data={ArrowUpRightFromSquare} />
</Button>
)}
) : null}
</div>
);
},
Expand Down Expand Up @@ -167,6 +171,8 @@ export function PDisk({
nodeId,
unfolded: unfoldedFromProps,
}: PDiskProps) {
const isUserAllowedToMakeChanges = useTypedSelector(selectIsUserAllowedToMakeChanges);

const [unfolded, setUnfolded] = React.useState(unfoldedFromProps ?? false);

const {TotalSize = 0, AvailableSize = 0, Device, PDiskId, Type, vDisks} = data;
Expand All @@ -186,7 +192,12 @@ export function PDisk({
<DataTable
theme="yandex-cloud"
data={vDisks}
columns={getColumns({nodeId, pDiskId: PDiskId, selectedVdiskId})}
columns={getColumns({
nodeId,
pDiskId: PDiskId,
selectedVdiskId,
withDeveloperUILink: isUserAllowedToMakeChanges,
})}
settings={{...DEFAULT_TABLE_SETTINGS, dynamicRender: false}}
rowClassName={(row) => {
return row.id === selectedVdiskId ? b('selected-vdisk') : '';
Expand Down

0 comments on commit 793ae34

Please sign in to comment.