All files / src/hooks/common/documents useFilePermissions.ts

100% Statements 6/6
66.66% Branches 2/3
100% Functions 2/2
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25          69x 1157x     1157x   1157x 2215x     1157x                  
import RESOURCE_BASE from "@constants/permissions";
import { useAppSelector } from "@redux/hooks";
import { selectIsAllowedByResource } from "@redux/slices/accessControl/accessControl";
import { composePermission } from "features/Permissions/AccessControl";
 
const useFilePermissions = (isEnterprise = false) => {
  const portal = isEnterprise
    ? RESOURCE_BASE.ENTERPRISE
    : RESOURCE_BASE.MERCHANT;
  const permission = composePermission(portal, RESOURCE_BASE.FILES);
 
  const filesPermissions = useAppSelector((state) =>
    selectIsAllowedByResource(state, permission),
  );
 
  return {
    isListAllowed: filesPermissions.read === "allow",
    isAddAllowed: filesPermissions.create === "allow",
    isUpdateAllowed: filesPermissions.update === "allow",
    isDeleteAllowed: filesPermissions.delete === "allow",
  };
};
 
export default useFilePermissions;