From a139fb5def8caabeb38c8518e5c1ec7b2b8e8ee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rui=20Tom=C3=A9?= <108268980+r-tome@users.noreply.github.com> Date: Fri, 8 Aug 2025 13:53:27 +0100 Subject: [PATCH] [PM-24433] Update the CLI confirm org-member command to create a default collection (#15917) * Update the CLI ConfirmCommand to send the DefaultUserCollectionName for default collection creation * Add "My Items" message to CLI * Refactor ConfirmCommand to encapsulate default user collection name encryption in a separate method --- .../admin-console/commands/confirm.command.ts | 20 +++++++++++++++++++ apps/cli/src/locales/en/messages.json | 3 +++ apps/cli/src/oss-serve-configurator.ts | 2 ++ apps/cli/src/vault.program.ts | 2 ++ 4 files changed, 27 insertions(+) diff --git a/apps/cli/src/admin-console/commands/confirm.command.ts b/apps/cli/src/admin-console/commands/confirm.command.ts index 1c900511499..f2965a23402 100644 --- a/apps/cli/src/admin-console/commands/confirm.command.ts +++ b/apps/cli/src/admin-console/commands/confirm.command.ts @@ -1,13 +1,20 @@ // FIXME: Update this file to be type safe and remove this and next line // @ts-strict-ignore +import { firstValueFrom } from "rxjs"; + import { OrganizationUserApiService, OrganizationUserConfirmRequest, } from "@bitwarden/admin-console/common"; import { ApiService } from "@bitwarden/common/abstractions/api.service"; +import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum"; import { EncryptService } from "@bitwarden/common/key-management/crypto/abstractions/encrypt.service"; +import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service"; +import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { Utils } from "@bitwarden/common/platform/misc/utils"; +import { OrgKey } from "@bitwarden/common/types/key"; import { KeyService } from "@bitwarden/key-management"; +import { EncString } from "@bitwarden/sdk-internal"; import { Response } from "../../models/response"; @@ -17,6 +24,8 @@ export class ConfirmCommand { private keyService: KeyService, private encryptService: EncryptService, private organizationUserApiService: OrganizationUserApiService, + private configService: ConfigService, + private i18nService: I18nService, ) {} async run(object: string, id: string, cmdOptions: Record): Promise { @@ -60,6 +69,11 @@ export class ConfirmCommand { const key = await this.encryptService.encapsulateKeyUnsigned(orgKey, publicKey); const req = new OrganizationUserConfirmRequest(); req.key = key.encryptedString; + if ( + await firstValueFrom(this.configService.getFeatureFlag$(FeatureFlag.CreateDefaultLocation)) + ) { + req.defaultUserCollectionName = await this.getEncryptedDefaultUserCollectionName(orgKey); + } await this.organizationUserApiService.postOrganizationUserConfirm( options.organizationId, id, @@ -70,6 +84,12 @@ export class ConfirmCommand { return Response.error(e); } } + + private async getEncryptedDefaultUserCollectionName(orgKey: OrgKey): Promise { + const defaultCollectionName = this.i18nService.t("myItems"); + const encrypted = await this.encryptService.encryptString(defaultCollectionName, orgKey); + return encrypted.encryptedString; + } } class Options { diff --git a/apps/cli/src/locales/en/messages.json b/apps/cli/src/locales/en/messages.json index 815939c0c95..cb7f89781dd 100644 --- a/apps/cli/src/locales/en/messages.json +++ b/apps/cli/src/locales/en/messages.json @@ -215,5 +215,8 @@ }, "youHaveBeenLoggedOut": { "message": "You have been logged out." + }, + "myItems": { + "message": "My Items" } } diff --git a/apps/cli/src/oss-serve-configurator.ts b/apps/cli/src/oss-serve-configurator.ts index a460fa270a8..760fa8935b6 100644 --- a/apps/cli/src/oss-serve-configurator.ts +++ b/apps/cli/src/oss-serve-configurator.ts @@ -131,6 +131,8 @@ export class OssServeConfigurator { this.serviceContainer.keyService, this.serviceContainer.encryptService, this.serviceContainer.organizationUserApiService, + this.serviceContainer.configService, + this.serviceContainer.i18nService, ); this.restoreCommand = new RestoreCommand( this.serviceContainer.cipherService, diff --git a/apps/cli/src/vault.program.ts b/apps/cli/src/vault.program.ts index bdcc52393ca..dfd18570e42 100644 --- a/apps/cli/src/vault.program.ts +++ b/apps/cli/src/vault.program.ts @@ -432,6 +432,8 @@ export class VaultProgram extends BaseProgram { this.serviceContainer.keyService, this.serviceContainer.encryptService, this.serviceContainer.organizationUserApiService, + this.serviceContainer.configService, + this.serviceContainer.i18nService, ); const response = await command.run(object, id, cmd); this.processResponse(response);