1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 07:43:35 +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:
Jordan Aasen
2025-07-23 09:33:45 -07:00
committed by GitHub
parent 417c4cd13b
commit 2040be68e3
4 changed files with 36 additions and 3 deletions

View File

@@ -68,6 +68,7 @@ import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.servi
import { InternalFolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
import { SearchService } from "@bitwarden/common/vault/abstractions/search.service";
import { CipherType } from "@bitwarden/common/vault/enums";
import { RestrictedItemTypesService } from "@bitwarden/common/vault/services/restricted-item-types.service";
import { DialogRef, DialogService, ToastOptions, ToastService } from "@bitwarden/components";
import { CredentialGeneratorHistoryDialogComponent } from "@bitwarden/generator-components";
import { KeyService, BiometricStateService } from "@bitwarden/key-management";
@@ -172,6 +173,7 @@ export class AppComponent implements OnInit, OnDestroy {
private userDecryptionOptionsService: UserDecryptionOptionsServiceAbstraction,
private readonly destroyRef: DestroyRef,
private readonly documentLangSetter: DocumentLangSetter,
private restrictedItemTypesService: RestrictedItemTypesService,
) {
this.deviceTrustToastService.setupListeners$.pipe(takeUntilDestroyed()).subscribe();
@@ -523,10 +525,12 @@ export class AppComponent implements OnInit, OnDestroy {
private async updateAppMenu() {
let updateRequest: MenuUpdateRequest;
const stateAccounts = await firstValueFrom(this.accountService.accounts$);
if (stateAccounts == null || Object.keys(stateAccounts).length < 1) {
updateRequest = {
accounts: null,
activeUserId: null,
restrictedCipherTypes: null,
};
} else {
const accounts: { [userId: string]: MenuAccount } = {};
@@ -557,6 +561,9 @@ export class AppComponent implements OnInit, OnDestroy {
activeUserId: await firstValueFrom(
this.accountService.activeAccount$.pipe(map((a) => a?.id)),
),
restrictedCipherTypes: (
await firstValueFrom(this.restrictedItemTypesService.restricted$)
).map((restrictedItems) => restrictedItems.cipherType),
};
}

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -83,6 +83,7 @@ export class Menubar {
updateRequest?.accounts,
isLocked,
isLockable,
updateRequest?.restrictedCipherTypes,
),
new EditMenu(i18nService, messagingService, isLocked),
new ViewMenu(i18nService, messagingService, isLocked),