Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [M3-8500] - Restricted users without account access unable to create Linodes on Linode Create v2 #10846

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-10846-fixed-1724859567426.md
Original file line number Diff line number Diff line change
@@ -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))
14 changes: 9 additions & 5 deletions packages/manager/src/features/Linodes/LinodeCreatev2/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
useCloneLinodeMutation,
useCreateLinodeMutation,
} from 'src/queries/linodes/linodes';
import { useProfile } from 'src/queries/profile/profile';
import {
sendLinodeCreateFormInputEvent,
sendLinodeCreateFormSubmitEvent,
Expand Down Expand Up @@ -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<LinodeCreateFormValues>({
context: { secureVMNoticesEnabled },
const form = useForm<LinodeCreateFormValues, LinodeCreateFormContext>({
context: { profile, secureVMNoticesEnabled },
defaultValues: () => defaultValues(params, queryClient),
mode: 'onBlur',
resolver: getLinodeCreateResolver(params.type, queryClient),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<LinodeCreateFormValues, { secureVMNoticesEnabled: boolean }> => {
): Resolver<LinodeCreateFormValues, LinodeCreateFormContext> => {
const schema = linodeCreateResolvers[tab ?? 'OS'];
return async (values, context, options) => {
const transformedValues = getLinodeCreatePayload(structuredClone(values));
Expand All @@ -46,7 +49,7 @@ export const getLinodeCreateResolver = (
getRegionCountryGroup(selectedRegion)
);

if (hasSelectedAnEURegion) {
if (hasSelectedAnEURegion && !context?.profile?.restricted) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fix πŸ”¨

We only check account agreements if the user is not restricted

const agreements = await queryClient.ensureQueryData(
accountQueries.agreements
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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.
Expand Down
Loading