1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 15:53:27 +00:00

use getUserId and getOrganizationById (#13017)

This commit is contained in:
Brandon Treston
2025-01-22 16:59:15 -05:00
committed by GitHub
parent a949f793ed
commit f5744ed28f

View File

@@ -2,10 +2,14 @@
// @ts-strict-ignore // @ts-strict-ignore
import { OptionValues } from "commander"; import { OptionValues } from "commander";
import * as inquirer from "inquirer"; import * as inquirer from "inquirer";
import { firstValueFrom, map } from "rxjs"; import { firstValueFrom } from "rxjs";
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction"; import {
OrganizationService,
getOrganizationById,
} from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { getUserId } from "@bitwarden/common/auth/services/account.service";
import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction"; import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction";
import { ImportServiceAbstraction, ImportType } from "@bitwarden/importer/core"; import { ImportServiceAbstraction, ImportType } from "@bitwarden/importer/core";
@@ -24,16 +28,12 @@ export class ImportCommand {
async run(format: ImportType, filepath: string, options: OptionValues): Promise<Response> { async run(format: ImportType, filepath: string, options: OptionValues): Promise<Response> {
const organizationId = options.organizationid; const organizationId = options.organizationid;
if (organizationId != null) { if (organizationId != null) {
const userId = await firstValueFrom( const userId = await firstValueFrom(getUserId(this.accountService.activeAccount$));
this.accountService.activeAccount$.pipe(map((a) => a?.id)),
);
if (!userId) { if (!userId) {
return Response.badRequest("No user found."); return Response.badRequest("No user found.");
} }
const organization = await firstValueFrom( const organization = await firstValueFrom(
this.organizationService this.organizationService.organizations$(userId).pipe(getOrganizationById(organizationId)),
.organizations$(userId)
.pipe(map((organizations) => organizations.find((o) => o.id === organizationId))),
); );
if (organization == null) { if (organization == null) {