feat(rbac): made changes from testing with maidul

This commit is contained in:
Akhil Mohan
2023-09-08 21:22:36 +05:30
parent 252042fb20
commit 98893a40f1
19 changed files with 612 additions and 529 deletions
@@ -7,12 +7,18 @@ import { Tooltip } from "../v2";
type Props = {
label?: ReactNode;
// this prop is used when there exist already a tooltip as helper text for users
// so when permission is allowed same tooltip will be reused to show helpertext
renderTooltip?: boolean;
allowedLabel?: string;
} & BoundCanProps<TOrgPermission>;
export const OrgPermissionCan: FunctionComponent<Props> = ({
label = "Permission Denied. Kindly contact your org admin",
children,
passThrough = true,
renderTooltip,
allowedLabel,
...props
}) => {
const permission = useOrgPermission();
@@ -30,6 +36,10 @@ export const OrgPermissionCan: FunctionComponent<Props> = ({
return <Tooltip content={label}>{finalChild}</Tooltip>;
}
if (isAllowed && renderTooltip) {
return <Tooltip content={allowedLabel}>{finalChild}</Tooltip>;
}
if (!isAllowed) return null;
return finalChild;
@@ -7,12 +7,18 @@ import { Tooltip } from "../v2";
type Props = {
label?: ReactNode;
// this prop is used when there exist already a tooltip as helper text for users
// so when permission is allowed same tooltip will be reused to show helpertext
renderTooltip?: boolean;
allowedLabel?: string;
} & BoundCanProps<TProjectPermission>;
export const ProjectPermissionCan: FunctionComponent<Props> = ({
label = "Permission Denied. Kindly contact your project admin",
children,
passThrough = true,
renderTooltip,
allowedLabel,
...props
}) => {
const permission = useProjectPermission();
@@ -30,6 +36,10 @@ export const ProjectPermissionCan: FunctionComponent<Props> = ({
return <Tooltip content={label}>{finalChild}</Tooltip>;
}
if (isAllowed && renderTooltip) {
return <Tooltip content={allowedLabel}>{finalChild}</Tooltip>;
}
if (!isAllowed) return null;
return finalChild;