From c1f39266f192a9d48032f04aec6096dfe82c23f2 Mon Sep 17 00:00:00 2001 From: Polina Arzhevikina <polina.arzhevikina@materna.group> Date: Wed, 22 Jan 2025 16:26:14 +0100 Subject: [PATCH 1/2] fix permission --- frontend/src/components/policies/index.tsx | 46 +++++++++++----------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/frontend/src/components/policies/index.tsx b/frontend/src/components/policies/index.tsx index c14e8b5..a45d7c0 100644 --- a/frontend/src/components/policies/index.tsx +++ b/frontend/src/components/policies/index.tsx @@ -72,18 +72,7 @@ const CustomAddButton = ({conditionType}) => { </ListItemIcon> Access Based </MenuItem> - <MenuItem value="identity" onClick={handleAdd} disableRipple> - <ListItemIcon> - <PermIdentityIcon /> - </ListItemIcon> - Identity Based - </MenuItem> - <MenuItem value="location" onClick={handleAdd} disableRipple> - <ListItemIcon> - <LocationOnIcon /> - </ListItemIcon> - Location Based - </MenuItem> + </Menu> </> ) @@ -101,13 +90,25 @@ const CustomAddButton = ({conditionType}) => { </ListItemIcon> Membership Based </MenuItem> + <MenuItem value="identity" onClick={handleAdd} disableRipple> + <ListItemIcon> + <PermIdentityIcon /> + </ListItemIcon> + Identity Based + </MenuItem> + <MenuItem value="location" onClick={handleAdd} disableRipple> + <ListItemIcon> + <LocationOnIcon /> + </ListItemIcon> + Location Based + </MenuItem> </Menu> </> ) } }; -const IdentityBasedObligation = () => { +const IdentityBasedPermission = () => { const { field: { value: operatorValue }, } = useInput({ source: "operator" }); @@ -129,7 +130,7 @@ const IdentityBasedObligation = () => { return ( <> - <Typography sx={{ mt: 2 }}>Identity Based Obligation</Typography> + <Typography sx={{ mt: 2 }}>Identity Based Permission</Typography> <TextInput source="leftOperand" defaultValue="Membership.membershipId" @@ -214,7 +215,7 @@ const MembershipBasedPermission = () => { </>) }; -const LocationBasedObligation = () => { +const LocationBasedPermission = () => { const { field: { value: operatorValue }, } = useInput({ source: "operator" }); @@ -242,7 +243,7 @@ const LocationBasedObligation = () => { return ( <> - <Typography sx={{ mt: 2 }}>Location Based Obligation</Typography> + <Typography sx={{ mt: 2 }}>Location Based Permission</Typography> <TextInput source="leftOperand" defaultValue="Membership.country" @@ -383,12 +384,7 @@ const ObligationCreate = () => { if (type === "access") { return <AccessBasedObligation />; } - if (type === "identity") { - return <IdentityBasedObligation />; - } - if (type === "location") { - return <LocationBasedObligation />; - } + return null; }; @@ -407,6 +403,12 @@ const PermissionCreate = () => { const renderPermission = ({ type }) => { if (type === "membership") { return <MembershipBasedPermission />; + } + if (type === "identity") { + return <IdentityBasedPermission />; + } + if (type === "location") { + return <LocationBasedPermission />; } return null; }; -- GitLab From 59ebc91941fb48621554f88f166ade5964f01402 Mon Sep 17 00:00:00 2001 From: Polina Arzhevikina <polina.arzhevikina@materna.group> Date: Thu, 23 Jan 2025 14:59:06 +0100 Subject: [PATCH 2/2] got rid of obligation input --- frontend/src/components/policies/index.tsx | 85 +++++++++++----------- 1 file changed, 44 insertions(+), 41 deletions(-) diff --git a/frontend/src/components/policies/index.tsx b/frontend/src/components/policies/index.tsx index a45d7c0..be718a0 100644 --- a/frontend/src/components/policies/index.tsx +++ b/frontend/src/components/policies/index.tsx @@ -59,25 +59,7 @@ const CustomAddButton = ({conditionType}) => { context.append({ type: event.target.getAttribute("value") }); setAnchorEl(null); }; - if (conditionType == 'obligation'){ - return( - <> - <IconButton color="primary" onClick={handleClick}> - <AddCircleOutlineIcon /> - </IconButton> - <Menu anchorEl={anchorEl} open={open} onClose={handleClose}> - <MenuItem value="access" onClick={handleAdd} disableRipple> - <ListItemIcon> - <KeyIcon /> - </ListItemIcon> - Access Based - </MenuItem> - - </Menu> - </> - ) - } - else if (conditionType == 'permission'){ + if (conditionType == 'permission'){ return ( <> <IconButton color="primary" onClick={handleClick}> @@ -102,10 +84,28 @@ const CustomAddButton = ({conditionType}) => { </ListItemIcon> Location Based </MenuItem> + <MenuItem value="access" onClick={handleAdd} disableRipple> + <ListItemIcon> + <KeyIcon /> + </ListItemIcon> + Access Based + </MenuItem> </Menu> </> ) } + // uncomment when there are obligation policies + // else if (conditionType == 'obligation'){ + // return( + // <> + // <IconButton color="primary" onClick={handleClick}> + // <AddCircleOutlineIcon /> + // </IconButton> + // <Menu anchorEl={anchorEl} open={open} onClose={handleClose}> + // </Menu> + // </> + // ) + // } }; const IdentityBasedPermission = () => { @@ -154,10 +154,10 @@ const IdentityBasedPermission = () => { ); }; -const AccessBasedObligation = () => { +const AccessBasedPermission = () => { return ( <> - <Typography sx={{ mt: 2 }}>Access Based Obligation</Typography> + <Typography sx={{ mt: 2 }}>Access Based Permission</Typography> <TextInput source="leftOperand" defaultValue="DataAccess.level" @@ -379,25 +379,24 @@ export const PolicyShow = () => { ); }; -const ObligationCreate = () => { - const renderObligation = ({ type }) => { - if (type === "access") { - return <AccessBasedObligation />; - } +// uncomment when there are policies for obligations +// const ObligationCreate = () => { +// const renderObligation = ({ type }) => { + +// {} +// return null; +// }; - return null; - }; - - return ( - <SimpleFormIterator addButton={<CustomAddButton conditionType={"obligation"} />}> - <FormDataConsumer> - {({ scopedFormData }) => { - return renderObligation({ type: scopedFormData.type }); - }} - </FormDataConsumer> - </SimpleFormIterator> - ); -}; +// return ( +// <SimpleFormIterator addButton={<CustomAddButton conditionType={"obligation"} />}> +// <FormDataConsumer> +// {({ scopedFormData }) => { +// return renderObligation({ type: scopedFormData.type }); +// }} +// </FormDataConsumer> +// </SimpleFormIterator> +// ); +// }; const PermissionCreate = () => { const renderPermission = ({ type }) => { @@ -410,6 +409,9 @@ const PermissionCreate = () => { if (type === "location") { return <LocationBasedPermission />; } + if (type === "access") { + return <AccessBasedPermission />; + } return null; }; @@ -449,9 +451,10 @@ export const PolicyCreate = (props: any) => ( <ArrayInput source="permissions"> <PermissionCreate /> </ArrayInput> - <ArrayInput source="obligations"> + {/* uncomment when there are policies for obligations */} + {/* <ArrayInput source="obligations"> <ObligationCreate /> - </ArrayInput> + </ArrayInput> */} </Grid> </Grid> </SimpleForm> -- GitLab