From b4888f21238d23e1c4a656ee408e778677036505 Mon Sep 17 00:00:00 2001 From: Robin Huang Date: Tue, 21 May 2024 11:58:04 -0700 Subject: [PATCH 1/2] Hide edit details when you don't own the publisher/node. --- components/nodes/NodeDetails.tsx | 15 +- components/publisher/PublisherDetail.tsx | 104 +++++---- src/api/generated.ts | 270 +++++++++++++++++------ 3 files changed, 278 insertions(+), 111 deletions(-) diff --git a/components/nodes/NodeDetails.tsx b/components/nodes/NodeDetails.tsx index 1c12c86..1aa85a7 100644 --- a/components/nodes/NodeDetails.tsx +++ b/components/nodes/NodeDetails.tsx @@ -6,7 +6,14 @@ import nodesLogo from '../../public/images/nodesLogo.svg' import NodeVDrawer from './NodeVDrawer' import Link from 'next/link' import { NodeEditModal } from './NodeEditModal' -import { NodeVersion, useGetNode, useListNodeVersions } from 'src/api/generated' +import { + NodeVersion, + useGetNode, + useGetPermissionOnPublisherNodes, + useListNodeVersions, + useListNodesForPublisher, + useListPublishersForUser, +} from 'src/api/generated' import CopyableCodeBlock from '../CodeBlock/CodeBlock' export function formatRelativeDate(dateString: string) { @@ -40,6 +47,10 @@ const NodeDetails = () => { const [selectedVersion, setSelectedVersion] = useState( null ) + const { data: permissions } = useGetPermissionOnPublisherNodes( + publisherId as string, + nodeId as string + ) const [openEditModal, setIsEditModal] = useState(false) const { data, isLoading, isError } = useGetNode(nodeId as string) const { @@ -245,7 +256,7 @@ const NodeDetails = () => { - {publisherId && ( + {permissions?.canEdit && ( + + Edit details + + )}

@{publisher.id}

@@ -175,28 +185,30 @@ const PublisherDetail: React.FC = ({ publisher }) => {

)}
- - deleteTokenMutation.mutate( - { - publisherId: publisher.id as string, - tokenId: tokenId, - }, - { - onError: (error) => { - toast.error('Failed to delete token') + {permissions?.canEdit && ( + + deleteTokenMutation.mutate( + { + publisherId: publisher.id as string, + tokenId: tokenId, }, - onSuccess: () => { - toast.success('Token deleted') - refetchTokens() - }, - } - ) - } - /> + { + onError: (error) => { + toast.error('Failed to delete token') + }, + onSuccess: () => { + toast.success('Token deleted') + refetchTokens() + }, + } + ) + } + /> + )} { } -export const getListAllNodesQueryOptions = >, TError = void | Error>(params?: ListAllNodesParams, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} +export const getListAllNodesQueryOptions = >, TError = void | ErrorResponse>(params?: ListAllNodesParams, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} ) => { const {query: queryOptions, request: requestOptions} = options ?? {}; @@ -749,12 +765,12 @@ const {query: queryOptions, request: requestOptions} = options ?? {}; } export type ListAllNodesQueryResult = NonNullable>> -export type ListAllNodesQueryError = void | Error +export type ListAllNodesQueryError = void | ErrorResponse /** * @summary Retrieves a list of nodes */ -export const useListAllNodes = >, TError = void | Error>( +export const useListAllNodes = >, TError = void | ErrorResponse>( params?: ListAllNodesParams, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} ): UseQueryResult & { queryKey: QueryKey } => { @@ -793,7 +809,7 @@ export const getGetNodeQueryKey = (nodeId: string,) => { } -export const getGetNodeQueryOptions = >, TError = Error>(nodeId: string, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} +export const getGetNodeQueryOptions = >, TError = ErrorResponse>(nodeId: string, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} ) => { const {query: queryOptions, request: requestOptions} = options ?? {}; @@ -812,12 +828,12 @@ const {query: queryOptions, request: requestOptions} = options ?? {}; } export type GetNodeQueryResult = NonNullable>> -export type GetNodeQueryError = Error +export type GetNodeQueryError = ErrorResponse /** * @summary Retrieve a specific node by ID */ -export const useGetNode = >, TError = Error>( +export const useGetNode = >, TError = ErrorResponse>( nodeId: string, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} ): UseQueryResult & { queryKey: QueryKey } => { @@ -859,7 +875,7 @@ export const getInstallNodeQueryKey = (nodeId: string, } -export const getInstallNodeQueryOptions = >, TError = Error | void>(nodeId: string, +export const getInstallNodeQueryOptions = >, TError = ErrorResponse>(nodeId: string, params?: InstallNodeParams, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} ) => { @@ -879,12 +895,12 @@ const {query: queryOptions, request: requestOptions} = options ?? {}; } export type InstallNodeQueryResult = NonNullable>> -export type InstallNodeQueryError = Error | void +export type InstallNodeQueryError = ErrorResponse /** * @summary Returns a node version to be installed. */ -export const useInstallNode = >, TError = Error | void>( +export const useInstallNode = >, TError = ErrorResponse>( nodeId: string, params?: InstallNodeParams, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} @@ -923,7 +939,7 @@ export const getListNodeVersionsQueryKey = (nodeId: string,) => { } -export const getListNodeVersionsQueryOptions = >, TError = Error>(nodeId: string, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} +export const getListNodeVersionsQueryOptions = >, TError = Error | ErrorResponse>(nodeId: string, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} ) => { const {query: queryOptions, request: requestOptions} = options ?? {}; @@ -942,12 +958,12 @@ const {query: queryOptions, request: requestOptions} = options ?? {}; } export type ListNodeVersionsQueryResult = NonNullable>> -export type ListNodeVersionsQueryError = Error +export type ListNodeVersionsQueryError = Error | ErrorResponse /** * @summary List all versions of a node */ -export const useListNodeVersions = >, TError = Error>( +export const useListNodeVersions = >, TError = Error | ErrorResponse>( nodeId: string, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} ): UseQueryResult & { queryKey: QueryKey } => { @@ -987,7 +1003,7 @@ export const getGetNodeVersionQueryKey = (nodeId: string, } -export const getGetNodeVersionQueryOptions = >, TError = Error>(nodeId: string, +export const getGetNodeVersionQueryOptions = >, TError = Error | ErrorResponse>(nodeId: string, versionId: string, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} ) => { @@ -1007,12 +1023,12 @@ const {query: queryOptions, request: requestOptions} = options ?? {}; } export type GetNodeVersionQueryResult = NonNullable>> -export type GetNodeVersionQueryError = Error +export type GetNodeVersionQueryError = Error | ErrorResponse /** * @summary Retrieve a specific version of a node */ -export const useGetNodeVersion = >, TError = Error>( +export const useGetNodeVersion = >, TError = Error | ErrorResponse>( nodeId: string, versionId: string, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} @@ -1051,7 +1067,7 @@ export const getListPublishersQueryKey = () => { } -export const getListPublishersQueryOptions = >, TError = void>( options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} +export const getListPublishersQueryOptions = >, TError = ErrorResponse>( options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} ) => { const {query: queryOptions, request: requestOptions} = options ?? {}; @@ -1070,12 +1086,12 @@ const {query: queryOptions, request: requestOptions} = options ?? {}; } export type ListPublishersQueryResult = NonNullable>> -export type ListPublishersQueryError = void +export type ListPublishersQueryError = ErrorResponse /** * @summary Retrieve all publishers */ -export const useListPublishers = >, TError = void>( +export const useListPublishers = >, TError = ErrorResponse>( options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} ): UseQueryResult & { queryKey: QueryKey } => { @@ -1110,7 +1126,7 @@ export const createPublisher = ( -export const getCreatePublisherMutationOptions = (options?: { mutation?:UseMutationOptions>, TError,{data: Publisher}, TContext>, request?: SecondParameter} ): UseMutationOptions>, TError,{data: Publisher}, TContext> => { const {mutation: mutationOptions, request: requestOptions} = options ?? {}; @@ -1131,12 +1147,12 @@ const {mutation: mutationOptions, request: requestOptions} = options ?? {}; export type CreatePublisherMutationResult = NonNullable>> export type CreatePublisherMutationBody = Publisher - export type CreatePublisherMutationError = void | Error + export type CreatePublisherMutationError = ErrorResponse | void /** * @summary Create a new publisher */ -export const useCreatePublisher = (options?: { mutation?:UseMutationOptions>, TError,{data: Publisher}, TContext>, request?: SecondParameter} ): UseMutationResult< Awaited>, @@ -1173,7 +1189,7 @@ export const getValidatePublisherQueryKey = (params: ValidatePublisherParams,) = } -export const getValidatePublisherQueryOptions = >, TError = Error | void>(params: ValidatePublisherParams, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} +export const getValidatePublisherQueryOptions = >, TError = ErrorResponse>(params: ValidatePublisherParams, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} ) => { const {query: queryOptions, request: requestOptions} = options ?? {}; @@ -1192,12 +1208,12 @@ const {query: queryOptions, request: requestOptions} = options ?? {}; } export type ValidatePublisherQueryResult = NonNullable>> -export type ValidatePublisherQueryError = Error | void +export type ValidatePublisherQueryError = ErrorResponse /** * @summary Validate if a publisher username is available */ -export const useValidatePublisher = >, TError = Error | void>( +export const useValidatePublisher = >, TError = ErrorResponse>( params: ValidatePublisherParams, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} ): UseQueryResult & { queryKey: QueryKey } => { @@ -1230,7 +1246,7 @@ export const deletePublisher = ( -export const getDeletePublisherMutationOptions = (options?: { mutation?:UseMutationOptions>, TError,{publisherId: string}, TContext>, request?: SecondParameter} ): UseMutationOptions>, TError,{publisherId: string}, TContext> => { const {mutation: mutationOptions, request: requestOptions} = options ?? {}; @@ -1251,12 +1267,12 @@ const {mutation: mutationOptions, request: requestOptions} = options ?? {}; export type DeletePublisherMutationResult = NonNullable>> - export type DeletePublisherMutationError = Error + export type DeletePublisherMutationError = ErrorResponse /** * @summary Delete a publisher */ -export const useDeletePublisher = (options?: { mutation?:UseMutationOptions>, TError,{publisherId: string}, TContext>, request?: SecondParameter} ): UseMutationResult< Awaited>, @@ -1291,7 +1307,7 @@ export const getGetPublisherQueryKey = (publisherId: string,) => { } -export const getGetPublisherQueryOptions = >, TError = void>(publisherId: string, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} +export const getGetPublisherQueryOptions = >, TError = ErrorResponse>(publisherId: string, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} ) => { const {query: queryOptions, request: requestOptions} = options ?? {}; @@ -1310,12 +1326,12 @@ const {query: queryOptions, request: requestOptions} = options ?? {}; } export type GetPublisherQueryResult = NonNullable>> -export type GetPublisherQueryError = void +export type GetPublisherQueryError = ErrorResponse /** * @summary Retrieve a publisher by ID */ -export const useGetPublisher = >, TError = void>( +export const useGetPublisher = >, TError = ErrorResponse>( publisherId: string, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} ): UseQueryResult & { queryKey: QueryKey } => { @@ -1351,7 +1367,7 @@ export const updatePublisher = ( -export const getUpdatePublisherMutationOptions = (options?: { mutation?:UseMutationOptions>, TError,{publisherId: string;data: Publisher}, TContext>, request?: SecondParameter} ): UseMutationOptions>, TError,{publisherId: string;data: Publisher}, TContext> => { const {mutation: mutationOptions, request: requestOptions} = options ?? {}; @@ -1372,12 +1388,12 @@ const {mutation: mutationOptions, request: requestOptions} = options ?? {}; export type UpdatePublisherMutationResult = NonNullable>> export type UpdatePublisherMutationBody = Publisher - export type UpdatePublisherMutationError = Error | void + export type UpdatePublisherMutationError = ErrorResponse | void /** * @summary Update a publisher */ -export const useUpdatePublisher = (options?: { mutation?:UseMutationOptions>, TError,{publisherId: string;data: Publisher}, TContext>, request?: SecondParameter} ): UseMutationResult< Awaited>, @@ -1412,7 +1428,7 @@ export const getListNodesForPublisherQueryKey = (publisherId: string,) => { } -export const getListNodesForPublisherQueryOptions = >, TError = void>(publisherId: string, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} +export const getListNodesForPublisherQueryOptions = >, TError = ErrorResponse>(publisherId: string, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} ) => { const {query: queryOptions, request: requestOptions} = options ?? {}; @@ -1431,12 +1447,12 @@ const {query: queryOptions, request: requestOptions} = options ?? {}; } export type ListNodesForPublisherQueryResult = NonNullable>> -export type ListNodesForPublisherQueryError = void +export type ListNodesForPublisherQueryError = ErrorResponse /** * @summary Retrieve all nodes */ -export const useListNodesForPublisher = >, TError = void>( +export const useListNodesForPublisher = >, TError = ErrorResponse>( publisherId: string, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} ): UseQueryResult & { queryKey: QueryKey } => { @@ -1472,7 +1488,7 @@ export const createNode = ( -export const getCreateNodeMutationOptions = (options?: { mutation?:UseMutationOptions>, TError,{publisherId: string;data: Node}, TContext>, request?: SecondParameter} ): UseMutationOptions>, TError,{publisherId: string;data: Node}, TContext> => { const {mutation: mutationOptions, request: requestOptions} = options ?? {}; @@ -1493,12 +1509,12 @@ const {mutation: mutationOptions, request: requestOptions} = options ?? {}; export type CreateNodeMutationResult = NonNullable>> export type CreateNodeMutationBody = Node - export type CreateNodeMutationError = Error + export type CreateNodeMutationError = ErrorResponse | void /** * @summary Create a new custom node */ -export const useCreateNode = (options?: { mutation?:UseMutationOptions>, TError,{publisherId: string;data: Node}, TContext>, request?: SecondParameter} ): UseMutationResult< Awaited>, @@ -1529,7 +1545,7 @@ export const deleteNode = ( -export const getDeleteNodeMutationOptions = (options?: { mutation?:UseMutationOptions>, TError,{publisherId: string;nodeId: string}, TContext>, request?: SecondParameter} ): UseMutationOptions>, TError,{publisherId: string;nodeId: string}, TContext> => { const {mutation: mutationOptions, request: requestOptions} = options ?? {}; @@ -1550,12 +1566,12 @@ const {mutation: mutationOptions, request: requestOptions} = options ?? {}; export type DeleteNodeMutationResult = NonNullable>> - export type DeleteNodeMutationError = Error + export type DeleteNodeMutationError = ErrorResponse /** * @summary Delete a specific node */ -export const useDeleteNode = (options?: { mutation?:UseMutationOptions>, TError,{publisherId: string;nodeId: string}, TContext>, request?: SecondParameter} ): UseMutationResult< Awaited>, @@ -1589,7 +1605,7 @@ export const updateNode = ( -export const getUpdateNodeMutationOptions = (options?: { mutation?:UseMutationOptions>, TError,{publisherId: string;nodeId: string;data: Node}, TContext>, request?: SecondParameter} ): UseMutationOptions>, TError,{publisherId: string;nodeId: string;data: Node}, TContext> => { const {mutation: mutationOptions, request: requestOptions} = options ?? {}; @@ -1610,12 +1626,12 @@ const {mutation: mutationOptions, request: requestOptions} = options ?? {}; export type UpdateNodeMutationResult = NonNullable>> export type UpdateNodeMutationBody = Node - export type UpdateNodeMutationError = Error | void + export type UpdateNodeMutationError = ErrorResponse | void /** * @summary Update a specific node */ -export const useUpdateNode = (options?: { mutation?:UseMutationOptions>, TError,{publisherId: string;nodeId: string;data: Node}, TContext>, request?: SecondParameter} ): UseMutationResult< Awaited>, @@ -1629,6 +1645,72 @@ export const useUpdateNode = ,signal?: AbortSignal +) => { + + + return customInstance( + {url: `/publishers/${publisherId}/nodes/${nodeId}/permissions`, method: 'GET', signal + }, + options); + } + + +export const getGetPermissionOnPublisherNodesQueryKey = (publisherId: string, + nodeId: string,) => { + return [`/publishers/${publisherId}/nodes/${nodeId}/permissions`] as const; + } + + +export const getGetPermissionOnPublisherNodesQueryOptions = >, TError = ErrorResponse>(publisherId: string, + nodeId: string, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} +) => { + +const {query: queryOptions, request: requestOptions} = options ?? {}; + + const queryKey = queryOptions?.queryKey ?? getGetPermissionOnPublisherNodesQueryKey(publisherId,nodeId); + + + + const queryFn: QueryFunction>> = ({ signal }) => getPermissionOnPublisherNodes(publisherId,nodeId, requestOptions, signal); + + + + + + return { queryKey, queryFn, enabled: !!(publisherId && nodeId), ...queryOptions} as UseQueryOptions>, TError, TData> & { queryKey: QueryKey } +} + +export type GetPermissionOnPublisherNodesQueryResult = NonNullable>> +export type GetPermissionOnPublisherNodesQueryError = ErrorResponse + +/** + * @summary Retrieve permissions the user has for a given publisher + */ +export const useGetPermissionOnPublisherNodes = >, TError = ErrorResponse>( + publisherId: string, + nodeId: string, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} + + ): UseQueryResult & { queryKey: QueryKey } => { + + const queryOptions = getGetPermissionOnPublisherNodesQueryOptions(publisherId,nodeId,options) + + const query = useQuery(queryOptions) as UseQueryResult & { queryKey: QueryKey }; + + query.queryKey = queryOptions.queryKey ; + + return query; +} + + + + /** * @summary Publish a new version of a node */ @@ -1649,7 +1731,7 @@ export const publishNodeVersion = ( -export const getPublishNodeVersionMutationOptions = (options?: { mutation?:UseMutationOptions>, TError,{publisherId: string;nodeId: string;data: PublishNodeVersionBody}, TContext>, request?: SecondParameter} ): UseMutationOptions>, TError,{publisherId: string;nodeId: string;data: PublishNodeVersionBody}, TContext> => { const {mutation: mutationOptions, request: requestOptions} = options ?? {}; @@ -1670,12 +1752,12 @@ const {mutation: mutationOptions, request: requestOptions} = options ?? {}; export type PublishNodeVersionMutationResult = NonNullable>> export type PublishNodeVersionMutationBody = PublishNodeVersionBody - export type PublishNodeVersionMutationError = Error + export type PublishNodeVersionMutationError = ErrorResponse /** * @summary Publish a new version of a node */ -export const usePublishNodeVersion = (options?: { mutation?:UseMutationOptions>, TError,{publisherId: string;nodeId: string;data: PublishNodeVersionBody}, TContext>, request?: SecondParameter} ): UseMutationResult< Awaited>, @@ -1769,7 +1851,7 @@ export const updateNodeVersion = ( -export const getUpdateNodeVersionMutationOptions = (options?: { mutation?:UseMutationOptions>, TError,{publisherId: string;nodeId: string;versionId: string;data: NodeVersionUpdateRequest}, TContext>, request?: SecondParameter} ): UseMutationOptions>, TError,{publisherId: string;nodeId: string;versionId: string;data: NodeVersionUpdateRequest}, TContext> => { const {mutation: mutationOptions, request: requestOptions} = options ?? {}; @@ -1790,12 +1872,12 @@ const {mutation: mutationOptions, request: requestOptions} = options ?? {}; export type UpdateNodeVersionMutationResult = NonNullable>> export type UpdateNodeVersionMutationBody = NodeVersionUpdateRequest - export type UpdateNodeVersionMutationError = Error | void + export type UpdateNodeVersionMutationError = ErrorResponse | void /** * @summary Update changelog and deprecation status of a node version */ -export const useUpdateNodeVersion = (options?: { mutation?:UseMutationOptions>, TError,{publisherId: string;nodeId: string;versionId: string;data: NodeVersionUpdateRequest}, TContext>, request?: SecondParameter} ): UseMutationResult< Awaited>, @@ -1809,6 +1891,68 @@ export const useUpdateNodeVersion = ,signal?: AbortSignal +) => { + + + return customInstance( + {url: `/publishers/${publisherId}/permissions`, method: 'GET', signal + }, + options); + } + + +export const getGetPermissionOnPublisherQueryKey = (publisherId: string,) => { + return [`/publishers/${publisherId}/permissions`] as const; + } + + +export const getGetPermissionOnPublisherQueryOptions = >, TError = ErrorResponse>(publisherId: string, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} +) => { + +const {query: queryOptions, request: requestOptions} = options ?? {}; + + const queryKey = queryOptions?.queryKey ?? getGetPermissionOnPublisherQueryKey(publisherId); + + + + const queryFn: QueryFunction>> = ({ signal }) => getPermissionOnPublisher(publisherId, requestOptions, signal); + + + + + + return { queryKey, queryFn, enabled: !!(publisherId), ...queryOptions} as UseQueryOptions>, TError, TData> & { queryKey: QueryKey } +} + +export type GetPermissionOnPublisherQueryResult = NonNullable>> +export type GetPermissionOnPublisherQueryError = ErrorResponse + +/** + * @summary Retrieve permissions the user has for a given publisher + */ +export const useGetPermissionOnPublisher = >, TError = ErrorResponse>( + publisherId: string, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} + + ): UseQueryResult & { queryKey: QueryKey } => { + + const queryOptions = getGetPermissionOnPublisherQueryOptions(publisherId,options) + + const query = useQuery(queryOptions) as UseQueryResult & { queryKey: QueryKey }; + + query.queryKey = queryOptions.queryKey ; + + return query; +} + + + + /** * @summary Retrieve all personal access tokens for a publisher */ @@ -1830,7 +1974,7 @@ export const getListPersonalAccessTokensQueryKey = (publisherId: string,) => { } -export const getListPersonalAccessTokensQueryOptions = >, TError = Error>(publisherId: string, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} +export const getListPersonalAccessTokensQueryOptions = >, TError = ErrorResponse>(publisherId: string, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} ) => { const {query: queryOptions, request: requestOptions} = options ?? {}; @@ -1849,12 +1993,12 @@ const {query: queryOptions, request: requestOptions} = options ?? {}; } export type ListPersonalAccessTokensQueryResult = NonNullable>> -export type ListPersonalAccessTokensQueryError = Error +export type ListPersonalAccessTokensQueryError = ErrorResponse /** * @summary Retrieve all personal access tokens for a publisher */ -export const useListPersonalAccessTokens = >, TError = Error>( +export const useListPersonalAccessTokens = >, TError = ErrorResponse>( publisherId: string, options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} ): UseQueryResult & { queryKey: QueryKey } => { @@ -1890,7 +2034,7 @@ export const createPersonalAccessToken = ( -export const getCreatePersonalAccessTokenMutationOptions = (options?: { mutation?:UseMutationOptions>, TError,{publisherId: string;data: PersonalAccessToken}, TContext>, request?: SecondParameter} ): UseMutationOptions>, TError,{publisherId: string;data: PersonalAccessToken}, TContext> => { const {mutation: mutationOptions, request: requestOptions} = options ?? {}; @@ -1911,12 +2055,12 @@ const {mutation: mutationOptions, request: requestOptions} = options ?? {}; export type CreatePersonalAccessTokenMutationResult = NonNullable>> export type CreatePersonalAccessTokenMutationBody = PersonalAccessToken - export type CreatePersonalAccessTokenMutationError = Error + export type CreatePersonalAccessTokenMutationError = ErrorResponse /** * @summary Create a new personal access token */ -export const useCreatePersonalAccessToken = (options?: { mutation?:UseMutationOptions>, TError,{publisherId: string;data: PersonalAccessToken}, TContext>, request?: SecondParameter} ): UseMutationResult< Awaited>, @@ -1947,7 +2091,7 @@ export const deletePersonalAccessToken = ( -export const getDeletePersonalAccessTokenMutationOptions = (options?: { mutation?:UseMutationOptions>, TError,{publisherId: string;tokenId: string}, TContext>, request?: SecondParameter} ): UseMutationOptions>, TError,{publisherId: string;tokenId: string}, TContext> => { const {mutation: mutationOptions, request: requestOptions} = options ?? {}; @@ -1968,12 +2112,12 @@ const {mutation: mutationOptions, request: requestOptions} = options ?? {}; export type DeletePersonalAccessTokenMutationResult = NonNullable>> - export type DeletePersonalAccessTokenMutationError = Error + export type DeletePersonalAccessTokenMutationError = ErrorResponse /** * @summary Delete a specific personal access token */ -export const useDeletePersonalAccessToken = (options?: { mutation?:UseMutationOptions>, TError,{publisherId: string;tokenId: string}, TContext>, request?: SecondParameter} ): UseMutationResult< Awaited>, @@ -2128,7 +2272,7 @@ export const getListPublishersForUserQueryKey = () => { } -export const getListPublishersForUserQueryOptions = >, TError = void>( options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} +export const getListPublishersForUserQueryOptions = >, TError = ErrorResponse>( options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} ) => { const {query: queryOptions, request: requestOptions} = options ?? {}; @@ -2147,12 +2291,12 @@ const {query: queryOptions, request: requestOptions} = options ?? {}; } export type ListPublishersForUserQueryResult = NonNullable>> -export type ListPublishersForUserQueryError = void +export type ListPublishersForUserQueryError = ErrorResponse /** * @summary Retrieve all publishers for a given user */ -export const useListPublishersForUser = >, TError = void>( +export const useListPublishersForUser = >, TError = ErrorResponse>( options?: { query?:Partial>, TError, TData>>, request?: SecondParameter} ): UseQueryResult & { queryKey: QueryKey } => { From 45a46ad4cffe50e532062e89f9d01c63f794567d Mon Sep 17 00:00:00 2001 From: Robin Huang Date: Tue, 21 May 2024 12:09:53 -0700 Subject: [PATCH 2/2] Add can edit for Node versions as well. --- components/nodes/NodeDetails.tsx | 1 + components/nodes/NodeVDrawer.tsx | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/components/nodes/NodeDetails.tsx b/components/nodes/NodeDetails.tsx index 1aa85a7..b079d26 100644 --- a/components/nodes/NodeDetails.tsx +++ b/components/nodes/NodeDetails.tsx @@ -304,6 +304,7 @@ const NodeDetails = () => { isDrawerOpen={isDrawerOpen} nodeId={nodeId as string} publisherId={publisherId as string} + canEdit={permissions?.canEdit} /> )} diff --git a/components/nodes/NodeVDrawer.tsx b/components/nodes/NodeVDrawer.tsx index e4ea51b..6be19c5 100644 --- a/components/nodes/NodeVDrawer.tsx +++ b/components/nodes/NodeVDrawer.tsx @@ -2,11 +2,13 @@ import React, { useState } from 'react' import { NodeVersion, useUpdateNodeVersion } from 'src/api/generated' import { formatRelativeDate } from './NodeDetails' import { toast } from 'react-toastify' +import { Button } from 'flowbite-react' type NodeVDrawerProps = { version: NodeVersion isDrawerOpen: boolean toggleDrawer: () => void publisherId?: string // Means don't deprecate version. + canEdit?: boolean nodeId: string } @@ -16,6 +18,7 @@ const NodeVDrawer: React.FC = ({ version, isDrawerOpen, toggleDrawer, + canEdit = false, }) => { const [isVersionAvailable, setIsVersionAvailable] = useState(true) const updateNodeVersionMutation = useUpdateNodeVersion() @@ -103,6 +106,13 @@ const NodeVDrawer: React.FC = ({ Released {formatRelativeDate(version.createdAt)}

)} + {version.downloadUrl && ( + + )}
@@ -116,7 +126,7 @@ const NodeVDrawer: React.FC = ({
- {publisherId && ( + {canEdit && (