Skip to content

Commit

Permalink
changes to permission settings UI
Browse files Browse the repository at this point in the history
  • Loading branch information
t83714 committed Aug 29, 2023
1 parent ccf16c8 commit 0aebcf3
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,14 @@ const PermissionDataGrid: FunctionComponent<PropsType> = (props) => {
)}
</Cell>
</Column>
<Column width={120} resizable>
<HeaderCell>Allow Exemption</HeaderCell>
<Cell align="center">
{(rowData: RolePermissionRecord) => (
<CheckBoxIcon value={rowData.allow_exemption} />
)}
</Cell>
</Column>
<Column width={120} fixed="right">
<HeaderCell align="center">Action</HeaderCell>
<Cell
Expand Down
57 changes: 55 additions & 2 deletions magda-web-client/src/Components/Settings/PermissionFormPopUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import React, {
useState,
forwardRef,
useImperativeHandle,
useRef
useRef,
useCallback
} from "react";
import Modal from "rsuite/Modal";
import Button from "rsuite/Button";
Expand All @@ -21,6 +22,7 @@ import "./PermissionFormPopUp.scss";
import Form from "rsuite/Form";
import Notification from "rsuite/Notification";
import { toaster } from "rsuite";
import Toggle from "rsuite/Toggle";
import { ItemDataType } from "rsuite/esm/@types/common";
import {
getPermissionById,
Expand Down Expand Up @@ -110,6 +112,21 @@ const constraintTooltip = (
</Popover>
);

const constraintExemptionTooltip = (
<Popover style={{ width: "500px" }}>
<p>
Users might set some resources as "public" (via supported resources'
`access-control.constraintExemption`) to allow users with
"restricted" permissions to access the resources regardless of their
current scope & the constraints of the permission granted to them.
<br />
This option allows system admin to specify whether the permission's
restrctions / constraints can be ignored when access those "public"
resources.
</p>
</Popover>
);

const PermissionFormPopUp: ForwardRefRenderFunction<RefType, PropsType> = (
props,
ref
Expand All @@ -123,6 +140,18 @@ const PermissionFormPopUp: ForwardRefRenderFunction<RefType, PropsType> = (
const [dataReloadToken, setdataReloadToken] = useState<string>("");
const selectedResourceId = permission?.resource_id;

const toggleAllowExemption = useCallback(
() =>
setPermission(
(p) =>
({
...p,
allow_exemption: !p?.allow_exemption
} as any)
),
[]
);

useImperativeHandle(ref, () => ({
open: (
selectPermissionId?: string,
Expand Down Expand Up @@ -243,7 +272,8 @@ const PermissionFormPopUp: ForwardRefRenderFunction<RefType, PropsType> = (
pre_authorised_constraint: permission.pre_authorised_constraint
? true
: false,
operationIds: permission.operationIds
operationIds: permission.operationIds,
allow_exemption: permission.allow_exemption ? true : false
};
if (isCreateForm) {
const newPermission = await createRolePermission(
Expand Down Expand Up @@ -455,6 +485,29 @@ const PermissionFormPopUp: ForwardRefRenderFunction<RefType, PropsType> = (
</Checkbox>
</Form.Control>
</Form.Group>
<Form.Group controlId="ctrl-constraint-exemption">
<span>
Allow Exemption?{" "}
<Whisper
placement="top"
controlId="ctrl-constraint-exemption-tooltip-hover"
trigger="hover"
speaker={constraintExemptionTooltip}
>
<span>
<MdInfoOutline />
</span>
</Whisper>
</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<Toggle
size="lg"
checkedChildren="Yes"
unCheckedChildren="No"
checked={permission?.allow_exemption}
onChange={toggleAllowExemption}
/>
</Form.Group>
<Form.Group controlId="ctrl-description">
<Form.ControlLabel>
Description:
Expand Down

0 comments on commit 0aebcf3

Please sign in to comment.