1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-05-03 01:18:43 +02:00

Fix/strategy permissions (#337)

* fix: only show actions if applicable to the current user

* fix: remove API access from admin settings

* fix: update snapshot
This commit is contained in:
Fredrik Strand Oseberg 2021-09-20 16:59:04 +02:00 committed by GitHub
parent 0baa7b22e9
commit 34df8617d2
3 changed files with 58 additions and 45 deletions

View File

@ -1,4 +1,4 @@
import React from 'react'; import React, { useContext } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { CardHeader, Typography, IconButton, Tooltip } from '@material-ui/core'; import { CardHeader, Typography, IconButton, Tooltip } from '@material-ui/core';
@ -7,6 +7,8 @@ import { Edit, Delete } from '@material-ui/icons';
import { useStyles } from './StrategyCardHeader.styles.js'; import { useStyles } from './StrategyCardHeader.styles.js';
import { ReactComponent as ReorderIcon } from '../../../../../assets/icons/reorder.svg'; import { ReactComponent as ReorderIcon } from '../../../../../assets/icons/reorder.svg';
import ConditionallyRender from '../../../../common/ConditionallyRender/ConditionallyRender'; import ConditionallyRender from '../../../../common/ConditionallyRender/ConditionallyRender';
import AccessContext from '../../../../../contexts/AccessContext';
import { UPDATE_FEATURE } from '../../../../AccessProvider/permissions';
const StrategyCardHeader = ({ const StrategyCardHeader = ({
name, name,
@ -15,6 +17,8 @@ const StrategyCardHeader = ({
editStrategy, editStrategy,
disableDelete, disableDelete,
}) => { }) => {
const { hasAccess } = useContext(AccessContext);
const styles = useStyles(); const styles = useStyles();
return ( return (
@ -33,14 +37,20 @@ const StrategyCardHeader = ({
{name} {name}
</Typography> </Typography>
</Tooltip> </Tooltip>
<ConditionallyRender
condition={hasAccess(UPDATE_FEATURE)}
show={
<div className={styles.strategyCardHeaderActions}> <div className={styles.strategyCardHeaderActions}>
<Tooltip title="Edit strategy"> <Tooltip title="Edit strategy">
<IconButton onClick={editStrategy}> <IconButton onClick={editStrategy}>
<Edit <Edit
className={styles.strateyCardHeaderIcon} className={
styles.strateyCardHeaderIcon
}
/> />
</IconButton> </IconButton>
</Tooltip> </Tooltip>
{connectDragSource( {connectDragSource(
<span> <span>
<Tooltip title="Drag and drop strategy to reorder. This only affects the order of which your strategies are evaluated."> <Tooltip title="Drag and drop strategy to reorder. This only affects the order of which your strategies are evaluated.">
@ -70,7 +80,9 @@ const StrategyCardHeader = ({
} }
elseShow={ elseShow={
<Tooltip title="Delete strategy"> <Tooltip title="Delete strategy">
<IconButton onClick={removeStrategy}> <IconButton
onClick={removeStrategy}
>
<Delete <Delete
className={ className={
styles.strateyCardHeaderIcon styles.strateyCardHeaderIcon
@ -81,6 +93,8 @@ const StrategyCardHeader = ({
} }
/> />
</div> </div>
}
/>
</> </>
} }
disableTypography disableTypography

View File

@ -333,7 +333,6 @@ Array [
"component": [Function], "component": [Function],
"layout": "main", "layout": "main",
"menu": Object { "menu": Object {
"adminSettings": true,
"advanced": true, "advanced": true,
"mobile": true, "mobile": true,
}, },

View File

@ -380,7 +380,7 @@ export const routes = [
component: AdminApi, component: AdminApi,
type: 'protected', type: 'protected',
layout: 'main', layout: 'main',
menu: { mobile: true, advanced: true, adminSettings: true }, menu: { mobile: true, advanced: true },
}, },
{ {
path: '/admin/users', path: '/admin/users',