Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/api-v4": Upcoming Features
---

RESPROT2- Added lock permissions to IAM types (AccountAdmin and AccountViewer ) ([#13305](https://github.com/linode/manager/pull/13305))
6 changes: 6 additions & 0 deletions packages/api-v4/src/iam/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ export type AccountAdmin =
| 'cancel_account'
| 'cancel_service_transfer'
| 'create_child_account_token'
| 'create_lock'
| 'create_profile_pat'
| 'create_profile_ssh_key'
| 'create_profile_tfa_secret'
| 'create_service_transfer'
| 'create_user'
| 'delete_lock'
| 'delete_profile_pat'
| 'delete_profile_phone_number'
| 'delete_profile_ssh_key'
Expand All @@ -98,6 +100,7 @@ export type AccountAdmin =
| 'list_delegate_users'
| 'list_enrolled_beta_programs'
| 'list_entities'
| 'list_locks'
| 'list_role_permissions'
| 'list_service_transfers'
| 'list_user_delegate_accounts'
Expand All @@ -123,6 +126,7 @@ export type AccountAdmin =
| 'view_account_settings'
| 'view_child_account'
| 'view_enrolled_beta_program'
| 'view_lock'
| 'view_network_usage'
| 'view_profile_security_question'
| 'view_region_available_service'
Expand Down Expand Up @@ -258,6 +262,7 @@ export type AccountViewer =
| 'list_default_firewalls'
| 'list_enrolled_beta_programs'
| 'list_entities'
| 'list_locks'
| 'list_role_permissions'
| 'list_service_transfers'
| 'list_user_grants'
Expand All @@ -266,6 +271,7 @@ export type AccountViewer =
| 'view_account_login'
| 'view_account_settings'
| 'view_enrolled_beta_program'
| 'view_lock'
| 'view_network_usage'
| 'view_region_available_service'
| 'view_service_transfer'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Upcoming Features
---

RESPROT2 - Display/Disable Lock/Unlock action in Linode list and detail action menu ([#13305](https://github.com/linode/manager/pull/13305))
1 change: 1 addition & 0 deletions packages/manager/src/dev-tools/FeatureFlagTool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const options: { flag: keyof Flags; label: string }[] = [
{ flag: 'objMultiCluster', label: 'OBJ Multi-Cluster' },
{ flag: 'objectStorageGen2', label: 'OBJ Gen2' },
{ flag: 'privateImageSharing', label: 'Private Image Sharing' },
{ flag: 'resourceLock', label: 'Resource Lock' },
{ flag: 'selfServeBetas', label: 'Self Serve Betas' },
{ flag: 'supportTicketSeverity', label: 'Support Ticket Severity' },
{ flag: 'dbaasV2', label: 'Databases V2 Beta' },
Expand Down
5 changes: 5 additions & 0 deletions packages/manager/src/featureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ interface FirewallRulesetsAndPrefixLists extends BetaFeatureFlag {
la: boolean;
}

interface ResourceLockFlag {
linodes: boolean;
}

export interface Flags {
acceleratedPlans: AcceleratedPlansFlag;
aclp: AclpFlag;
Expand Down Expand Up @@ -255,6 +259,7 @@ export interface Flags {
promos: boolean;
promotionalOffers: PromotionalOffer[];
referralBannerText: BannerContent;
resourceLock: ResourceLockFlag;
secureVmCopy: SecureVMCopy;
selfServeBetas: boolean;
soldOutChips: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { isMTCPlan } from 'src/features/components/PlansPanel/utils';
import { usePermissions } from 'src/features/IAM/hooks/usePermissions';
import { lishLaunch } from 'src/features/Lish/lishUtils';
import { useFlags } from 'src/hooks/useFlags';
import {
sendLinodeActionEvent,
sendLinodeActionMenuItemEvent,
Expand All @@ -18,7 +19,7 @@
import { buildQueryStringForLinodeClone } from './LinodeActionMenuUtils';

import type { LinodeHandlers } from '../LinodesLanding';
import type { LinodeBackups, LinodeType } from '@linode/api-v4';
import type { LinodeBackups, LinodeType, LockType } from '@linode/api-v4';
import type { ActionType } from 'src/features/Account/utils';

const MAINTENANCE_TOOLTIP_TEXT =
Expand All @@ -36,6 +37,7 @@
linodeRegion: string;
linodeStatus: string;
linodeType?: LinodeType;
locks?: LockType[];
}

interface ActionConfig {
Expand All @@ -49,16 +51,22 @@
}

export const LinodeActionMenu = (props: LinodeActionMenuProps) => {
const { linodeId, linodeRegion, linodeStatus, linodeType } = props;
const { linodeId, linodeRegion, linodeStatus, linodeType, locks } = props;

const navigate = useNavigate();
const flags = useFlags();
const regions = useRegionsQuery().data ?? [];
const isBareMetalInstance = linodeType?.class === 'metal';
const hasHostMaintenance = linodeStatus === 'stopped';
const [isOpen, setIsOpen] = React.useState<boolean>(false);

const isResourceLockEnabled = flags.resourceLock?.linodes;
const isLocked = !!locks?.length;

const { data: accountPermissions } = usePermissions('account', [
'create_linode',
'create_lock',
'delete_lock',
]);

const { data: permissions, isLoading } = usePermissions(
Expand Down Expand Up @@ -234,6 +242,33 @@
? MAINTENANCE_TOOLTIP_TEXT
: undefined,
},
{
condition: Boolean(isResourceLockEnabled),
disabled: isLocked
? !accountPermissions.delete_lock
: !accountPermissions.create_lock,
isReadOnly: isLocked
? !accountPermissions.delete_lock
: !accountPermissions.create_lock,
onClick: () => {
if (isLocked) {
sendLinodeActionMenuItemEvent('Unlock Linode');
// props.onOpenUnlockDialog();

Check warning on line 256 in packages/manager/src/features/Linodes/LinodesLanding/LinodeActionMenu/LinodeActionMenu.tsx

View workflow job for this annotation

GitHub Actions / ESLint Review (manager)

[eslint] reported by reviewdog 🐢 Remove this commented out code. Raw Output: {"ruleId":"sonarjs/no-commented-code","severity":1,"message":"Remove this commented out code.","line":256,"column":11,"nodeType":null,"messageId":"commentedCode","endLine":256,"endColumn":41,"suggestions":[{"messageId":"commentedCodeFix","fix":{"range":[8520,8550],"text":""},"desc":"Remove this commented out code"}]}
} else {
sendLinodeActionMenuItemEvent('Lock Linode');
// props.onOpenAddLockDialog();

Check warning on line 259 in packages/manager/src/features/Linodes/LinodesLanding/LinodeActionMenu/LinodeActionMenu.tsx

View workflow job for this annotation

GitHub Actions / ESLint Review (manager)

[eslint] reported by reviewdog 🐢 Remove this commented out code. Raw Output: {"ruleId":"sonarjs/no-commented-code","severity":1,"message":"Remove this commented out code.","line":259,"column":11,"nodeType":null,"messageId":"commentedCode","endLine":259,"endColumn":42,"suggestions":[{"messageId":"commentedCodeFix","fix":{"range":[8634,8665],"text":""},"desc":"Remove this commented out code"}]}
}
},
title: isLocked ? 'Unlock' : 'Lock',
tooltipAction: 'edit',
tooltipText: isLocked
? !accountPermissions.delete_lock
? NO_PERMISSION_TOOLTIP_TEXT
: undefined
: !accountPermissions.create_lock
? NO_PERMISSION_TOOLTIP_TEXT
: undefined,
},
{
condition: true,
disabled: !permissions.delete_linode || hasHostMaintenance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const LinodeRow = (props: Props) => {
id,
ipv4,
label,
locks,
maintenance,
region,
status,
Expand Down Expand Up @@ -189,6 +190,7 @@ export const LinodeRow = (props: Props) => {
linodeRegion={region}
linodeStatus={status}
linodeType={linodeType}
locks={locks}
{...handlers}
/>
</TableCell>
Expand Down
7 changes: 6 additions & 1 deletion packages/queries/src/locks/locks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ export const lockQueries = createQueryKeys('locks', {
* @example
* const { data, isLoading } = useLocksQuery();
*/
export const useLocksQuery = (params: Params = {}, filter: Filter = {}) => {
export const useLocksQuery = (
params: Params = {},
filter: Filter = {},
enabled: boolean = true,
) => {
return useQuery<ResourcePage<ResourceLock>, APIError[]>({
...lockQueries.locks._ctx.paginated(params, filter),
enabled,
});
};

Expand Down