From 454eae24f545a45d628969801517a1784d932453 Mon Sep 17 00:00:00 2001 From: Hussain Khalil Date: Mon, 23 Sep 2024 16:47:40 -0400 Subject: [PATCH 1/5] Hide SMTP warning for Linodes and accounts that have SMTP enabled --- packages/api-v4/src/account/types.ts | 1 + packages/api-v4/src/linodes/types.ts | 2 +- .../LinodesDetail/LinodesDetailNavigation.tsx | 5 ++++- .../features/Linodes/SMTPRestrictionText.tsx | 19 ++++++++++++------- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/packages/api-v4/src/account/types.ts b/packages/api-v4/src/account/types.ts index 6cec39f8f4d..84882d03429 100644 --- a/packages/api-v4/src/account/types.ts +++ b/packages/api-v4/src/account/types.ts @@ -78,6 +78,7 @@ export type AccountCapability = | 'Object Storage Endpoint Types' | 'Object Storage' | 'Placement Group' + | 'SMTP Enabled' | 'Support Ticket Severity' | 'Vlans' | 'VPCs'; diff --git a/packages/api-v4/src/linodes/types.ts b/packages/api-v4/src/linodes/types.ts index aa74b71ac70..5a194836115 100644 --- a/packages/api-v4/src/linodes/types.ts +++ b/packages/api-v4/src/linodes/types.ts @@ -54,7 +54,7 @@ export interface LinodeBackups { last_successful: string | null; } -export type LinodeCapabilities = 'Block Storage Encryption'; +export type LinodeCapabilities = 'Block Storage Encryption' | 'SMTP Enabled'; export type Window = | 'Scheduling' diff --git a/packages/manager/src/features/Linodes/LinodesDetail/LinodesDetailNavigation.tsx b/packages/manager/src/features/Linodes/LinodesDetail/LinodesDetailNavigation.tsx index 0fff44b46ce..dccfa5c7e00 100644 --- a/packages/manager/src/features/Linodes/LinodesDetail/LinodesDetailNavigation.tsx +++ b/packages/manager/src/features/Linodes/LinodesDetail/LinodesDetailNavigation.tsx @@ -117,7 +117,10 @@ const LinodesDetailNavigation = () => { tabs[getIndex()]?.title ?? 'Detail View' }`} /> - + {({ text }) => text !== null ? ( React.ReactNode; + linode?: Linode; supportLink?: { id: number; label: string; @@ -16,14 +19,17 @@ export interface SMTPRestrictionTextProps { } export const SMTPRestrictionText = (props: SMTPRestrictionTextProps) => { - const { supportLink } = props; + const { linode, supportLink } = props; const { data: account } = useAccount(); + const displayRestrictionText = + accountCreatedAfterRestrictions(account?.active_since) && + !account?.capabilities.includes('SMTP Enabled') && + (linode === undefined || !linode.capabilities?.includes('SMTP Enabled')); + // If there account was created before restrictions were put into place, // there's no need to display anything. - const text = !accountCreatedAfterRestrictions( - account?.active_since - ) ? null : ( + const text = displayRestrictionText ? ( SMTP ports may be restricted on this Linode. Need to send email? Review our{' '} @@ -46,10 +52,9 @@ export const SMTPRestrictionText = (props: SMTPRestrictionTextProps) => { )} . - ); + ) : null; - // eslint-disable-next-line - return <>{props.children({ text })}; + return props.children({ text }); }; export const accountCreatedAfterRestrictions = (_accountCreated?: string) => { From aaf7e3ed20d352d09009e06e0cde3e241b1912fb Mon Sep 17 00:00:00 2001 From: Hussain Khalil Date: Mon, 23 Sep 2024 17:03:03 -0400 Subject: [PATCH 2/5] Update unit tests --- .../Linodes/SMTPRestrictionText.test.tsx | 60 ++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/packages/manager/src/features/Linodes/SMTPRestrictionText.test.tsx b/packages/manager/src/features/Linodes/SMTPRestrictionText.test.tsx index 68da9b39fcb..3c79d9ee71e 100644 --- a/packages/manager/src/features/Linodes/SMTPRestrictionText.test.tsx +++ b/packages/manager/src/features/Linodes/SMTPRestrictionText.test.tsx @@ -2,16 +2,18 @@ import { waitFor } from '@testing-library/react'; import * as React from 'react'; import { MAGIC_DATE_THAT_EMAIL_RESTRICTIONS_WERE_IMPLEMENTED } from 'src/constants'; +import { linodeFactory } from 'src/factories'; import { accountFactory } from 'src/factories/account'; import { HttpResponse, http, server } from 'src/mocks/testServer'; import { renderWithTheme } from 'src/utilities/testHelpers'; import { SMTPRestrictionText, - SMTPRestrictionTextProps, accountCreatedAfterRestrictions, } from './SMTPRestrictionText'; +import type { SMTPRestrictionTextProps } from './SMTPRestrictionText'; + const defaultChildren = (props: { text: React.ReactNode }) => ( {props.text} ); @@ -89,6 +91,62 @@ describe('SMTPRestrictionText component', () => { ); }); + it('should not render for an account with the "SMTP Enabled" capability', async () => { + const account = accountFactory.build({ + active_since: MAGIC_DATE_THAT_EMAIL_RESTRICTIONS_WERE_IMPLEMENTED, + capabilities: ['SMTP Enabled'], + }); + + server.use( + http.get('*/account', () => { + return HttpResponse.json(account); + }) + ); + + const { queryByText } = renderWithTheme( + + ); + + await waitFor(() => + expect( + queryByText('SMTP ports may be restricted on this Linode.', { + exact: false, + }) + ).toBeNull() + ); + }); + + it('should not render for a Linode with the "SMTP Enabled" capability', async () => { + const account = accountFactory.build({ + active_since: MAGIC_DATE_THAT_EMAIL_RESTRICTIONS_WERE_IMPLEMENTED, + }); + + server.use( + http.get('*/account', () => { + return HttpResponse.json(account); + }) + ); + + const { queryByText } = renderWithTheme( + + ); + + await waitFor(() => + expect( + queryByText('SMTP ports may be restricted on this Linode.', { + exact: false, + }) + ).toBeNull() + ); + }); + it('should default to not including a link to open a support ticket', () => { const account = accountFactory.build({ active_since: MAGIC_DATE_THAT_EMAIL_RESTRICTIONS_WERE_IMPLEMENTED, From a88b4aae0fc57cc7a2cc2383b080eda3d159835f Mon Sep 17 00:00:00 2001 From: Hussain Khalil Date: Mon, 23 Sep 2024 17:05:05 -0400 Subject: [PATCH 3/5] Added changeset: Hide SMTP warning for Linodes and accounts that have SMTP enabled --- .../manager/.changeset/pr-10991-changed-1727125505081.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 packages/manager/.changeset/pr-10991-changed-1727125505081.md diff --git a/packages/manager/.changeset/pr-10991-changed-1727125505081.md b/packages/manager/.changeset/pr-10991-changed-1727125505081.md new file mode 100644 index 00000000000..acce1f1ed60 --- /dev/null +++ b/packages/manager/.changeset/pr-10991-changed-1727125505081.md @@ -0,0 +1,5 @@ +--- +"@linode/manager": Changed +--- + +Hide SMTP warning for Linodes and accounts that have SMTP enabled ([#10991](https://github.com/linode/manager/pull/10991)) From b09b99e66602799049ebe5c9bb7a4a974e2721c5 Mon Sep 17 00:00:00 2001 From: Hussain Khalil Date: Mon, 23 Sep 2024 17:05:36 -0400 Subject: [PATCH 4/5] Added changeset: 'SMTP Enabled' account & Linode capabilities --- packages/api-v4/.changeset/pr-10991-added-1727125536609.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 packages/api-v4/.changeset/pr-10991-added-1727125536609.md diff --git a/packages/api-v4/.changeset/pr-10991-added-1727125536609.md b/packages/api-v4/.changeset/pr-10991-added-1727125536609.md new file mode 100644 index 00000000000..85aa3e7a23f --- /dev/null +++ b/packages/api-v4/.changeset/pr-10991-added-1727125536609.md @@ -0,0 +1,5 @@ +--- +"@linode/api-v4": Added +--- + +'SMTP Enabled' account & Linode capabilities ([#10991](https://github.com/linode/manager/pull/10991)) From 09c78cbd654d4a6c58b0c0eba46d51feb11be6bd Mon Sep 17 00:00:00 2001 From: Hussain Khalil Date: Mon, 7 Oct 2024 13:53:08 -0400 Subject: [PATCH 5/5] Remove magic date --- .../open-support-ticket.spec.ts | 2 - packages/manager/src/constants.ts | 5 -- .../Linodes/SMTPRestrictionText.test.tsx | 87 +------------------ .../features/Linodes/SMTPRestrictionText.tsx | 25 +----- 4 files changed, 7 insertions(+), 112 deletions(-) diff --git a/packages/manager/cypress/e2e/core/helpAndSupport/open-support-ticket.spec.ts b/packages/manager/cypress/e2e/core/helpAndSupport/open-support-ticket.spec.ts index 5644f5deea4..ec286a59281 100644 --- a/packages/manager/cypress/e2e/core/helpAndSupport/open-support-ticket.spec.ts +++ b/packages/manager/cypress/e2e/core/helpAndSupport/open-support-ticket.spec.ts @@ -42,7 +42,6 @@ import { import { createTestLinode } from 'support/util/linodes'; import { cleanUp } from 'support/util/cleanup'; import { authenticate } from 'support/api/authentication'; -import { MAGIC_DATE_THAT_EMAIL_RESTRICTIONS_WERE_IMPLEMENTED } from 'src/constants'; import { mockCreateLinodeAccountLimitError, mockGetLinodes, @@ -227,7 +226,6 @@ describe('open support tickets', () => { first_name: 'Jane', last_name: 'Doe', company: 'Acme Co.', - active_since: MAGIC_DATE_THAT_EMAIL_RESTRICTIONS_WERE_IMPLEMENTED, }); const mockFormFields = { diff --git a/packages/manager/src/constants.ts b/packages/manager/src/constants.ts index 99c1ee53599..b400343c46f 100644 --- a/packages/manager/src/constants.ts +++ b/packages/manager/src/constants.ts @@ -233,11 +233,6 @@ export const PAYMENT_HARD_MAX = 50_000; export const DB_ROOT_USERNAME = 'linroot'; -// "In an effort to fight spam, Linode restricts outbound connections on ports 25, 465, and 587 on all Linodes for new accounts created after November 5th, 2019." -// https://www.linode.com/docs/email/best-practices/running-a-mail-server/ -export const MAGIC_DATE_THAT_EMAIL_RESTRICTIONS_WERE_IMPLEMENTED = - '2022-11-30T00:00:00.000Z'; // Date of release for Manager v1.81.0. - // The date Linode switching to Akamai (for purposes of billing) export const AKAMAI_DATE = '2022-12-15 00:00:00'; diff --git a/packages/manager/src/features/Linodes/SMTPRestrictionText.test.tsx b/packages/manager/src/features/Linodes/SMTPRestrictionText.test.tsx index 3c79d9ee71e..7884196c7ce 100644 --- a/packages/manager/src/features/Linodes/SMTPRestrictionText.test.tsx +++ b/packages/manager/src/features/Linodes/SMTPRestrictionText.test.tsx @@ -1,16 +1,12 @@ import { waitFor } from '@testing-library/react'; import * as React from 'react'; -import { MAGIC_DATE_THAT_EMAIL_RESTRICTIONS_WERE_IMPLEMENTED } from 'src/constants'; import { linodeFactory } from 'src/factories'; import { accountFactory } from 'src/factories/account'; import { HttpResponse, http, server } from 'src/mocks/testServer'; import { renderWithTheme } from 'src/utilities/testHelpers'; -import { - SMTPRestrictionText, - accountCreatedAfterRestrictions, -} from './SMTPRestrictionText'; +import { SMTPRestrictionText } from './SMTPRestrictionText'; import type { SMTPRestrictionTextProps } from './SMTPRestrictionText'; @@ -22,78 +18,9 @@ const props: SMTPRestrictionTextProps = { children: defaultChildren, }; -describe('accountCreatedAfterRestrictions', () => { - it('defaults to true with bad/no input', () => { - expect(accountCreatedAfterRestrictions()).toBe(true); - expect(accountCreatedAfterRestrictions('not a date!')).toBe(true); - }); - - it('only returns true when the account was created after the magic date', () => { - expect(accountCreatedAfterRestrictions('2022-11-27 00:00:00Z')).toBe(false); - expect(accountCreatedAfterRestrictions('2022-11-29 23:59:59Z')).toBe(false); - expect( - accountCreatedAfterRestrictions( - MAGIC_DATE_THAT_EMAIL_RESTRICTIONS_WERE_IMPLEMENTED - ) - ).toBe(true); - expect(accountCreatedAfterRestrictions('2022-11-30 00:00:01Z')).toBe(true); - }); -}); - describe('SMTPRestrictionText component', () => { - it('should render when user account is created on or after the magic date', async () => { - const account = accountFactory.build({ - active_since: MAGIC_DATE_THAT_EMAIL_RESTRICTIONS_WERE_IMPLEMENTED, - }); - - server.use( - http.get('*/account', () => { - return HttpResponse.json(account); - }) - ); - - const { findByText } = renderWithTheme( - - ); - - await findByText('SMTP ports may be restricted on this Linode.', { - exact: false, - }); - }); - - it('should not render when user account is created before the magic date', async () => { - const account = accountFactory.build({ - active_since: '2022-11-27 00:00:00Z', - }); - - server.use( - http.get('*/account', () => { - return HttpResponse.json(account); - }) - ); - - const { queryByText } = renderWithTheme( - - ); - - await waitFor(() => - expect( - queryByText('SMTP ports may be restricted on this Linode.', { - exact: false, - }) - ).toBeNull() - ); - }); - it('should not render for an account with the "SMTP Enabled" capability', async () => { const account = accountFactory.build({ - active_since: MAGIC_DATE_THAT_EMAIL_RESTRICTIONS_WERE_IMPLEMENTED, capabilities: ['SMTP Enabled'], }); @@ -120,9 +47,7 @@ describe('SMTPRestrictionText component', () => { }); it('should not render for a Linode with the "SMTP Enabled" capability', async () => { - const account = accountFactory.build({ - active_since: MAGIC_DATE_THAT_EMAIL_RESTRICTIONS_WERE_IMPLEMENTED, - }); + const account = accountFactory.build(); server.use( http.get('*/account', () => { @@ -148,9 +73,7 @@ describe('SMTPRestrictionText component', () => { }); it('should default to not including a link to open a support ticket', () => { - const account = accountFactory.build({ - active_since: MAGIC_DATE_THAT_EMAIL_RESTRICTIONS_WERE_IMPLEMENTED, - }); + const account = accountFactory.build(); server.use( http.get('*/account', () => { @@ -166,9 +89,7 @@ describe('SMTPRestrictionText component', () => { }); it('should include a link to open a support ticket when the prop is provided', () => { - const account = accountFactory.build({ - active_since: MAGIC_DATE_THAT_EMAIL_RESTRICTIONS_WERE_IMPLEMENTED, - }); + const account = accountFactory.build(); server.use( http.get('*/account', () => { diff --git a/packages/manager/src/features/Linodes/SMTPRestrictionText.tsx b/packages/manager/src/features/Linodes/SMTPRestrictionText.tsx index 7017fee077a..23ff57d2be9 100644 --- a/packages/manager/src/features/Linodes/SMTPRestrictionText.tsx +++ b/packages/manager/src/features/Linodes/SMTPRestrictionText.tsx @@ -3,7 +3,6 @@ import * as React from 'react'; import { Link } from 'src/components/Link'; import { SupportLink } from 'src/components/SupportLink'; import { Typography } from 'src/components/Typography'; -import { MAGIC_DATE_THAT_EMAIL_RESTRICTIONS_WERE_IMPLEMENTED } from 'src/constants'; import { useAccount } from 'src/queries/account/account'; import { sendLinodeCreateDocsEvent } from 'src/utilities/analytics/customEventAnalytics'; @@ -23,9 +22,9 @@ export const SMTPRestrictionText = (props: SMTPRestrictionTextProps) => { const { data: account } = useAccount(); const displayRestrictionText = - accountCreatedAfterRestrictions(account?.active_since) && - !account?.capabilities.includes('SMTP Enabled') && - (linode === undefined || !linode.capabilities?.includes('SMTP Enabled')); + linode === undefined + ? !account?.capabilities.includes('SMTP Enabled') + : !linode.capabilities?.includes('SMTP Enabled'); // If there account was created before restrictions were put into place, // there's no need to display anything. @@ -56,21 +55,3 @@ export const SMTPRestrictionText = (props: SMTPRestrictionTextProps) => { return props.children({ text }); }; - -export const accountCreatedAfterRestrictions = (_accountCreated?: string) => { - // Default to `true` for bad input. - if (!_accountCreated) { - return true; - } - - const restrictionsImplemented = new Date( - MAGIC_DATE_THAT_EMAIL_RESTRICTIONS_WERE_IMPLEMENTED - ).getTime(); - const accountCreated = new Date(_accountCreated).getTime(); - - if (isNaN(accountCreated)) { - return true; - } - - return accountCreated >= restrictionsImplemented; -};