From ebeeb5cbb762fac75a203d32178ca0c93426f1ba Mon Sep 17 00:00:00 2001 From: Jared Snider Date: Thu, 25 May 2023 15:26:16 -0400 Subject: [PATCH] PM-1049 - Move newly created getDevices() method out of api.service into proper place in new devices-api.service. --- .../login-decryption-options.component.ts | 6 +++--- .../login-decryption-options.component.ts | 6 +++--- .../login-decryption-options.component.ts | 6 +++--- .../components/base-login-decryption-options.component.ts | 6 +++--- libs/common/src/abstractions/api.service.ts | 3 --- .../devices/devices-api.service.abstraction.ts | 4 ++++ libs/common/src/services/api.service.ts | 7 ------- .../services/devices/devices-api.service.implementation.ts | 6 ++++++ 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/apps/browser/src/auth/popup/login-decryption-options/login-decryption-options.component.ts b/apps/browser/src/auth/popup/login-decryption-options/login-decryption-options.component.ts index df24a4a361..08a0e839e0 100644 --- a/apps/browser/src/auth/popup/login-decryption-options/login-decryption-options.component.ts +++ b/apps/browser/src/auth/popup/login-decryption-options/login-decryption-options.component.ts @@ -2,7 +2,7 @@ import { Component } from "@angular/core"; import { FormBuilder } from "@angular/forms"; import { BaseLoginDecryptionOptionsComponent } from "@bitwarden/angular/auth/components/base-login-decryption-options.component"; -import { ApiService } from "@bitwarden/common/abstractions/api.service"; +import { DevicesApiServiceAbstraction } from "@bitwarden/common/abstractions/devices/devices-api.service.abstraction"; import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction"; import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction"; @@ -13,10 +13,10 @@ import { PolicyService } from "@bitwarden/common/admin-console/abstractions/poli export class LoginDecryptionOptionsComponent extends BaseLoginDecryptionOptionsComponent { constructor( formBuilder: FormBuilder, - apiService: ApiService, + devicesApiService: DevicesApiServiceAbstraction, organizationService: OrganizationService, policyService: PolicyService ) { - super(formBuilder, apiService, organizationService, policyService); + super(formBuilder, devicesApiService, organizationService, policyService); } } diff --git a/apps/desktop/src/auth/login/login-decryption-options/login-decryption-options.component.ts b/apps/desktop/src/auth/login/login-decryption-options/login-decryption-options.component.ts index cb661ee6f9..27180d5a85 100644 --- a/apps/desktop/src/auth/login/login-decryption-options/login-decryption-options.component.ts +++ b/apps/desktop/src/auth/login/login-decryption-options/login-decryption-options.component.ts @@ -2,7 +2,7 @@ import { Component } from "@angular/core"; import { FormBuilder } from "@angular/forms"; import { BaseLoginDecryptionOptionsComponent } from "@bitwarden/angular/auth/components/base-login-decryption-options.component"; -import { ApiService } from "@bitwarden/common/abstractions/api.service"; +import { DevicesApiServiceAbstraction } from "@bitwarden/common/abstractions/devices/devices-api.service.abstraction"; import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction"; import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction"; @@ -13,10 +13,10 @@ import { PolicyService } from "@bitwarden/common/admin-console/abstractions/poli export class LoginDecryptionOptionsComponent extends BaseLoginDecryptionOptionsComponent { constructor( formBuilder: FormBuilder, - apiService: ApiService, + devicesApiService: DevicesApiServiceAbstraction, organizationService: OrganizationService, policyService: PolicyService ) { - super(formBuilder, apiService, organizationService, policyService); + super(formBuilder, devicesApiService, organizationService, policyService); } } diff --git a/apps/web/src/app/auth/login/login-decryption-options/login-decryption-options.component.ts b/apps/web/src/app/auth/login/login-decryption-options/login-decryption-options.component.ts index db3e7cfe71..beade5bf0a 100644 --- a/apps/web/src/app/auth/login/login-decryption-options/login-decryption-options.component.ts +++ b/apps/web/src/app/auth/login/login-decryption-options/login-decryption-options.component.ts @@ -2,7 +2,7 @@ import { Component } from "@angular/core"; import { FormBuilder } from "@angular/forms"; import { BaseLoginDecryptionOptionsComponent } from "@bitwarden/angular/auth/components/base-login-decryption-options.component"; -import { ApiService } from "@bitwarden/common/abstractions/api.service"; +import { DevicesApiServiceAbstraction } from "@bitwarden/common/abstractions/devices/devices-api.service.abstraction"; import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction"; import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction"; @@ -13,10 +13,10 @@ import { PolicyService } from "@bitwarden/common/admin-console/abstractions/poli export class LoginDecryptionOptionsComponent extends BaseLoginDecryptionOptionsComponent { constructor( formBuilder: FormBuilder, - apiService: ApiService, + devicesApiService: DevicesApiServiceAbstraction, organizationService: OrganizationService, policyService: PolicyService ) { - super(formBuilder, apiService, organizationService, policyService); + super(formBuilder, devicesApiService, organizationService, policyService); } } diff --git a/libs/angular/src/auth/components/base-login-decryption-options.component.ts b/libs/angular/src/auth/components/base-login-decryption-options.component.ts index c6c9cbc96d..a49e96d097 100644 --- a/libs/angular/src/auth/components/base-login-decryption-options.component.ts +++ b/libs/angular/src/auth/components/base-login-decryption-options.component.ts @@ -2,7 +2,7 @@ import { Directive, OnDestroy, OnInit } from "@angular/core"; import { FormBuilder } from "@angular/forms"; import { Subject } from "rxjs"; -import { ApiService } from "@bitwarden/common/abstractions/api.service"; +import { DevicesApiServiceAbstraction } from "@bitwarden/common/abstractions/devices/devices-api.service.abstraction"; import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction"; import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction"; import { Policy } from "@bitwarden/common/admin-console/models/domain/policy"; @@ -27,7 +27,7 @@ export class BaseLoginDecryptionOptionsComponent implements OnInit, OnDestroy { constructor( protected formBuilder: FormBuilder, - protected apiService: ApiService, + protected devicesApiService: DevicesApiServiceAbstraction, protected organizationService: OrganizationService, protected policyService: PolicyService ) {} @@ -50,7 +50,7 @@ export class BaseLoginDecryptionOptionsComponent implements OnInit, OnDestroy { // Determine if the user has any mobile or desktop devices // to determine if we should show the approve from other device button - const devicesListResponse = await this.apiService.getDevices(); + const devicesListResponse = await this.devicesApiService.getDevices(); for (const device of devicesListResponse.data) { if ( device.type === DeviceType.Android || diff --git a/libs/common/src/abstractions/api.service.ts b/libs/common/src/abstractions/api.service.ts index 7cdb85f52d..2273b29019 100644 --- a/libs/common/src/abstractions/api.service.ts +++ b/libs/common/src/abstractions/api.service.ts @@ -70,7 +70,6 @@ import { UpdateTwoFactorYubioOtpRequest } from "../auth/models/request/update-tw import { ApiKeyResponse } from "../auth/models/response/api-key.response"; import { AuthRequestResponse } from "../auth/models/response/auth-request.response"; import { DeviceVerificationResponse } from "../auth/models/response/device-verification.response"; -import { DeviceResponse } from "../auth/models/response/device.response"; import { EmergencyAccessGranteeDetailsResponse, EmergencyAccessGrantorDetailsResponse, @@ -363,8 +362,6 @@ export abstract class ApiService { request: DeviceVerificationRequest ) => Promise; - getDevices: () => Promise>; - getEmergencyAccessTrusted: () => Promise>; getEmergencyAccessGranted: () => Promise>; getEmergencyAccess: (id: string) => Promise; diff --git a/libs/common/src/abstractions/devices/devices-api.service.abstraction.ts b/libs/common/src/abstractions/devices/devices-api.service.abstraction.ts index 345b728977..2a45ae2fb3 100644 --- a/libs/common/src/abstractions/devices/devices-api.service.abstraction.ts +++ b/libs/common/src/abstractions/devices/devices-api.service.abstraction.ts @@ -1,3 +1,5 @@ +import { ListResponse } from "../../models/response/list.response"; + import { DeviceResponse } from "./responses/device.response"; export abstract class DevicesApiServiceAbstraction { @@ -5,6 +7,8 @@ export abstract class DevicesApiServiceAbstraction { getDeviceByIdentifier: (deviceIdentifier: string) => Promise; + getDevices: () => Promise>; + updateTrustedDeviceKeys: ( deviceIdentifier: string, devicePublicKeyEncryptedUserSymKey: string, diff --git a/libs/common/src/services/api.service.ts b/libs/common/src/services/api.service.ts index bed78fb135..59e3755a04 100644 --- a/libs/common/src/services/api.service.ts +++ b/libs/common/src/services/api.service.ts @@ -77,7 +77,6 @@ import { UpdateTwoFactorYubioOtpRequest } from "../auth/models/request/update-tw import { ApiKeyResponse } from "../auth/models/response/api-key.response"; import { AuthRequestResponse } from "../auth/models/response/auth-request.response"; import { DeviceVerificationResponse } from "../auth/models/response/device-verification.response"; -import { DeviceResponse } from "../auth/models/response/device.response"; import { EmergencyAccessGranteeDetailsResponse, EmergencyAccessGrantorDetailsResponse, @@ -1111,12 +1110,6 @@ export class ApiService implements ApiServiceAbstraction { return new DeviceVerificationResponse(r); } - // TODO: move this method to new devices-api.service once it's merged to master - async getDevices(): Promise> { - const r = await this.send("GET", "/devices", null, true, true, null); - return new ListResponse(r, DeviceResponse); - } - // Emergency Access APIs async getEmergencyAccessTrusted(): Promise> { diff --git a/libs/common/src/services/devices/devices-api.service.implementation.ts b/libs/common/src/services/devices/devices-api.service.implementation.ts index aa0d0f0c29..8747e5b4f8 100644 --- a/libs/common/src/services/devices/devices-api.service.implementation.ts +++ b/libs/common/src/services/devices/devices-api.service.implementation.ts @@ -1,6 +1,7 @@ import { DevicesApiServiceAbstraction } from "../../abstractions/devices/devices-api.service.abstraction"; import { DeviceResponse } from "../../abstractions/devices/responses/device.response"; import { Utils } from "../../misc/utils"; +import { ListResponse } from "../../models/response/list.response"; import { ApiService } from "../api.service"; import { TrustedDeviceKeysRequest } from "./requests/trusted-device-keys.request"; @@ -39,6 +40,11 @@ export class DevicesApiServiceImplementation implements DevicesApiServiceAbstrac return new DeviceResponse(r); } + async getDevices(): Promise> { + const r = await this.apiService.send("GET", "/devices", null, true, true, null); + return new ListResponse(r, DeviceResponse); + } + async updateTrustedDeviceKeys( deviceIdentifier: string, devicePublicKeyEncryptedUserSymKey: string,