Skip to content

Commit

Permalink
Vault Refactor: Clean up some strict types (#12357)
Browse files Browse the repository at this point in the history
* update cipher-view to account for strict type checking

* update view-identity-sections to account for strict type checking

* update read-only-cipher-card to account for strict type checking

* remove unused card import

* remove unused card import

* update additional-options to account for strict type checking
  • Loading branch information
nick-livefront authored Dec 20, 2024
1 parent b27a1a5 commit 6ad35e0
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { CommonModule } from "@angular/common";
import { Component, Input } from "@angular/core";

Expand Down Expand Up @@ -31,5 +29,5 @@ import {
],
})
export class AdditionalOptionsComponent {
@Input() notes: string;
@Input() notes: string = "";
}
28 changes: 20 additions & 8 deletions libs/vault/src/cipher-view/cipher-view.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { CommonModule } from "@angular/common";
import { Component, Input, OnChanges, OnDestroy } from "@angular/core";
import { firstValueFrom, Observable, Subject, takeUntil } from "rxjs";
Expand Down Expand Up @@ -48,19 +46,19 @@ import { ViewIdentitySectionsComponent } from "./view-identity-sections/view-ide
],
})
export class CipherViewComponent implements OnChanges, OnDestroy {
@Input({ required: true }) cipher: CipherView;
@Input({ required: true }) cipher: CipherView | null = null;

/**
* Optional list of collections the cipher is assigned to. If none are provided, they will be fetched using the
* `CipherService` and the `collectionIds` property of the cipher.
*/
@Input() collections: CollectionView[];
@Input() collections?: CollectionView[];

/** Should be set to true when the component is used within the Admin Console */
@Input() isAdminConsole?: boolean = false;

organization$: Observable<Organization>;
folder$: Observable<FolderView>;
organization$: Observable<Organization | undefined> | undefined;
folder$: Observable<FolderView | undefined> | undefined;
private destroyed$: Subject<void> = new Subject();
cardIsExpired: boolean = false;

Expand All @@ -86,24 +84,38 @@ export class CipherViewComponent implements OnChanges, OnDestroy {
}

get hasCard() {
if (!this.cipher) {
return false;
}

const { cardholderName, code, expMonth, expYear, number } = this.cipher.card;
return cardholderName || code || expMonth || expYear || number;
}

get hasLogin() {
if (!this.cipher) {
return false;
}

const { username, password, totp } = this.cipher.login;
return username || password || totp;
}

get hasAutofill() {
return this.cipher.login?.uris.length > 0;
const uris = this.cipher?.login?.uris.length ?? 0;

return uris > 0;
}

get hasSshKey() {
return this.cipher.sshKey?.privateKey;
return !!this.cipher?.sshKey?.privateKey;
}

async loadCipherData() {
if (!this.cipher) {
return;
}

// Load collections if not provided and the cipher has collectionIds
if (
this.cipher.collectionIds &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { EventType } from "@bitwarden/common/enums";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
import {
CardComponent,
FormFieldModule,
SectionComponent,
SectionHeaderComponent,
Expand All @@ -37,7 +36,6 @@ type TotpCodeValues = {
imports: [
CommonModule,
JslibModule,
CardComponent,
SectionComponent,
SectionHeaderComponent,
TypographyModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { AfterViewInit, Component, ContentChildren, QueryList } from "@angular/core";

import { CardComponent, BitFormFieldComponent } from "@bitwarden/components";
Expand All @@ -14,14 +12,16 @@ import { CardComponent, BitFormFieldComponent } from "@bitwarden/components";
* A thin wrapper around the `bit-card` component that disables the bottom border for the last form field.
*/
export class ReadOnlyCipherCardComponent implements AfterViewInit {
@ContentChildren(BitFormFieldComponent) formFields: QueryList<BitFormFieldComponent>;
@ContentChildren(BitFormFieldComponent) formFields?: QueryList<BitFormFieldComponent>;

ngAfterViewInit(): void {
// Disable the bottom border for the last form field
if (this.formFields.last) {
if (this.formFields?.last) {
// Delay model update until next change detection cycle
setTimeout(() => {
this.formFields.last.disableReadOnlyBorder = true;
if (this.formFields) {
this.formFields.last.disableReadOnlyBorder = true;
}
});
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { NgIf } from "@angular/common";
import { Component, Input, OnInit } from "@angular/core";

import { JslibModule } from "@bitwarden/angular/jslib.module";
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
import {
CardComponent,
FormFieldModule,
IconButtonModule,
SectionComponent,
Expand All @@ -23,7 +20,6 @@ import { ReadOnlyCipherCardComponent } from "../read-only-cipher-card/read-only-
imports: [
NgIf,
JslibModule,
CardComponent,
SectionComponent,
SectionHeaderComponent,
TypographyModule,
Expand All @@ -33,11 +29,11 @@ import { ReadOnlyCipherCardComponent } from "../read-only-cipher-card/read-only-
],
})
export class ViewIdentitySectionsComponent implements OnInit {
@Input() cipher: CipherView;
@Input({ required: true }) cipher: CipherView | null = null;

showPersonalDetails: boolean;
showIdentificationDetails: boolean;
showContactDetails: boolean;
showPersonalDetails: boolean = false;
showIdentificationDetails: boolean = false;
showContactDetails: boolean = false;

ngOnInit(): void {
this.showPersonalDetails = this.hasPersonalDetails();
Expand All @@ -47,6 +43,10 @@ export class ViewIdentitySectionsComponent implements OnInit {

/** Returns all populated address fields */
get addressFields(): string {
if (!this.cipher) {
return "";
}

const { address1, address2, address3, fullAddressPart2, country } = this.cipher.identity;
return [address1, address2, address3, fullAddressPart2, country].filter(Boolean).join("\n");
}
Expand All @@ -58,18 +58,30 @@ export class ViewIdentitySectionsComponent implements OnInit {

/** Returns true when any of the "personal detail" attributes are populated */
private hasPersonalDetails(): boolean {
if (!this.cipher) {
return false;
}

const { username, company, fullName } = this.cipher.identity;
return Boolean(fullName || username || company);
}

/** Returns true when any of the "identification detail" attributes are populated */
private hasIdentificationDetails(): boolean {
if (!this.cipher) {
return false;
}

const { ssn, passportNumber, licenseNumber } = this.cipher.identity;
return Boolean(ssn || passportNumber || licenseNumber);
}

/** Returns true when any of the "contact detail" attributes are populated */
private hasContactDetails(): boolean {
if (!this.cipher) {
return false;
}

const { email, phone } = this.cipher.identity;

return Boolean(email || phone || this.addressFields);
Expand Down

0 comments on commit 6ad35e0

Please sign in to comment.