Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { AccountService } from "@bitwarden/common/auth/abstractions/account.serv
import { getUserId } from "@bitwarden/common/auth/services/account.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { uuidAsString } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
import { CipherId } from "@bitwarden/common/types/guid";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
import { CipherType } from "@bitwarden/common/vault/enums";
Expand Down Expand Up @@ -321,7 +322,7 @@ export class VaultListItemsContainerComponent implements AfterViewInit {
}

const activeUserId = await firstValueFrom(this.accountService.activeAccount$.pipe(getUserId));
await this.cipherService.updateLastLaunchedDate(cipher.id!, activeUserId);
await this.cipherService.updateLastLaunchedDate(uuidAsString(cipher.id!), activeUserId);

await BrowserApi.createNewTab(launchURI);

Expand All @@ -338,7 +339,7 @@ export class VaultListItemsContainerComponent implements AfterViewInit {

// When only the `CipherListView` is available, fetch the full cipher details
const activeUserId = await firstValueFrom(this.accountService.activeAccount$.pipe(getUserId));
const _cipher = await this.cipherService.get(cipher.id!, activeUserId);
const _cipher = await this.cipherService.get(uuidAsString(cipher.id!), activeUserId);
const cipherView = await this.cipherService.decrypt(_cipher, activeUserId);

await this.vaultPopupAutofillService.doAutofill(cipherView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { OrganizationService } from "@bitwarden/common/admin-console/abstraction
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { ProductTierType } from "@bitwarden/common/billing/enums";
import { uuidAsString } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
import { Utils } from "@bitwarden/common/platform/misc/utils";
import { SyncService } from "@bitwarden/common/platform/sync";
import { ObservableTracker, mockAccountServiceWith } from "@bitwarden/common/spec";
Expand Down Expand Up @@ -102,7 +103,7 @@ describe("VaultPopupItemsService", () => {

searchService.searchCiphers.mockImplementation(async (userId, _, __, ciphers) => ciphers);
cipherServiceMock.filterCiphersForUrl.mockImplementation(async (ciphers) =>
ciphers.filter((c) => ["0", "1"].includes(c.id)),
ciphers.filter((c) => ["0", "1"].includes(uuidAsString(c.id))),
);
vaultSettingsServiceMock.showCardsCurrentTab$ = new BehaviorSubject(false);
vaultSettingsServiceMock.showIdentitiesCurrentTab$ = new BehaviorSubject(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { AccountService } from "@bitwarden/common/auth/abstractions/account.serv
import { ProductTierType } from "@bitwarden/common/billing/enums";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { asUuid } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
import { StateProvider } from "@bitwarden/common/platform/state";
import { mockAccountServiceWith } from "@bitwarden/common/spec";
import { UserId } from "@bitwarden/common/types/guid";
Expand Down Expand Up @@ -514,8 +515,17 @@ describe("VaultPopupListFiltersService", () => {
describe("filterFunction$", () => {
const ciphers = [
{ type: CipherType.Login, collectionIds: [], organizationId: null },
{ type: CipherType.Card, collectionIds: ["1234"], organizationId: "8978" },
{ type: CipherType.Identity, collectionIds: [], folderId: "5432", organizationId: null },
{
type: CipherType.Card,
collectionIds: [asUuid("cbcae898-9f9a-48eb-863e-edf92e3ad7e0")],
organizationId: "8978" as any,
},
{
type: CipherType.Identity,
collectionIds: [],
folderId: "5432" as any,
organizationId: null,
},
{ type: CipherType.SecureNote, collectionIds: [], organizationId: null },
] as CipherView[];

Expand All @@ -529,7 +539,7 @@ describe("VaultPopupListFiltersService", () => {
});

it("filters by collection", (done) => {
const collection = { id: "1234" } as CollectionView;
const collection = { id: "cbcae898-9f9a-48eb-863e-edf92e3ad7e0" } as CollectionView;

service.filterFunction$.subscribe((filterFunction) => {
expect(filterFunction(ciphers)).toEqual([ciphers[1]]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { ProductTierType } from "@bitwarden/common/billing/enums";
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { asUuid } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
import { Utils } from "@bitwarden/common/platform/misc/utils";
import {
KeyDefinition,
Expand Down Expand Up @@ -236,7 +237,10 @@ export class VaultPopupListFiltersService {
return false;
}

if (filters.collection && !cipher.collectionIds?.includes(filters.collection.id!)) {
if (
filters.collection &&
!cipher.collectionIds?.includes(asUuid(filters.collection.id!))
) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { distinctUntilChanged } from "rxjs";
import { JslibModule } from "@bitwarden/angular/jslib.module";
import { VaultItemsComponent as BaseVaultItemsComponent } from "@bitwarden/angular/vault/components/vault-items.component";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { uuidAsString } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
import { SearchService } from "@bitwarden/common/vault/abstractions/search.service";
import { RestrictedItemTypesService } from "@bitwarden/common/vault/services/restricted-item-types.service";
Expand Down Expand Up @@ -42,6 +43,6 @@ export class VaultItemsV2Component<C extends CipherViewLike> extends BaseVaultIt
}

trackByFn(index: number, c: C): string {
return c.id!;
return uuidAsString(c.id!);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import { Component, Input } from "@angular/core";

import { CollectionView } from "@bitwarden/admin-console/common";
import { uuidAsString } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
import { CollectionId } from "@bitwarden/sdk-internal";

import { SharedModule } from "../../../../shared/shared.module";
import { GetCollectionNameFromIdPipe } from "../pipes";
Expand All @@ -13,11 +15,11 @@ import { GetCollectionNameFromIdPipe } from "../pipes";
imports: [SharedModule, GetCollectionNameFromIdPipe],
})
export class CollectionNameBadgeComponent {
@Input() collectionIds: string[];
@Input() collectionIds: CollectionId[] | string[];
@Input() collections: CollectionView[];

get shownCollections(): string[] {
return this.showXMore ? this.collectionIds.slice(0, 2) : this.collectionIds;
return (this.showXMore ? this.collectionIds.slice(0, 2) : this.collectionIds).map(uuidAsString);
}

get showXMore(): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ export class VaultItemsComponent<C extends CipherViewLike> {
const orgCollections = this.allCollections.filter((c) => c.organizationId === org.id);

for (const collection of orgCollections) {
if (vaultItem.cipher.collectionIds.includes(collection.id) && collection.manage) {
if (vaultItem.cipher.collectionIds.includes(collection.id as any) && collection.manage) {
return true;
}
}
Expand Down Expand Up @@ -364,7 +364,7 @@ export class VaultItemsComponent<C extends CipherViewLike> {
}

return this.allCollections
.filter((c) => cipher.collectionIds.includes(c.id))
.filter((c) => cipher.collectionIds.includes(c.id as any))
.some((collection) => collection.manage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import { AvatarService } from "@bitwarden/common/auth/abstractions/avatar.servic
import { TokenService } from "@bitwarden/common/auth/abstractions/token.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { Utils } from "@bitwarden/common/platform/misc/utils";
import { OrganizationId } from "@bitwarden/sdk-internal";

@Component({
selector: "app-org-badge",
templateUrl: "organization-name-badge.component.html",
standalone: false,
})
export class OrganizationNameBadgeComponent implements OnChanges {
@Input() organizationId?: string;
@Input() organizationId?: OrganizationId | string;
@Input() organizationName: string;
@Input() disabled: boolean;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Pipe, PipeTransform } from "@angular/core";

import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
import { OrganizationId } from "@bitwarden/sdk-internal";

@Pipe({
name: "orgNameFromId",
pure: true,
standalone: false,
})
export class GetOrgNameFromIdPipe implements PipeTransform {
transform(value: string, organizations: Organization[]) {
transform(value: string | OrganizationId, organizations: Organization[]) {
const orgName = organizations?.find((o) => o.id === value)?.name;
return orgName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function createFilterFunction(filter: RoutedVaultFilterModel): FilterFunc
filter.collectionId !== undefined &&
filter.collectionId !== All &&
filter.collectionId !== Unassigned &&
(cipher.collectionIds == null || !cipher.collectionIds.includes(filter.collectionId))
(cipher.collectionIds == null || !cipher.collectionIds.includes(filter.collectionId as any))
) {
return false;
}
Expand Down
24 changes: 14 additions & 10 deletions apps/web/src/app/vault/individual-vault/vault.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.servic
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { uuidAsString } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
import { Utils } from "@bitwarden/common/platform/misc/utils";
import { SyncService } from "@bitwarden/common/platform/sync";
import { CipherId, CollectionId, OrganizationId, UserId } from "@bitwarden/common/types/guid";
Expand Down Expand Up @@ -678,7 +679,7 @@ export class VaultComponent<C extends CipherViewLike> implements OnInit, OnDestr
return;
} else if (cipher.organizationId != null) {
const org = await firstValueFrom(
this.organizations$.pipe(getOrganizationById(cipher.organizationId)),
this.organizations$.pipe(getOrganizationById(uuidAsString(cipher.organizationId))),
);
if (org != null && (org.maxStorageGb == null || org.maxStorageGb === 0)) {
this.messagingService.send("upgradeOrganization", {
Expand Down Expand Up @@ -775,7 +776,7 @@ export class VaultComponent<C extends CipherViewLike> implements OnInit, OnDestr
}

async editCipher(cipher: CipherView | CipherListView, cloneMode?: boolean) {
return this.editCipherId(cipher?.id, cloneMode);
return this.editCipherId(uuidAsString(cipher?.id), cloneMode);
}

/**
Expand Down Expand Up @@ -1044,7 +1045,7 @@ export class VaultComponent<C extends CipherViewLike> implements OnInit, OnDestr

try {
const activeUserId = await firstValueFrom(this.accountService.activeAccount$.pipe(getUserId));
await this.cipherService.restoreWithServer(c.id, activeUserId);
await this.cipherService.restoreWithServer(uuidAsString(c.id), activeUserId);
this.toastService.showToast({
variant: "success",
title: null,
Expand All @@ -1066,7 +1067,7 @@ export class VaultComponent<C extends CipherViewLike> implements OnInit, OnDestr
return;
}

const selectedCipherIds = ciphers.map((cipher) => cipher.id);
const selectedCipherIds = ciphers.map((cipher) => uuidAsString(cipher.id));
if (selectedCipherIds.length === 0) {
this.toastService.showToast({
variant: "error",
Expand Down Expand Up @@ -1128,7 +1129,7 @@ export class VaultComponent<C extends CipherViewLike> implements OnInit, OnDestr

try {
const activeUserId = await firstValueFrom(this.accountService.activeAccount$.pipe(getUserId));
await this.deleteCipherWithServer(c.id, activeUserId, permanent);
await this.deleteCipherWithServer(uuidAsString(c.id), activeUserId, permanent);

this.toastService.showToast({
variant: "success",
Expand Down Expand Up @@ -1168,7 +1169,7 @@ export class VaultComponent<C extends CipherViewLike> implements OnInit, OnDestr
const dialog = openBulkDeleteDialog(this.dialogService, {
data: {
permanent: this.filter.type === "trash",
cipherIds: ciphers.map((c) => c.id),
cipherIds: ciphers.map((c) => uuidAsString(c.id)),
organizations: organizations,
collections: collections,
},
Expand All @@ -1185,7 +1186,7 @@ export class VaultComponent<C extends CipherViewLike> implements OnInit, OnDestr
return;
}

const selectedCipherIds = ciphers.map((cipher) => cipher.id);
const selectedCipherIds = ciphers.map((cipher) => uuidAsString(cipher.id));
if (selectedCipherIds.length === 0) {
this.toastService.showToast({
variant: "error",
Expand Down Expand Up @@ -1261,11 +1262,14 @@ export class VaultComponent<C extends CipherViewLike> implements OnInit, OnDestr
});

if (field === "password") {
await this.eventCollectionService.collect(EventType.Cipher_ClientCopiedPassword, cipher.id);
await this.eventCollectionService.collect(
EventType.Cipher_ClientCopiedPassword,
uuidAsString(cipher.id),
);
} else if (field === "totp") {
await this.eventCollectionService.collect(
EventType.Cipher_ClientCopiedHiddenField,
cipher.id,
uuidAsString(cipher.id),
);
}
}
Expand Down Expand Up @@ -1324,7 +1328,7 @@ export class VaultComponent<C extends CipherViewLike> implements OnInit, OnDestr
}

const activeUserId = await firstValueFrom(this.accountService.activeAccount$.pipe(getUserId));
const _cipher = await this.cipherService.get(cipher.id, activeUserId);
const _cipher = await this.cipherService.get(uuidAsString(cipher.id), activeUserId);
const cipherView = await this.cipherService.decrypt(_cipher, activeUserId);
return cipherView.login?.password;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,18 @@ describe("VaultFilter", () => {
});

describe("given an organizational cipher (with organization and collections)", () => {
const collection1 = "e9652fc0-1fe4-48d5-a3d8-d821e32fbd98";
const collection2 = "42a971a5-8c16-48a3-a725-4be27cd99bc9";

const cipher = createCipher({
organizationId: "organizationId",
collectionIds: ["collectionId", "anotherId"],
collectionIds: [collection1, collection2],
});

it("should return true when filter matches collection id", () => {
const filterFunction = createFilterFunction({
selectedCollection: true,
selectedCollectionId: "collectionId",
selectedCollectionId: collection1,
});

const result = filterFunction(cipher);
Expand All @@ -137,7 +140,7 @@ describe("VaultFilter", () => {
it("should return false when filter does not match collection id", () => {
const filterFunction = createFilterFunction({
selectedCollection: true,
selectedCollectionId: "nonMatchingId",
selectedCollectionId: "1ea7ad96-3fc1-4567-8fe5-91aa9f697fd1",
});

const result = filterFunction(cipher);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { asUuid } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
import { CipherType } from "@bitwarden/common/vault/enums";
import {
CipherViewLike,
Expand Down Expand Up @@ -65,7 +66,8 @@ export class VaultFilter {
}
if (this.selectedCollection && this.selectedCollectionId != null && cipherPassesFilter) {
cipherPassesFilter =
cipher.collectionIds != null && cipher.collectionIds.includes(this.selectedCollectionId);
cipher.collectionIds != null &&
cipher.collectionIds.includes(asUuid(this.selectedCollectionId));
}
if (this.selectedOrganizationId != null && cipherPassesFilter) {
cipherPassesFilter = cipher.organizationId === this.selectedOrganizationId;
Expand Down
2 changes: 1 addition & 1 deletion libs/common/src/platform/abstractions/sdk/sdk.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function asUuid<T extends Uuid>(uuid: string): T {
/**
* Converts a UUID to the string representation.
*/
export function uuidToString<T extends Uuid>(uuid: T): string {
export function uuidAsString<T extends Uuid>(uuid: T): string {
return uuid as unknown as string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe("DefaultSdkService", () => {
});

describe("given the user is logged in", () => {
const userId = "user-id" as UserId;
const userId = "0da62ebd-98bb-4f42-a846-64e8555087d7" as UserId;
beforeEach(() => {
environmentService.getEnvironment$
.calledWith(userId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { Environment, EnvironmentService } from "../../abstractions/environment.
import { PlatformUtilsService } from "../../abstractions/platform-utils.service";
import { SdkClientFactory } from "../../abstractions/sdk/sdk-client-factory";
import { SdkLoadService } from "../../abstractions/sdk/sdk-load.service";
import { SdkService, UserNotLoggedInError } from "../../abstractions/sdk/sdk.service";
import { asUuid, SdkService, UserNotLoggedInError } from "../../abstractions/sdk/sdk.service";
import { compareValues } from "../../misc/compare-values";
import { Rc } from "../../misc/reference-counting/rc";

Expand Down Expand Up @@ -214,7 +214,7 @@ export class DefaultSdkService implements SdkService {
orgKeys: Record<OrganizationId, EncryptedOrganizationKeyData> | null,
) {
await client.crypto().initialize_user_crypto({
userId,
userId: asUuid(userId),
email: account.email,
method: { decryptedKey: { decrypted_user_key: userKey.keyB64 } },
kdfParams:
Expand All @@ -238,7 +238,7 @@ export class DefaultSdkService implements SdkService {
organizationKeys: new Map(
Object.entries(orgKeys ?? {})
.filter(([_, v]) => v.type === "organization")
.map(([k, v]) => [k, v.key as UnsignedSharedKey]),
.map(([k, v]) => [asUuid(k), v.key as UnsignedSharedKey]),
),
});
}
Expand Down
Loading
Loading