mirror of
https://github.com/bitwarden/browser
synced 2026-01-04 17:43:39 +00:00
[PM-23360] - Hide restricted cipher types in "File -> New Item" on desktop (#15743)
* hide restricted cipher types in file menu on desktop * fix bitwarden menu * small fixes
This commit is contained in:
@@ -2,6 +2,7 @@ import { BrowserWindow, MenuItemConstructorOptions } from "electron";
|
||||
|
||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
||||
import { CipherType } from "@bitwarden/sdk-internal";
|
||||
|
||||
import { isMac, isMacAppStore } from "../../utils";
|
||||
import { UpdaterMain } from "../updater.main";
|
||||
@@ -54,6 +55,7 @@ export class FileMenu extends FirstMenu implements IMenubarMenu {
|
||||
accounts: { [userId: string]: MenuAccount },
|
||||
isLocked: boolean,
|
||||
isLockable: boolean,
|
||||
private restrictedCipherTypes: CipherType[],
|
||||
) {
|
||||
super(i18nService, messagingService, updater, window, accounts, isLocked, isLockable);
|
||||
}
|
||||
@@ -77,6 +79,23 @@ export class FileMenu extends FirstMenu implements IMenubarMenu {
|
||||
};
|
||||
}
|
||||
|
||||
private mapMenuItemToCipherType(itemId: string): CipherType {
|
||||
switch (itemId) {
|
||||
case "typeLogin":
|
||||
return CipherType.Login;
|
||||
case "typeCard":
|
||||
return CipherType.Card;
|
||||
case "typeIdentity":
|
||||
return CipherType.Identity;
|
||||
case "typeSecureNote":
|
||||
return CipherType.SecureNote;
|
||||
case "typeSshKey":
|
||||
return CipherType.SshKey;
|
||||
default:
|
||||
throw new Error(`Unknown menu item id: ${itemId}`);
|
||||
}
|
||||
}
|
||||
|
||||
private get addNewItemSubmenu(): MenuItemConstructorOptions[] {
|
||||
return [
|
||||
{
|
||||
@@ -109,7 +128,11 @@ export class FileMenu extends FirstMenu implements IMenubarMenu {
|
||||
click: () => this.sendMessage("newSshKey"),
|
||||
accelerator: "CmdOrCtrl+Shift+K",
|
||||
},
|
||||
];
|
||||
].filter((item) => {
|
||||
return !this.restrictedCipherTypes?.some(
|
||||
(restrictedType) => restrictedType === this.mapMenuItemToCipherType(item.id),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
private get addNewFolder(): MenuItemConstructorOptions {
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
// FIXME: Update this file to be type safe and remove this and next line
|
||||
// @ts-strict-ignore
|
||||
import { CipherType } from "@bitwarden/common/vault/enums";
|
||||
export class MenuUpdateRequest {
|
||||
activeUserId: string;
|
||||
accounts: { [userId: string]: MenuAccount };
|
||||
activeUserId: string | null;
|
||||
accounts: { [userId: string]: MenuAccount } | null;
|
||||
restrictedCipherTypes: CipherType[] | null;
|
||||
}
|
||||
|
||||
export class MenuAccount {
|
||||
|
||||
@@ -83,6 +83,7 @@ export class Menubar {
|
||||
updateRequest?.accounts,
|
||||
isLocked,
|
||||
isLockable,
|
||||
updateRequest?.restrictedCipherTypes,
|
||||
),
|
||||
new EditMenu(i18nService, messagingService, isLocked),
|
||||
new ViewMenu(i18nService, messagingService, isLocked),
|
||||
|
||||
Reference in New Issue
Block a user