Skip to content

Commit e893249

Browse files
upcoming: [UIE-9640] – Update useIsFirewallRulesetsPrefixlistsEnabled to include account capability check (#13156)
1 parent 80f3ba8 commit e893249

File tree

5 files changed

+109
-11
lines changed

5 files changed

+109
-11
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/api-v4": Upcoming Features
3+
---
4+
5+
Add 'Cloud Firewall Rule Set' to AccountCapability type ([#13156](https://github.com/linode/manager/pull/13156))

packages/api-v4/src/account/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export const accountCapabilities = [
6666
'Block Storage',
6767
'Block Storage Encryption',
6868
'Cloud Firewall',
69+
'Cloud Firewall Rule Set',
6970
'CloudPulse',
7071
'Disk Encryption',
7172
'Kubernetes',
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/manager": Upcoming Features
3+
---
4+
5+
Update useIsFirewallRulesetsPrefixlistsEnabled() to factor in account capability ([#13156](https://github.com/linode/manager/pull/13156))

packages/manager/src/features/Firewalls/shared.test.tsx

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { renderHook, waitFor } from '@testing-library/react';
33
import userEvent from '@testing-library/user-event';
44
import React from 'react';
55

6+
import { accountFactory } from 'src/factories';
7+
import { http, HttpResponse, server } from 'src/mocks/testServer';
68
import { renderWithTheme, wrapWithTheme } from 'src/utilities/testHelpers';
79

810
import {
@@ -391,7 +393,7 @@ describe('generateAddressesLabelV2', () => {
391393
});
392394

393395
describe('useIsFirewallRulesetsPrefixlistsEnabled', () => {
394-
it('returns true if the feature is enabled', async () => {
396+
it('returns true if the feature is enabled AND the account has the capability', async () => {
395397
const options = {
396398
flags: {
397399
fwRulesetsPrefixLists: {
@@ -403,6 +405,16 @@ describe('useIsFirewallRulesetsPrefixlistsEnabled', () => {
403405
},
404406
};
405407

408+
const account = accountFactory.build({
409+
capabilities: ['Cloud Firewall Rule Set'],
410+
});
411+
412+
server.use(
413+
http.get('*/v4*/account', () => {
414+
return HttpResponse.json(account);
415+
})
416+
);
417+
406418
const { result } = renderHook(
407419
() => useIsFirewallRulesetsPrefixlistsEnabled(),
408420
{
@@ -417,7 +429,7 @@ describe('useIsFirewallRulesetsPrefixlistsEnabled', () => {
417429
});
418430
});
419431

420-
it('returns false if the feature is NOT enabled', async () => {
432+
it('returns false if the feature is NOT enabled but the account has the capability', async () => {
421433
const options = {
422434
flags: {
423435
fwRulesetsPrefixLists: {
@@ -429,6 +441,52 @@ describe('useIsFirewallRulesetsPrefixlistsEnabled', () => {
429441
},
430442
};
431443

444+
const account = accountFactory.build({
445+
capabilities: ['Cloud Firewall Rule Set'],
446+
});
447+
448+
server.use(
449+
http.get('*/v4*/account', () => {
450+
return HttpResponse.json(account);
451+
})
452+
);
453+
454+
const { result } = renderHook(
455+
() => useIsFirewallRulesetsPrefixlistsEnabled(),
456+
{
457+
wrapper: (ui) => wrapWithTheme(ui, options),
458+
}
459+
);
460+
461+
await waitFor(() => {
462+
expect(result.current.isFirewallRulesetsPrefixlistsFeatureEnabled).toBe(
463+
false
464+
);
465+
});
466+
});
467+
468+
it('returns false if the feature is enabled but the account DOES NOT have the capability', async () => {
469+
const options = {
470+
flags: {
471+
fwRulesetsPrefixLists: {
472+
enabled: true,
473+
beta: false,
474+
la: false,
475+
ga: false,
476+
},
477+
},
478+
};
479+
480+
const account = accountFactory.build({
481+
capabilities: [],
482+
});
483+
484+
server.use(
485+
http.get('*/v4*/account', () => {
486+
return HttpResponse.json(account);
487+
})
488+
);
489+
432490
const { result } = renderHook(
433491
() => useIsFirewallRulesetsPrefixlistsEnabled(),
434492
{

packages/manager/src/features/Firewalls/shared.tsx

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
import { useAccount } from '@linode/queries';
12
import { BetaChip, Box, Chip, NewFeatureChip, Tooltip } from '@linode/ui';
2-
import { capitalize, truncateAndJoinList } from '@linode/utilities';
3+
import {
4+
capitalize,
5+
isFeatureEnabledV2,
6+
truncateAndJoinList,
7+
} from '@linode/utilities';
38
import React from 'react';
49

510
import { Link } from 'src/components/Link';
@@ -107,6 +112,8 @@ export const allIPs = {
107112
ipv6: [allIPv6],
108113
};
109114

115+
export const FW_RULESET_CAPABILITY = 'Cloud Firewall Rule Set';
116+
110117
export interface PredefinedFirewall {
111118
inbound: FirewallRuleType[];
112119
label: string;
@@ -566,18 +573,40 @@ export const getFirewallDescription = (firewall: Firewall) => {
566573
* but will eventually also look at account capabilities if available.
567574
*/
568575
export const useIsFirewallRulesetsPrefixlistsEnabled = () => {
576+
const { data: account } = useAccount();
569577
const flags = useFlags();
570578

579+
if (!flags) {
580+
return {
581+
isFirewallRulesetsPrefixlistsFeatureEnabled: false,
582+
isFirewallRulesetsPrefixListsBetaEnabled: false,
583+
isFirewallRulesetsPrefixListsLAEnabled: false,
584+
isFirewallRulesetsPrefixListsGAEnabled: false,
585+
};
586+
}
587+
571588
// @TODO: Firewall Rulesets & Prefix Lists - check for customer tag/account capability when it exists
572589
return {
573-
isFirewallRulesetsPrefixlistsFeatureEnabled:
574-
flags.fwRulesetsPrefixLists?.enabled ?? false,
575-
isFirewallRulesetsPrefixListsBetaEnabled:
576-
flags.fwRulesetsPrefixLists?.beta ?? false,
577-
isFirewallRulesetsPrefixListsLAEnabled:
578-
flags.fwRulesetsPrefixLists?.la ?? false,
579-
isFirewallRulesetsPrefixListsGAEnabled:
580-
flags.fwRulesetsPrefixLists?.ga ?? false,
590+
isFirewallRulesetsPrefixlistsFeatureEnabled: isFeatureEnabledV2(
591+
FW_RULESET_CAPABILITY,
592+
Boolean(flags.fwRulesetsPrefixLists?.enabled),
593+
account?.capabilities ?? []
594+
),
595+
isFirewallRulesetsPrefixListsBetaEnabled: isFeatureEnabledV2(
596+
FW_RULESET_CAPABILITY,
597+
Boolean(flags.fwRulesetsPrefixLists?.beta),
598+
account?.capabilities ?? []
599+
),
600+
isFirewallRulesetsPrefixListsLAEnabled: isFeatureEnabledV2(
601+
FW_RULESET_CAPABILITY,
602+
Boolean(flags.fwRulesetsPrefixLists?.la),
603+
account?.capabilities ?? []
604+
),
605+
isFirewallRulesetsPrefixListsGAEnabled: isFeatureEnabledV2(
606+
FW_RULESET_CAPABILITY,
607+
Boolean(flags.fwRulesetsPrefixLists?.ga),
608+
account?.capabilities ?? []
609+
),
581610
};
582611
};
583612

0 commit comments

Comments
 (0)