Merge pull request #1948 from automatisch/AUT-1076

feat: block access to flow creation for users without permissions
This commit is contained in:
Ali BARIN
2024-07-04 10:44:15 +02:00
committed by GitHub
3 changed files with 16 additions and 4 deletions

View File

@@ -5,8 +5,10 @@ import AddCircleIcon from '@mui/icons-material/AddCircle';
import CardActionArea from '@mui/material/CardActionArea'; import CardActionArea from '@mui/material/CardActionArea';
import Typography from '@mui/material/Typography'; import Typography from '@mui/material/Typography';
import { CardContent } from './style'; import { CardContent } from './style';
export default function NoResultFound(props) { export default function NoResultFound(props) {
const { text, to } = props; const { text, to } = props;
const ActionAreaLink = React.useMemo( const ActionAreaLink = React.useMemo(
() => () =>
React.forwardRef(function InlineLink(linkProps, ref) { React.forwardRef(function InlineLink(linkProps, ref) {
@@ -15,12 +17,12 @@ export default function NoResultFound(props) {
}), }),
[to], [to],
); );
return ( return (
<Card elevation={0}> <Card elevation={0}>
<CardActionArea component={ActionAreaLink} {...props}> <CardActionArea component={ActionAreaLink} {...props}>
<CardContent> <CardContent>
{!!to && <AddCircleIcon color="primary" />} {!!to && <AddCircleIcon color="primary" />}
<Typography variant="body1">{text}</Typography> <Typography variant="body1">{text}</Typography>
</CardContent> </CardContent>
</CardActionArea> </CardActionArea>

View File

@@ -7,13 +7,15 @@ import * as URLS from 'config/urls';
import useFormatMessage from 'hooks/useFormatMessage'; import useFormatMessage from 'hooks/useFormatMessage';
import { CREATE_FLOW } from 'graphql/mutations/create-flow'; import { CREATE_FLOW } from 'graphql/mutations/create-flow';
import Box from '@mui/material/Box'; import Box from '@mui/material/Box';
export default function CreateFlow() { export default function CreateFlow() {
const [searchParams] = useSearchParams(); const [searchParams] = useSearchParams();
const navigate = useNavigate(); const navigate = useNavigate();
const formatMessage = useFormatMessage(); const formatMessage = useFormatMessage();
const [createFlow] = useMutation(CREATE_FLOW); const [createFlow, { error }] = useMutation(CREATE_FLOW);
const appKey = searchParams.get('appKey'); const appKey = searchParams.get('appKey');
const connectionId = searchParams.get('connectionId'); const connectionId = searchParams.get('connectionId');
React.useEffect(() => { React.useEffect(() => {
async function initiate() { async function initiate() {
const variables = {}; const variables = {};
@@ -33,6 +35,11 @@ export default function CreateFlow() {
} }
initiate(); initiate();
}, [createFlow, navigate, appKey, connectionId]); }, [createFlow, navigate, appKey, connectionId]);
if (error) {
return null;
}
return ( return (
<Box <Box
sx={{ sx={{
@@ -45,7 +52,6 @@ export default function CreateFlow() {
}} }}
> >
<CircularProgress size={16} thickness={7.5} /> <CircularProgress size={16} thickness={7.5} />
<Typography variant="body2"> <Typography variant="body2">
{formatMessage('createFlow.creating')} {formatMessage('createFlow.creating')}
</Typography> </Typography>

View File

@@ -17,6 +17,7 @@ import Container from 'components/Container';
import PageTitle from 'components/PageTitle'; import PageTitle from 'components/PageTitle';
import SearchInput from 'components/SearchInput'; import SearchInput from 'components/SearchInput';
import useFormatMessage from 'hooks/useFormatMessage'; import useFormatMessage from 'hooks/useFormatMessage';
import useCurrentUserAbility from 'hooks/useCurrentUserAbility';
import * as URLS from 'config/urls'; import * as URLS from 'config/urls';
import useLazyFlows from 'hooks/useLazyFlows'; import useLazyFlows from 'hooks/useLazyFlows';
@@ -26,6 +27,7 @@ export default function Flows() {
const page = parseInt(searchParams.get('page') || '', 10) || 1; const page = parseInt(searchParams.get('page') || '', 10) || 1;
const [flowName, setFlowName] = React.useState(''); const [flowName, setFlowName] = React.useState('');
const [isLoading, setIsLoading] = React.useState(false); const [isLoading, setIsLoading] = React.useState(false);
const currentUserAbility = useCurrentUserAbility();
const { data, mutate: fetchFlows } = useLazyFlows( const { data, mutate: fetchFlows } = useLazyFlows(
{ flowName, page }, { flowName, page },
@@ -124,7 +126,9 @@ export default function Flows() {
{!isLoading && !hasFlows && ( {!isLoading && !hasFlows && (
<NoResultFound <NoResultFound
text={formatMessage('flows.noFlows')} text={formatMessage('flows.noFlows')}
to={URLS.CREATE_FLOW} {...(currentUserAbility.can('create', 'Flow') && {
to: URLS.CREATE_FLOW,
})}
/> />
)} )}
{!isLoading && pageInfo && pageInfo.totalPages > 1 && ( {!isLoading && pageInfo && pageInfo.totalPages > 1 && (