1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 08:43:33 +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 { InternalFolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
import { SearchService } from "@bitwarden/common/vault/abstractions/search.service"; import { SearchService } from "@bitwarden/common/vault/abstractions/search.service";
import { CipherType } from "@bitwarden/common/vault/enums"; 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 { DialogRef, DialogService, ToastOptions, ToastService } from "@bitwarden/components";
import { CredentialGeneratorHistoryDialogComponent } from "@bitwarden/generator-components"; import { CredentialGeneratorHistoryDialogComponent } from "@bitwarden/generator-components";
import { KeyService, BiometricStateService } from "@bitwarden/key-management"; import { KeyService, BiometricStateService } from "@bitwarden/key-management";
@@ -172,6 +173,7 @@ export class AppComponent implements OnInit, OnDestroy {
private userDecryptionOptionsService: UserDecryptionOptionsServiceAbstraction, private userDecryptionOptionsService: UserDecryptionOptionsServiceAbstraction,
private readonly destroyRef: DestroyRef, private readonly destroyRef: DestroyRef,
private readonly documentLangSetter: DocumentLangSetter, private readonly documentLangSetter: DocumentLangSetter,
private restrictedItemTypesService: RestrictedItemTypesService,
) { ) {
this.deviceTrustToastService.setupListeners$.pipe(takeUntilDestroyed()).subscribe(); this.deviceTrustToastService.setupListeners$.pipe(takeUntilDestroyed()).subscribe();
@@ -523,10 +525,12 @@ export class AppComponent implements OnInit, OnDestroy {
private async updateAppMenu() { private async updateAppMenu() {
let updateRequest: MenuUpdateRequest; let updateRequest: MenuUpdateRequest;
const stateAccounts = await firstValueFrom(this.accountService.accounts$); const stateAccounts = await firstValueFrom(this.accountService.accounts$);
if (stateAccounts == null || Object.keys(stateAccounts).length < 1) { if (stateAccounts == null || Object.keys(stateAccounts).length < 1) {
updateRequest = { updateRequest = {
accounts: null, accounts: null,
activeUserId: null, activeUserId: null,
restrictedCipherTypes: null,
}; };
} else { } else {
const accounts: { [userId: string]: MenuAccount } = {}; const accounts: { [userId: string]: MenuAccount } = {};
@@ -557,6 +561,9 @@ export class AppComponent implements OnInit, OnDestroy {
activeUserId: await firstValueFrom( activeUserId: await firstValueFrom(
this.accountService.activeAccount$.pipe(map((a) => a?.id)), 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 { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
import { CipherType } from "@bitwarden/sdk-internal";
import { isMac, isMacAppStore } from "../../utils"; import { isMac, isMacAppStore } from "../../utils";
import { UpdaterMain } from "../updater.main"; import { UpdaterMain } from "../updater.main";
@@ -54,6 +55,7 @@ export class FileMenu extends FirstMenu implements IMenubarMenu {
accounts: { [userId: string]: MenuAccount }, accounts: { [userId: string]: MenuAccount },
isLocked: boolean, isLocked: boolean,
isLockable: boolean, isLockable: boolean,
private restrictedCipherTypes: CipherType[],
) { ) {
super(i18nService, messagingService, updater, window, accounts, isLocked, isLockable); 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[] { private get addNewItemSubmenu(): MenuItemConstructorOptions[] {
return [ return [
{ {
@@ -109,7 +128,11 @@ export class FileMenu extends FirstMenu implements IMenubarMenu {
click: () => this.sendMessage("newSshKey"), click: () => this.sendMessage("newSshKey"),
accelerator: "CmdOrCtrl+Shift+K", accelerator: "CmdOrCtrl+Shift+K",
}, },
]; ].filter((item) => {
return !this.restrictedCipherTypes?.some(
(restrictedType) => restrictedType === this.mapMenuItemToCipherType(item.id),
);
});
} }
private get addNewFolder(): MenuItemConstructorOptions { private get addNewFolder(): MenuItemConstructorOptions {

View File

@@ -1,8 +1,10 @@
// FIXME: Update this file to be type safe and remove this and next line // FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore // @ts-strict-ignore
import { CipherType } from "@bitwarden/common/vault/enums";
export class MenuUpdateRequest { export class MenuUpdateRequest {
activeUserId: string; activeUserId: string | null;
accounts: { [userId: string]: MenuAccount }; accounts: { [userId: string]: MenuAccount } | null;
restrictedCipherTypes: CipherType[] | null;
} }
export class MenuAccount { export class MenuAccount {

View File

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