Fix assets page permissions handling

Signed-off-by: Émile Ré <nemile.re@gmail.com>
This commit is contained in:
Émile Ré
2025-12-31 15:52:27 +01:00
committed by Bryan Frimin
parent 7e22893fd2
commit a59e62782b
8 changed files with 207 additions and 54 deletions

View File

@@ -1,5 +1,5 @@
/** /**
* @generated SignedSource<<9ebcbef6d786f85d0b88c881d1478938>> * @generated SignedSource<<ea7d06a1fdefd4e76c3f7ee3ef27f8ec>>
* @lightSyntaxTransform * @lightSyntaxTransform
* @nogrep * @nogrep
*/ */
@@ -29,6 +29,8 @@ export type AssetGraphCreateMutation$data = {
readonly node: { readonly node: {
readonly amount: number; readonly amount: number;
readonly assetType: AssetType; readonly assetType: AssetType;
readonly canDelete: boolean;
readonly canUpdate: boolean;
readonly createdAt: any; readonly createdAt: any;
readonly dataTypesStored: string; readonly dataTypesStored: string;
readonly id: string; readonly id: string;
@@ -207,6 +209,32 @@ v5 = {
"kind": "ScalarField", "kind": "ScalarField",
"name": "createdAt", "name": "createdAt",
"storageKey": null "storageKey": null
},
{
"alias": "canUpdate",
"args": [
{
"kind": "Literal",
"name": "action",
"value": "core:asset:update"
}
],
"kind": "ScalarField",
"name": "permission",
"storageKey": "permission(action:\"core:asset:update\")"
},
{
"alias": "canDelete",
"args": [
{
"kind": "Literal",
"name": "action",
"value": "core:asset:delete"
}
],
"kind": "ScalarField",
"name": "permission",
"storageKey": "permission(action:\"core:asset:delete\")"
} }
], ],
"storageKey": null "storageKey": null
@@ -280,16 +308,16 @@ return {
] ]
}, },
"params": { "params": {
"cacheID": "bc22942b9b4b5efb63a0167c083823fc", "cacheID": "6e077b7787ccbc473247d102b0540e98",
"id": null, "id": null,
"metadata": {}, "metadata": {},
"name": "AssetGraphCreateMutation", "name": "AssetGraphCreateMutation",
"operationKind": "mutation", "operationKind": "mutation",
"text": "mutation AssetGraphCreateMutation(\n $input: CreateAssetInput!\n) {\n createAsset(input: $input) {\n assetEdge {\n node {\n id\n snapshotId\n name\n amount\n assetType\n dataTypesStored\n owner {\n id\n fullName\n }\n vendors(first: 50) {\n edges {\n node {\n id\n name\n websiteUrl\n }\n }\n }\n createdAt\n }\n }\n }\n}\n" "text": "mutation AssetGraphCreateMutation(\n $input: CreateAssetInput!\n) {\n createAsset(input: $input) {\n assetEdge {\n node {\n id\n snapshotId\n name\n amount\n assetType\n dataTypesStored\n owner {\n id\n fullName\n }\n vendors(first: 50) {\n edges {\n node {\n id\n name\n websiteUrl\n }\n }\n }\n createdAt\n canUpdate: permission(action: \"core:asset:update\")\n canDelete: permission(action: \"core:asset:delete\")\n }\n }\n }\n}\n"
} }
}; };
})(); })();
(node as any).hash = "92fca40d88a9ea68f013e9953d46388e"; (node as any).hash = "f337be2dfc0f146f33e1b94f65cfc199";
export default node; export default node;

View File

@@ -1,5 +1,5 @@
/** /**
* @generated SignedSource<<cd1648fe4f86e16da121483001ec1a80>> * @generated SignedSource<<ff88330f4c9b747f6936824eea6d0b54>>
* @lightSyntaxTransform * @lightSyntaxTransform
* @nogrep * @nogrep
*/ */
@@ -16,6 +16,7 @@ export type AssetGraphListQuery$variables = {
}; };
export type AssetGraphListQuery$data = { export type AssetGraphListQuery$data = {
readonly node: { readonly node: {
readonly canCreateAsset?: boolean;
readonly " $fragmentSpreads": FragmentRefs<"AssetsPageFragment">; readonly " $fragmentSpreads": FragmentRefs<"AssetsPageFragment">;
}; };
}; };
@@ -44,30 +45,43 @@ v1 = [
"variableName": "organizationId" "variableName": "organizationId"
} }
], ],
v2 = [ v2 = {
"alias": "canCreateAsset",
"args": [
{
"kind": "Literal",
"name": "action",
"value": "core:asset:create"
}
],
"kind": "ScalarField",
"name": "permission",
"storageKey": "permission(action:\"core:asset:create\")"
},
v3 = [
{ {
"kind": "Variable", "kind": "Variable",
"name": "snapshotId", "name": "snapshotId",
"variableName": "snapshotId" "variableName": "snapshotId"
} }
], ],
v3 = { v4 = {
"alias": null, "alias": null,
"args": null, "args": null,
"kind": "ScalarField", "kind": "ScalarField",
"name": "__typename", "name": "__typename",
"storageKey": null "storageKey": null
}, },
v4 = { v5 = {
"alias": null, "alias": null,
"args": null, "args": null,
"kind": "ScalarField", "kind": "ScalarField",
"name": "id", "name": "id",
"storageKey": null "storageKey": null
}, },
v5 = [ v6 = [
{ {
"fields": (v2/*: any*/), "fields": (v3/*: any*/),
"kind": "ObjectValue", "kind": "ObjectValue",
"name": "filter" "name": "filter"
}, },
@@ -77,7 +91,7 @@ v5 = [
"value": 10 "value": 10
} }
], ],
v6 = { v7 = {
"alias": null, "alias": null,
"args": null, "args": null,
"kind": "ScalarField", "kind": "ScalarField",
@@ -102,8 +116,9 @@ return {
{ {
"kind": "InlineFragment", "kind": "InlineFragment",
"selections": [ "selections": [
(v2/*: any*/),
{ {
"args": (v2/*: any*/), "args": (v3/*: any*/),
"kind": "FragmentSpread", "kind": "FragmentSpread",
"name": "AssetsPageFragment" "name": "AssetsPageFragment"
} }
@@ -132,14 +147,15 @@ return {
"name": "node", "name": "node",
"plural": false, "plural": false,
"selections": [ "selections": [
(v3/*: any*/),
(v4/*: any*/), (v4/*: any*/),
(v5/*: any*/),
{ {
"kind": "InlineFragment", "kind": "InlineFragment",
"selections": [ "selections": [
(v2/*: any*/),
{ {
"alias": null, "alias": null,
"args": (v5/*: any*/), "args": (v6/*: any*/),
"concreteType": "AssetConnection", "concreteType": "AssetConnection",
"kind": "LinkedField", "kind": "LinkedField",
"name": "assets", "name": "assets",
@@ -161,7 +177,7 @@ return {
"name": "node", "name": "node",
"plural": false, "plural": false,
"selections": [ "selections": [
(v4/*: any*/), (v5/*: any*/),
{ {
"alias": null, "alias": null,
"args": null, "args": null,
@@ -169,7 +185,7 @@ return {
"name": "snapshotId", "name": "snapshotId",
"storageKey": null "storageKey": null
}, },
(v6/*: any*/), (v7/*: any*/),
{ {
"alias": null, "alias": null,
"args": null, "args": null,
@@ -199,7 +215,7 @@ return {
"name": "owner", "name": "owner",
"plural": false, "plural": false,
"selections": [ "selections": [
(v4/*: any*/), (v5/*: any*/),
{ {
"alias": null, "alias": null,
"args": null, "args": null,
@@ -240,8 +256,8 @@ return {
"name": "node", "name": "node",
"plural": false, "plural": false,
"selections": [ "selections": [
(v4/*: any*/), (v5/*: any*/),
(v6/*: any*/), (v7/*: any*/),
{ {
"alias": null, "alias": null,
"args": null, "args": null,
@@ -265,7 +281,33 @@ return {
"name": "createdAt", "name": "createdAt",
"storageKey": null "storageKey": null
}, },
(v3/*: any*/) {
"alias": "canUpdate",
"args": [
{
"kind": "Literal",
"name": "action",
"value": "core:asset:update"
}
],
"kind": "ScalarField",
"name": "permission",
"storageKey": "permission(action:\"core:asset:update\")"
},
{
"alias": "canDelete",
"args": [
{
"kind": "Literal",
"name": "action",
"value": "core:asset:delete"
}
],
"kind": "ScalarField",
"name": "permission",
"storageKey": "permission(action:\"core:asset:delete\")"
},
(v4/*: any*/)
], ],
"storageKey": null "storageKey": null
}, },
@@ -335,7 +377,7 @@ return {
}, },
{ {
"alias": null, "alias": null,
"args": (v5/*: any*/), "args": (v6/*: any*/),
"filters": [ "filters": [
"filter" "filter"
], ],
@@ -354,16 +396,16 @@ return {
] ]
}, },
"params": { "params": {
"cacheID": "273752608722b727e8c8999b93d45cd4", "cacheID": "e55d3b21b1689a03329569da5669d216",
"id": null, "id": null,
"metadata": {}, "metadata": {},
"name": "AssetGraphListQuery", "name": "AssetGraphListQuery",
"operationKind": "query", "operationKind": "query",
"text": "query AssetGraphListQuery(\n $organizationId: ID!\n $snapshotId: ID\n) {\n node(id: $organizationId) {\n __typename\n ... on Organization {\n ...AssetsPageFragment_3iomuz\n }\n id\n }\n}\n\nfragment AssetsPageFragment_3iomuz on Organization {\n assets(first: 10, filter: {snapshotId: $snapshotId}) {\n edges {\n node {\n id\n snapshotId\n name\n amount\n assetType\n dataTypesStored\n owner {\n id\n fullName\n }\n vendors(first: 50) {\n edges {\n node {\n id\n name\n websiteUrl\n }\n }\n }\n createdAt\n __typename\n }\n cursor\n }\n pageInfo {\n endCursor\n hasNextPage\n hasPreviousPage\n startCursor\n }\n }\n id\n}\n" "text": "query AssetGraphListQuery(\n $organizationId: ID!\n $snapshotId: ID\n) {\n node(id: $organizationId) {\n __typename\n ... on Organization {\n canCreateAsset: permission(action: \"core:asset:create\")\n ...AssetsPageFragment_3iomuz\n }\n id\n }\n}\n\nfragment AssetsPageFragment_3iomuz on Organization {\n assets(first: 10, filter: {snapshotId: $snapshotId}) {\n edges {\n node {\n id\n snapshotId\n name\n amount\n assetType\n dataTypesStored\n owner {\n id\n fullName\n }\n vendors(first: 50) {\n edges {\n node {\n id\n name\n websiteUrl\n }\n }\n }\n createdAt\n canUpdate: permission(action: \"core:asset:update\")\n canDelete: permission(action: \"core:asset:delete\")\n __typename\n }\n cursor\n }\n pageInfo {\n endCursor\n hasNextPage\n hasPreviousPage\n startCursor\n }\n }\n id\n}\n"
} }
}; };
})(); })();
(node as any).hash = "4cbb1234b0884823285d3660334a2b29"; (node as any).hash = "319c01153f98cf6c927a07cbe6eed98e";
export default node; export default node;

View File

@@ -1,5 +1,5 @@
/** /**
* @generated SignedSource<<c8cbb4eb1df9d733a86642b8f27d6df6>> * @generated SignedSource<<37dc142d4245fcbf81a63926cd6c1c0e>>
* @lightSyntaxTransform * @lightSyntaxTransform
* @nogrep * @nogrep
*/ */
@@ -18,6 +18,8 @@ export type AssetGraphNodeQuery$data = {
readonly node: { readonly node: {
readonly amount?: number; readonly amount?: number;
readonly assetType?: AssetType; readonly assetType?: AssetType;
readonly canDelete?: boolean;
readonly canUpdate?: boolean;
readonly createdAt?: any; readonly createdAt?: any;
readonly dataTypesStored?: string; readonly dataTypesStored?: string;
readonly id?: string; readonly id?: string;
@@ -189,6 +191,32 @@ v11 = {
"kind": "ScalarField", "kind": "ScalarField",
"name": "updatedAt", "name": "updatedAt",
"storageKey": null "storageKey": null
},
v12 = {
"alias": "canUpdate",
"args": [
{
"kind": "Literal",
"name": "action",
"value": "core:asset:update"
}
],
"kind": "ScalarField",
"name": "permission",
"storageKey": "permission(action:\"core:asset:update\")"
},
v13 = {
"alias": "canDelete",
"args": [
{
"kind": "Literal",
"name": "action",
"value": "core:asset:delete"
}
],
"kind": "ScalarField",
"name": "permission",
"storageKey": "permission(action:\"core:asset:delete\")"
}; };
return { return {
"fragment": { "fragment": {
@@ -217,7 +245,9 @@ return {
(v8/*: any*/), (v8/*: any*/),
(v9/*: any*/), (v9/*: any*/),
(v10/*: any*/), (v10/*: any*/),
(v11/*: any*/) (v11/*: any*/),
(v12/*: any*/),
(v13/*: any*/)
], ],
"type": "Asset", "type": "Asset",
"abstractKey": null "abstractKey": null
@@ -262,7 +292,9 @@ return {
(v8/*: any*/), (v8/*: any*/),
(v9/*: any*/), (v9/*: any*/),
(v10/*: any*/), (v10/*: any*/),
(v11/*: any*/) (v11/*: any*/),
(v12/*: any*/),
(v13/*: any*/)
], ],
"type": "Asset", "type": "Asset",
"abstractKey": null "abstractKey": null
@@ -273,16 +305,16 @@ return {
] ]
}, },
"params": { "params": {
"cacheID": "f0aebb3dbefaf776a518bb72892d8983", "cacheID": "6cc4f590468366f12144c88b15704bac",
"id": null, "id": null,
"metadata": {}, "metadata": {},
"name": "AssetGraphNodeQuery", "name": "AssetGraphNodeQuery",
"operationKind": "query", "operationKind": "query",
"text": "query AssetGraphNodeQuery(\n $assetId: ID!\n) {\n node(id: $assetId) {\n __typename\n ... on Asset {\n id\n snapshotId\n name\n amount\n assetType\n dataTypesStored\n owner {\n id\n fullName\n }\n vendors(first: 50) {\n edges {\n node {\n id\n name\n websiteUrl\n category\n }\n }\n }\n createdAt\n updatedAt\n }\n id\n }\n}\n" "text": "query AssetGraphNodeQuery(\n $assetId: ID!\n) {\n node(id: $assetId) {\n __typename\n ... on Asset {\n id\n snapshotId\n name\n amount\n assetType\n dataTypesStored\n owner {\n id\n fullName\n }\n vendors(first: 50) {\n edges {\n node {\n id\n name\n websiteUrl\n category\n }\n }\n }\n createdAt\n updatedAt\n canUpdate: permission(action: \"core:asset:update\")\n canDelete: permission(action: \"core:asset:delete\")\n }\n id\n }\n}\n"
} }
}; };
})(); })();
(node as any).hash = "08e11e09bc4462efdbebc36aec347c4c"; (node as any).hash = "61e648da526c4b332ded50ba1daa3fbf";
export default node; export default node;

View File

@@ -1,5 +1,5 @@
/** /**
* @generated SignedSource<<794ba3ed2ccc75355a8c69c83d143587>> * @generated SignedSource<<a18d99b6e4ee0b256a7391f30ea1dc4f>>
* @lightSyntaxTransform * @lightSyntaxTransform
* @nogrep * @nogrep
*/ */
@@ -340,6 +340,32 @@ return {
"name": "createdAt", "name": "createdAt",
"storageKey": null "storageKey": null
}, },
{
"alias": "canUpdate",
"args": [
{
"kind": "Literal",
"name": "action",
"value": "core:asset:update"
}
],
"kind": "ScalarField",
"name": "permission",
"storageKey": "permission(action:\"core:asset:update\")"
},
{
"alias": "canDelete",
"args": [
{
"kind": "Literal",
"name": "action",
"value": "core:asset:delete"
}
],
"kind": "ScalarField",
"name": "permission",
"storageKey": "permission(action:\"core:asset:delete\")"
},
(v14/*: any*/) (v14/*: any*/)
], ],
"storageKey": null "storageKey": null
@@ -429,16 +455,16 @@ return {
] ]
}, },
"params": { "params": {
"cacheID": "71aa6b89d4eba225262e326fdfe04cf7", "cacheID": "350938b31ac1c7f7a28849123995da3a",
"id": null, "id": null,
"metadata": {}, "metadata": {},
"name": "AssetsListQuery", "name": "AssetsListQuery",
"operationKind": "query", "operationKind": "query",
"text": "query AssetsListQuery(\n $after: CursorKey = null\n $before: CursorKey = null\n $first: Int = 10\n $last: Int = null\n $orderBy: AssetOrder = null\n $snapshotId: ID = null\n $id: ID!\n) {\n node(id: $id) {\n __typename\n ...AssetsPageFragment_38J9tm\n id\n }\n}\n\nfragment AssetsPageFragment_38J9tm on Organization {\n assets(first: $first, after: $after, last: $last, before: $before, orderBy: $orderBy, filter: {snapshotId: $snapshotId}) {\n edges {\n node {\n id\n snapshotId\n name\n amount\n assetType\n dataTypesStored\n owner {\n id\n fullName\n }\n vendors(first: 50) {\n edges {\n node {\n id\n name\n websiteUrl\n }\n }\n }\n createdAt\n __typename\n }\n cursor\n }\n pageInfo {\n endCursor\n hasNextPage\n hasPreviousPage\n startCursor\n }\n }\n id\n}\n" "text": "query AssetsListQuery(\n $after: CursorKey = null\n $before: CursorKey = null\n $first: Int = 10\n $last: Int = null\n $orderBy: AssetOrder = null\n $snapshotId: ID = null\n $id: ID!\n) {\n node(id: $id) {\n __typename\n ...AssetsPageFragment_38J9tm\n id\n }\n}\n\nfragment AssetsPageFragment_38J9tm on Organization {\n assets(first: $first, after: $after, last: $last, before: $before, orderBy: $orderBy, filter: {snapshotId: $snapshotId}) {\n edges {\n node {\n id\n snapshotId\n name\n amount\n assetType\n dataTypesStored\n owner {\n id\n fullName\n }\n vendors(first: 50) {\n edges {\n node {\n id\n name\n websiteUrl\n }\n }\n }\n createdAt\n canUpdate: permission(action: \"core:asset:update\")\n canDelete: permission(action: \"core:asset:delete\")\n __typename\n }\n cursor\n }\n pageInfo {\n endCursor\n hasNextPage\n hasPreviousPage\n startCursor\n }\n }\n id\n}\n"
} }
}; };
})(); })();
(node as any).hash = "a230182c928f189b50fdc39950602ffd"; (node as any).hash = "4e870b93c801e9f0b6e26ab6069863fe";
export default node; export default node;

View File

@@ -1,5 +1,5 @@
/** /**
* @generated SignedSource<<6f077a71ef62a9c059bee1b50d3a23ef>> * @generated SignedSource<<f9b0ae27afd022a27fc3e8860ff72729>>
* @lightSyntaxTransform * @lightSyntaxTransform
* @nogrep * @nogrep
*/ */
@@ -18,6 +18,8 @@ export type AssetsPageFragment$data = {
readonly node: { readonly node: {
readonly amount: number; readonly amount: number;
readonly assetType: AssetType; readonly assetType: AssetType;
readonly canDelete: boolean;
readonly canUpdate: boolean;
readonly createdAt: any; readonly createdAt: any;
readonly dataTypesStored: string; readonly dataTypesStored: string;
readonly id: string; readonly id: string;
@@ -274,6 +276,32 @@ return {
"name": "createdAt", "name": "createdAt",
"storageKey": null "storageKey": null
}, },
{
"alias": "canUpdate",
"args": [
{
"kind": "Literal",
"name": "action",
"value": "core:asset:update"
}
],
"kind": "ScalarField",
"name": "permission",
"storageKey": "permission(action:\"core:asset:update\")"
},
{
"alias": "canDelete",
"args": [
{
"kind": "Literal",
"name": "action",
"value": "core:asset:delete"
}
],
"kind": "ScalarField",
"name": "permission",
"storageKey": "permission(action:\"core:asset:delete\")"
},
{ {
"alias": null, "alias": null,
"args": null, "args": null,
@@ -355,6 +383,6 @@ return {
}; };
})(); })();
(node as any).hash = "a230182c928f189b50fdc39950602ffd"; (node as any).hash = "4e870b93c801e9f0b6e26ab6069863fe";
export default node; export default node;

View File

@@ -9,6 +9,7 @@ export const assetsQuery = graphql`
query AssetGraphListQuery($organizationId: ID!, $snapshotId: ID) { query AssetGraphListQuery($organizationId: ID!, $snapshotId: ID) {
node(id: $organizationId) { node(id: $organizationId) {
... on Organization { ... on Organization {
canCreateAsset: permission(action: "core:asset:create")
...AssetsPageFragment @arguments(snapshotId: $snapshotId) ...AssetsPageFragment @arguments(snapshotId: $snapshotId)
} }
} }
@@ -41,6 +42,8 @@ export const assetNodeQuery = graphql`
} }
createdAt createdAt
updatedAt updatedAt
canUpdate: permission(action: "core:asset:update")
canDelete: permission(action: "core:asset:delete")
} }
} }
} }
@@ -74,6 +77,8 @@ export const createAssetMutation = graphql`
} }
} }
createdAt createdAt
canUpdate: permission(action: "core:asset:update")
canDelete: permission(action: "core:asset:delete")
} }
} }
} }

View File

@@ -32,8 +32,6 @@ import { VendorsMultiSelectField } from "/components/form/VendorsMultiSelectFiel
import type { AssetGraphNodeQuery } from "/__generated__/core/AssetGraphNodeQuery.graphql"; import type { AssetGraphNodeQuery } from "/__generated__/core/AssetGraphNodeQuery.graphql";
import { useFormWithSchema } from "/hooks/useFormWithSchema"; import { useFormWithSchema } from "/hooks/useFormWithSchema";
import { useOrganizationId } from "/hooks/useOrganizationId"; import { useOrganizationId } from "/hooks/useOrganizationId";
import { use } from "react";
import { PermissionsContext } from "/providers/PermissionsContext";
const updateAssetSchema = z.object({ const updateAssetSchema = z.object({
name: z.string().min(1, "Name is required"), name: z.string().min(1, "Name is required"),
@@ -58,7 +56,6 @@ export default function AssetDetailsPage(props: Props) {
const organizationId = useOrganizationId(); const organizationId = useOrganizationId();
const { snapshotId } = useParams<{ snapshotId?: string }>(); const { snapshotId } = useParams<{ snapshotId?: string }>();
const isSnapshotMode = Boolean(snapshotId); const isSnapshotMode = Boolean(snapshotId);
const { isAuthorized } = use(PermissionsContext);
validateSnapshotConsistency(assetEntry, snapshotId); validateSnapshotConsistency(assetEntry, snapshotId);
@@ -125,7 +122,7 @@ export default function AssetDetailsPage(props: Props) {
: __("Virtual")} : __("Virtual")}
</Badge> </Badge>
</div> </div>
{!isSnapshotMode && isAuthorized("Asset", "deleteAsset") && ( {!isSnapshotMode && asset.node.canDelete && (
<ActionDropdown variant="secondary"> <ActionDropdown variant="secondary">
<DropdownItem <DropdownItem
variant="danger" variant="danger"
@@ -189,9 +186,7 @@ export default function AssetDetailsPage(props: Props) {
/> />
<div className="flex justify-end"> <div className="flex justify-end">
{formState.isDirty && {formState.isDirty && !isSnapshotMode && asset.node.canUpdate && (
!isSnapshotMode &&
isAuthorized("Asset", "updateAsset") && (
<Button type="submit" disabled={formState.isSubmitting}> <Button type="submit" disabled={formState.isSubmitting}>
{formState.isSubmitting ? __("Updating...") : __("Update")} {formState.isSubmitting ? __("Updating...") : __("Update")}
</Button> </Button>

View File

@@ -1,7 +1,6 @@
import { usePageTitle } from "@probo/hooks"; import { usePageTitle } from "@probo/hooks";
import { useTranslate } from "@probo/i18n"; import { useTranslate } from "@probo/i18n";
import { Button, IconPlusLarge, PageHeader } from "@probo/ui"; import { Button, IconPlusLarge, PageHeader } from "@probo/ui";
import { use } from "react";
import { import {
graphql, graphql,
usePaginationFragment, usePaginationFragment,
@@ -17,7 +16,6 @@ import { SnapshotBanner } from "/components/SnapshotBanner";
import { assetsQuery } from "/hooks/graph/AssetGraph"; import { assetsQuery } from "/hooks/graph/AssetGraph";
import type { AssetGraphListQuery } from "/__generated__/core/AssetGraphListQuery.graphql"; import type { AssetGraphListQuery } from "/__generated__/core/AssetGraphListQuery.graphql";
import { useOrganizationId } from "/hooks/useOrganizationId"; import { useOrganizationId } from "/hooks/useOrganizationId";
import { PermissionsContext } from "/providers/PermissionsContext";
const paginatedAssetsFragment = graphql` const paginatedAssetsFragment = graphql`
fragment AssetsPageFragment on Organization fragment AssetsPageFragment on Organization
@@ -61,6 +59,8 @@ const paginatedAssetsFragment = graphql`
} }
} }
createdAt createdAt
canUpdate: permission(action: "core:asset:update")
canDelete: permission(action: "core:asset:delete")
} }
} }
} }
@@ -88,10 +88,7 @@ export default function AssetsPage(props: Props) {
const assets = pagination.data.assets?.edges.map((edge) => edge.node); const assets = pagination.data.assets?.edges.map((edge) => edge.node);
const connectionId = pagination.data.assets.__id; const connectionId = pagination.data.assets.__id;
const { isAuthorized } = use(PermissionsContext); const canWrite = assets.some((asset) => asset.canDelete || asset.canUpdate);
const canWrite =
isAuthorized("Asset", "updateAsset") ||
isAuthorized("Asset", "deleteAsset");
usePageTitle(__("Assets")); usePageTitle(__("Assets"));
return ( return (
@@ -103,7 +100,7 @@ export default function AssetsPage(props: Props) {
"Manage your organization's assets and their classifications.", "Manage your organization's assets and their classifications.",
)} )}
> >
{!isSnapshotMode && isAuthorized("Organization", "createAsset") && ( {!isSnapshotMode && data.node.canCreateAsset && (
<CreateAssetDialog <CreateAssetDialog
connection={connectionId} connection={connectionId}
organizationId={organizationId} organizationId={organizationId}