From 173a130785eeed659fe24274b8922fab59ab48f4 Mon Sep 17 00:00:00 2001 From: Banks Nussman Date: Wed, 28 Aug 2024 11:11:53 -0400 Subject: [PATCH 1/2] initial fix --- .../src/features/Linodes/LinodeCreatev2/index.tsx | 14 +++++++++----- .../features/Linodes/LinodeCreatev2/resolvers.ts | 9 ++++++--- .../features/Linodes/LinodeCreatev2/utilities.ts | 13 +++++++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/packages/manager/src/features/Linodes/LinodeCreatev2/index.tsx b/packages/manager/src/features/Linodes/LinodeCreatev2/index.tsx index 0a7e7524887..e3dde917e42 100644 --- a/packages/manager/src/features/Linodes/LinodeCreatev2/index.tsx +++ b/packages/manager/src/features/Linodes/LinodeCreatev2/index.tsx @@ -20,6 +20,7 @@ import { useCloneLinodeMutation, useCreateLinodeMutation, } from 'src/queries/linodes/linodes'; +import { useProfile } from 'src/queries/profile/profile'; import { sendLinodeCreateFormInputEvent, sendLinodeCreateFormSubmitEvent, @@ -58,18 +59,21 @@ import { import { VLAN } from './VLAN'; import { VPC } from './VPC/VPC'; -import type { LinodeCreateFormValues } from './utilities'; +import type { + LinodeCreateFormContext, + LinodeCreateFormValues, +} from './utilities'; import type { SubmitHandler } from 'react-hook-form'; export const LinodeCreatev2 = () => { const { params, setParams } = useLinodeCreateQueryParams(); + const { secureVMNoticesEnabled } = useSecureVMNoticesEnabled(); + const { data: profile } = useProfile(); const queryClient = useQueryClient(); - const { secureVMNoticesEnabled } = useSecureVMNoticesEnabled(); - - const form = useForm({ - context: { secureVMNoticesEnabled }, + const form = useForm({ + context: { profile, secureVMNoticesEnabled }, defaultValues: () => defaultValues(params, queryClient), mode: 'onBlur', resolver: getLinodeCreateResolver(params.type, queryClient), diff --git a/packages/manager/src/features/Linodes/LinodeCreatev2/resolvers.ts b/packages/manager/src/features/Linodes/LinodeCreatev2/resolvers.ts index e95f38d40f4..5981245a8d7 100644 --- a/packages/manager/src/features/Linodes/LinodeCreatev2/resolvers.ts +++ b/packages/manager/src/features/Linodes/LinodeCreatev2/resolvers.ts @@ -13,14 +13,17 @@ import { import { getLinodeCreatePayload } from './utilities'; import type { LinodeCreateType } from '../LinodesCreate/types'; -import type { LinodeCreateFormValues } from './utilities'; +import type { + LinodeCreateFormContext, + LinodeCreateFormValues, +} from './utilities'; import type { QueryClient } from '@tanstack/react-query'; import type { FieldErrors, Resolver } from 'react-hook-form'; export const getLinodeCreateResolver = ( tab: LinodeCreateType | undefined, queryClient: QueryClient -): Resolver => { +): Resolver => { const schema = linodeCreateResolvers[tab ?? 'OS']; return async (values, context, options) => { const transformedValues = getLinodeCreatePayload(structuredClone(values)); @@ -46,7 +49,7 @@ export const getLinodeCreateResolver = ( getRegionCountryGroup(selectedRegion) ); - if (hasSelectedAnEURegion) { + if (hasSelectedAnEURegion && !context?.profile?.restricted) { const agreements = await queryClient.ensureQueryData( accountQueries.agreements ); diff --git a/packages/manager/src/features/Linodes/LinodeCreatev2/utilities.ts b/packages/manager/src/features/Linodes/LinodeCreatev2/utilities.ts index b0c92b33886..a5b136b5044 100644 --- a/packages/manager/src/features/Linodes/LinodeCreatev2/utilities.ts +++ b/packages/manager/src/features/Linodes/LinodeCreatev2/utilities.ts @@ -20,6 +20,7 @@ import type { CreateLinodeRequest, InterfacePayload, Linode, + Profile, } from '@linode/api-v4'; import type { QueryClient } from '@tanstack/react-query'; import type { FieldErrors } from 'react-hook-form'; @@ -260,6 +261,18 @@ export interface LinodeCreateFormValues extends CreateLinodeRequest { linode?: Linode | null; } +export interface LinodeCreateFormContext { + /** + * Profile data is used in the Linode Create v2 resolver because + * restricted users are subject to different validation. + */ + profile: Profile | undefined; + /** + * Used for dispaying warnings to internal Akamai employees. + */ + secureVMNoticesEnabled: boolean; +} + /** * This function initializes the Linode Create flow form * when the form mounts. From bfce5ad8e80f596904abdd3a93ea818c4c9472b7 Mon Sep 17 00:00:00 2001 From: Banks Nussman Date: Wed, 28 Aug 2024 11:39:28 -0400 Subject: [PATCH 2/2] Added changeset: Restricted users without account access unable to create Linodes on Linode Create v2 --- packages/manager/.changeset/pr-10846-fixed-1724859567426.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 packages/manager/.changeset/pr-10846-fixed-1724859567426.md diff --git a/packages/manager/.changeset/pr-10846-fixed-1724859567426.md b/packages/manager/.changeset/pr-10846-fixed-1724859567426.md new file mode 100644 index 00000000000..1c37ba54784 --- /dev/null +++ b/packages/manager/.changeset/pr-10846-fixed-1724859567426.md @@ -0,0 +1,5 @@ +--- +"@linode/manager": Fixed +--- + +Restricted users without account access unable to create Linodes on Linode Create v2 ([#10846](https://github.com/linode/manager/pull/10846))