[PM-3050] Add sync on unlock, logout when account is deleted (#9288)
* Add sync on unlock, logout when account is deleted * Update libs/common/src/vault/services/sync/sync.service.ts Co-authored-by: SmithThe4th <gsmith@bitwarden.com> * Fix failing unit tests * Fix incorrect merge --------- Co-authored-by: SmithThe4th <gsmith@bitwarden.com>
This commit is contained in:
parent
6d0ef65094
commit
f6942dde74
|
@ -25,6 +25,7 @@ import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/pl
|
||||||
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
|
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
|
||||||
import { BiometricStateService } from "@bitwarden/common/platform/biometrics/biometric-state.service";
|
import { BiometricStateService } from "@bitwarden/common/platform/biometrics/biometric-state.service";
|
||||||
import { PasswordStrengthServiceAbstraction } from "@bitwarden/common/tools/password-strength";
|
import { PasswordStrengthServiceAbstraction } from "@bitwarden/common/tools/password-strength";
|
||||||
|
import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction";
|
||||||
import { DialogService } from "@bitwarden/components";
|
import { DialogService } from "@bitwarden/components";
|
||||||
|
|
||||||
import { BiometricErrors, BiometricErrorTypes } from "../../models/biometricErrors";
|
import { BiometricErrors, BiometricErrorTypes } from "../../models/biometricErrors";
|
||||||
|
@ -68,6 +69,7 @@ export class LockComponent extends BaseLockComponent {
|
||||||
biometricStateService: BiometricStateService,
|
biometricStateService: BiometricStateService,
|
||||||
accountService: AccountService,
|
accountService: AccountService,
|
||||||
kdfConfigService: KdfConfigService,
|
kdfConfigService: KdfConfigService,
|
||||||
|
syncService: SyncService,
|
||||||
) {
|
) {
|
||||||
super(
|
super(
|
||||||
masterPasswordService,
|
masterPasswordService,
|
||||||
|
@ -94,6 +96,7 @@ export class LockComponent extends BaseLockComponent {
|
||||||
accountService,
|
accountService,
|
||||||
authService,
|
authService,
|
||||||
kdfConfigService,
|
kdfConfigService,
|
||||||
|
syncService,
|
||||||
);
|
);
|
||||||
this.successRoute = "/tabs/current";
|
this.successRoute = "/tabs/current";
|
||||||
this.isInitialLockScreen = (window as any).previousPopupUrl == null;
|
this.isInitialLockScreen = (window as any).previousPopupUrl == null;
|
||||||
|
|
|
@ -32,6 +32,7 @@ import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||||
import { FakeAccountService, mockAccountServiceWith } from "@bitwarden/common/spec";
|
import { FakeAccountService, mockAccountServiceWith } from "@bitwarden/common/spec";
|
||||||
import { PasswordStrengthServiceAbstraction } from "@bitwarden/common/tools/password-strength";
|
import { PasswordStrengthServiceAbstraction } from "@bitwarden/common/tools/password-strength";
|
||||||
import { UserId } from "@bitwarden/common/types/guid";
|
import { UserId } from "@bitwarden/common/types/guid";
|
||||||
|
import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction";
|
||||||
import { DialogService } from "@bitwarden/components";
|
import { DialogService } from "@bitwarden/components";
|
||||||
|
|
||||||
import { LockComponent } from "./lock.component";
|
import { LockComponent } from "./lock.component";
|
||||||
|
@ -174,6 +175,10 @@ describe("LockComponent", () => {
|
||||||
provide: KdfConfigService,
|
provide: KdfConfigService,
|
||||||
useValue: mock<KdfConfigService>(),
|
useValue: mock<KdfConfigService>(),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
provide: SyncService,
|
||||||
|
useValue: mock<SyncService>(),
|
||||||
|
},
|
||||||
],
|
],
|
||||||
schemas: [NO_ERRORS_SCHEMA],
|
schemas: [NO_ERRORS_SCHEMA],
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
|
|
|
@ -26,6 +26,7 @@ import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/pl
|
||||||
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
|
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
|
||||||
import { BiometricStateService } from "@bitwarden/common/platform/biometrics/biometric-state.service";
|
import { BiometricStateService } from "@bitwarden/common/platform/biometrics/biometric-state.service";
|
||||||
import { PasswordStrengthServiceAbstraction } from "@bitwarden/common/tools/password-strength";
|
import { PasswordStrengthServiceAbstraction } from "@bitwarden/common/tools/password-strength";
|
||||||
|
import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction";
|
||||||
import { DialogService } from "@bitwarden/components";
|
import { DialogService } from "@bitwarden/components";
|
||||||
|
|
||||||
const BroadcasterSubscriptionId = "LockComponent";
|
const BroadcasterSubscriptionId = "LockComponent";
|
||||||
|
@ -67,6 +68,7 @@ export class LockComponent extends BaseLockComponent {
|
||||||
accountService: AccountService,
|
accountService: AccountService,
|
||||||
authService: AuthService,
|
authService: AuthService,
|
||||||
kdfConfigService: KdfConfigService,
|
kdfConfigService: KdfConfigService,
|
||||||
|
syncService: SyncService,
|
||||||
) {
|
) {
|
||||||
super(
|
super(
|
||||||
masterPasswordService,
|
masterPasswordService,
|
||||||
|
@ -93,6 +95,7 @@ export class LockComponent extends BaseLockComponent {
|
||||||
accountService,
|
accountService,
|
||||||
authService,
|
authService,
|
||||||
kdfConfigService,
|
kdfConfigService,
|
||||||
|
syncService,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ import { HashPurpose, KeySuffixOptions } from "@bitwarden/common/platform/enums"
|
||||||
import { PasswordStrengthServiceAbstraction } from "@bitwarden/common/tools/password-strength";
|
import { PasswordStrengthServiceAbstraction } from "@bitwarden/common/tools/password-strength";
|
||||||
import { UserId } from "@bitwarden/common/types/guid";
|
import { UserId } from "@bitwarden/common/types/guid";
|
||||||
import { UserKey } from "@bitwarden/common/types/key";
|
import { UserKey } from "@bitwarden/common/types/key";
|
||||||
|
import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction";
|
||||||
import { DialogService } from "@bitwarden/components";
|
import { DialogService } from "@bitwarden/components";
|
||||||
|
|
||||||
@Directive()
|
@Directive()
|
||||||
|
@ -85,6 +86,7 @@ export class LockComponent implements OnInit, OnDestroy {
|
||||||
protected accountService: AccountService,
|
protected accountService: AccountService,
|
||||||
protected authService: AuthService,
|
protected authService: AuthService,
|
||||||
protected kdfConfigService: KdfConfigService,
|
protected kdfConfigService: KdfConfigService,
|
||||||
|
protected syncService: SyncService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async ngOnInit() {
|
async ngOnInit() {
|
||||||
|
@ -318,6 +320,9 @@ export class LockComponent implements OnInit, OnDestroy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Vault can be de-synced since notifications get ignored while locked. Need to check whether sync is required using the sync service.
|
||||||
|
await this.syncService.fullSync(false);
|
||||||
|
|
||||||
if (this.onSuccessfulSubmit != null) {
|
if (this.onSuccessfulSubmit != null) {
|
||||||
await this.onSuccessfulSubmit();
|
await this.onSuccessfulSubmit();
|
||||||
} else if (this.router != null) {
|
} else if (this.router != null) {
|
||||||
|
|
|
@ -145,6 +145,11 @@ export class SyncService extends CoreSyncService {
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await this.apiService.getAccountRevisionDate();
|
const response = await this.apiService.getAccountRevisionDate();
|
||||||
|
if (response < 0 && this.logoutCallback) {
|
||||||
|
// Account was deleted, log out now
|
||||||
|
await this.logoutCallback(false);
|
||||||
|
}
|
||||||
|
|
||||||
if (new Date(response) <= lastSync) {
|
if (new Date(response) <= lastSync) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue