mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 08:43:33 +00:00
[PM-24677] Slim StateService down so it can be moved to state lib (#16021)
* Slim StateService down so it can be moved to state lib * Fix accidental import changes * Add `switchAccount` assertion * Needs to use mock
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
// FIXME: Update this file to be type safe and remove this and next line
|
||||
// @ts-strict-ignore
|
||||
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
|
||||
import { firstValueFrom, of, switchMap } from "rxjs";
|
||||
|
||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||
import { TokenService } from "@bitwarden/common/auth/abstractions/token.service";
|
||||
import {
|
||||
DefaultPasswordGenerationOptions,
|
||||
DefaultPassphraseGenerationOptions,
|
||||
@@ -17,7 +20,8 @@ import { CliUtils } from "../utils";
|
||||
export class GenerateCommand {
|
||||
constructor(
|
||||
private passwordGenerationService: PasswordGenerationServiceAbstraction,
|
||||
private stateService: StateService,
|
||||
private tokenService: TokenService,
|
||||
private accountService: AccountService,
|
||||
) {}
|
||||
|
||||
async run(cmdOptions: Record<string, any>): Promise<Response> {
|
||||
@@ -38,7 +42,18 @@ export class GenerateCommand {
|
||||
ambiguous: !normalizedOptions.ambiguous,
|
||||
};
|
||||
|
||||
const enforcedOptions = (await this.stateService.getIsAuthenticated())
|
||||
const shouldEnforceOptions = await firstValueFrom(
|
||||
this.accountService.activeAccount$.pipe(
|
||||
switchMap((account) => {
|
||||
if (account == null) {
|
||||
return of(false);
|
||||
}
|
||||
|
||||
return this.tokenService.hasAccessToken$(account.id);
|
||||
}),
|
||||
),
|
||||
);
|
||||
const enforcedOptions = shouldEnforceOptions
|
||||
? (await this.passwordGenerationService.enforcePasswordGeneratorPoliciesOnOptions(options))[0]
|
||||
: options;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user