Fix trust center audist documents files tabs permissions handling
Signed-off-by: Émile Ré <nemile.re@gmail.com>
This commit is contained in:
@@ -14,7 +14,7 @@ import {
|
||||
} from "@probo/ui";
|
||||
import { useTranslate } from "@probo/i18n";
|
||||
import { useFragment } from "react-relay";
|
||||
import { useMemo, useState, useCallback, useEffect, use } from "react";
|
||||
import { useMemo, useState, useCallback, useEffect } from "react";
|
||||
import {
|
||||
sprintf,
|
||||
getAuditStateVariant,
|
||||
@@ -24,7 +24,6 @@ import {
|
||||
} from "@probo/helpers";
|
||||
import { useOrganizationId } from "/hooks/useOrganizationId";
|
||||
import type { TrustCenterAuditsCardFragment$key } from "/__generated__/core/TrustCenterAuditsCardFragment.graphql";
|
||||
import { PermissionsContext } from "/providers/PermissionsContext";
|
||||
|
||||
const trustCenterAuditFragment = graphql`
|
||||
fragment TrustCenterAuditsCardFragment on Audit {
|
||||
@@ -55,6 +54,7 @@ type Props<Params> = {
|
||||
params: Params;
|
||||
disabled?: boolean;
|
||||
onChangeVisibility: Mutation<Params>;
|
||||
canUpdate: boolean;
|
||||
};
|
||||
|
||||
export function TrustCenterAuditsCard<Params>(props: Props<Params>) {
|
||||
@@ -104,6 +104,7 @@ export function TrustCenterAuditsCard<Params>(props: Props<Params>) {
|
||||
<AuditRow
|
||||
key={index}
|
||||
auditFragmentRef={audit}
|
||||
canUpdate={props.canUpdate}
|
||||
onChangeVisibility={onChangeVisibility}
|
||||
disabled={props.disabled}
|
||||
/>
|
||||
@@ -131,16 +132,13 @@ function AuditRow(props: {
|
||||
trustCenterVisibility: "NONE" | "PRIVATE" | "PUBLIC",
|
||||
) => void;
|
||||
disabled?: boolean;
|
||||
canUpdate: boolean;
|
||||
}) {
|
||||
const { auditFragmentRef, onChangeVisibility, disabled } = props;
|
||||
const { auditFragmentRef, onChangeVisibility, disabled, canUpdate } = props;
|
||||
const audit = useFragment(trustCenterAuditFragment, auditFragmentRef);
|
||||
const organizationId = useOrganizationId();
|
||||
const { __ } = useTranslate();
|
||||
const [optimisticValue, setOptimisticValue] = useState<string | null>(null);
|
||||
const { isAuthorized } = use(PermissionsContext);
|
||||
const canUpdate = organizationId
|
||||
? isAuthorized("TrustCenter", "updateTrustCenter")
|
||||
: false;
|
||||
|
||||
const handleValueChange = useCallback(
|
||||
(value: string) => {
|
||||
|
||||
@@ -17,10 +17,9 @@ import {
|
||||
import { useTranslate } from "@probo/i18n";
|
||||
import type { TrustCenterDocumentsCardFragment$key } from "/__generated__/core/TrustCenterDocumentsCardFragment.graphql";
|
||||
import { useFragment } from "react-relay";
|
||||
import { useMemo, useState, useCallback, useEffect, use } from "react";
|
||||
import { useMemo, useState, useCallback, useEffect } from "react";
|
||||
import { sprintf, getTrustCenterVisibilityOptions } from "@probo/helpers";
|
||||
import { useOrganizationId } from "/hooks/useOrganizationId";
|
||||
import { PermissionsContext } from "/providers/PermissionsContext";
|
||||
|
||||
const trustCenterDocumentFragment = graphql`
|
||||
fragment TrustCenterDocumentsCardFragment on Document {
|
||||
@@ -54,6 +53,7 @@ type Props<Params> = {
|
||||
params: Params;
|
||||
disabled?: boolean;
|
||||
onChangeVisibility: Mutation<Params>;
|
||||
canUpdate: boolean;
|
||||
};
|
||||
|
||||
export function TrustCenterDocumentsCard<Params>(props: Props<Params>) {
|
||||
@@ -104,6 +104,7 @@ export function TrustCenterDocumentsCard<Params>(props: Props<Params>) {
|
||||
documentFragmentRef={document}
|
||||
onChangeVisibility={onChangeVisibility}
|
||||
disabled={props.disabled}
|
||||
canUpdate={props.canUpdate}
|
||||
/>
|
||||
))}
|
||||
</Tbody>
|
||||
@@ -129,8 +130,10 @@ function DocumentRow(props: {
|
||||
trustCenterVisibility: "NONE" | "PRIVATE" | "PUBLIC",
|
||||
) => void;
|
||||
disabled?: boolean;
|
||||
canUpdate: boolean;
|
||||
}) {
|
||||
const { documentFragmentRef, onChangeVisibility, disabled } = props;
|
||||
const { documentFragmentRef, onChangeVisibility, disabled, canUpdate } =
|
||||
props;
|
||||
const document = useFragment(
|
||||
trustCenterDocumentFragment,
|
||||
documentFragmentRef,
|
||||
@@ -138,8 +141,6 @@ function DocumentRow(props: {
|
||||
const organizationId = useOrganizationId();
|
||||
const { __ } = useTranslate();
|
||||
const [optimisticValue, setOptimisticValue] = useState<string | null>(null);
|
||||
const { isAuthorized } = use(PermissionsContext);
|
||||
const canUpdate = isAuthorized("TrustCenter", "updateTrustCenter");
|
||||
|
||||
const handleValueChange = useCallback(
|
||||
(value: string) => {
|
||||
|
||||
@@ -21,10 +21,9 @@ import type {
|
||||
TrustCenterFilesCardFragment$data,
|
||||
} from "/__generated__/core/TrustCenterFilesCardFragment.graphql";
|
||||
import { useFragment } from "react-relay";
|
||||
import { useMemo, useState, useCallback, useEffect, use } from "react";
|
||||
import { useMemo, useState, useCallback, useEffect } from "react";
|
||||
import { sprintf, getTrustCenterVisibilityOptions } from "@probo/helpers";
|
||||
import { formatDate } from "@probo/helpers";
|
||||
import { PermissionsContext } from "/providers/PermissionsContext";
|
||||
|
||||
const trustCenterFileFragment = graphql`
|
||||
fragment TrustCenterFilesCardFragment on TrustCenterFile {
|
||||
@@ -35,6 +34,8 @@ const trustCenterFileFragment = graphql`
|
||||
trustCenterVisibility
|
||||
createdAt
|
||||
updatedAt
|
||||
canUpdate: permission(action: "core:trust-center-file:update")
|
||||
canDelete: permission(action: "core:trust-center-file:delete")
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -54,6 +55,7 @@ type Props<Params> = {
|
||||
onChangeVisibility: Mutation<Params>;
|
||||
onEdit: (file: { id: string; name: string; category: string }) => void;
|
||||
onDelete: (id: string) => void;
|
||||
canUpdate: boolean;
|
||||
};
|
||||
|
||||
export function TrustCenterFilesCard<Params>(props: Props<Params>) {
|
||||
@@ -107,6 +109,7 @@ export function TrustCenterFilesCard<Params>(props: Props<Params>) {
|
||||
onEdit={props.onEdit}
|
||||
onDelete={props.onDelete}
|
||||
disabled={props.disabled}
|
||||
canUpdate={props.canUpdate}
|
||||
/>
|
||||
))}
|
||||
</Tbody>
|
||||
@@ -134,6 +137,7 @@ function FileRowWrapper(props: {
|
||||
onEdit: (file: { id: string; name: string; category: string }) => void;
|
||||
onDelete: (id: string) => void;
|
||||
disabled?: boolean;
|
||||
canUpdate: boolean;
|
||||
}) {
|
||||
const file = useFragment(trustCenterFileFragment, props.fileFragmentRef);
|
||||
return (
|
||||
@@ -143,6 +147,7 @@ function FileRowWrapper(props: {
|
||||
onEdit={props.onEdit}
|
||||
onDelete={props.onDelete}
|
||||
disabled={props.disabled}
|
||||
canUpdate={props.canUpdate}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -156,12 +161,12 @@ function FileRow(props: {
|
||||
onEdit: (file: { id: string; name: string; category: string }) => void;
|
||||
onDelete: (id: string) => void;
|
||||
disabled?: boolean;
|
||||
canUpdate: boolean;
|
||||
}) {
|
||||
const { file, onChangeVisibility, onEdit, onDelete, disabled } = props;
|
||||
const { file, onChangeVisibility, onEdit, onDelete, disabled, canUpdate } =
|
||||
props;
|
||||
const { __ } = useTranslate();
|
||||
const [optimisticValue, setOptimisticValue] = useState<string | null>(null);
|
||||
const { isAuthorized } = use(PermissionsContext);
|
||||
const canUpdate = isAuthorized("TrustCenter", "updateTrustCenter");
|
||||
|
||||
const handleValueChange = useCallback(
|
||||
(value: string) => {
|
||||
@@ -217,7 +222,7 @@ function FileRow(props: {
|
||||
}
|
||||
title={__("Download")}
|
||||
/>
|
||||
{isAuthorized("TrustCenterFile", "updateTrustCenterFile") && (
|
||||
{file.canUpdate && (
|
||||
<Button
|
||||
variant="secondary"
|
||||
icon={IconPencil}
|
||||
@@ -232,7 +237,7 @@ function FileRow(props: {
|
||||
title={__("Edit")}
|
||||
/>
|
||||
)}
|
||||
{isAuthorized("TrustCenterFile", "deleteTrustCenterFile") && (
|
||||
{file.canDelete && (
|
||||
<Button
|
||||
variant="danger"
|
||||
icon={IconTrashCan}
|
||||
|
||||
Reference in New Issue
Block a user