mirror of
https://github.com/bitwarden/cli
synced 2025-12-16 00:03:23 +00:00
[refactor] Replace references to deprecated services
Several refactors were done on the data storage layer of jslib to support Account Switching for desktop. These changes have been implemented here for parity across clients, improved readability, and to make it easier to add Account Switching to other clients later if desired. * The UserService was removed, and so all references have been replaced with the new access points for that data (activeAccount and organizationService most often) * The StorageService is now considered a "global" scope, where as we have a new "account" scope to consider. Any "account" scope storage items I have moved to saving with an ActiveAccountService instance instead of a StorageService instance. * ConstantsServices have been removed and replaced with a StorageKey enum that holds keys that were in ConstantServices and in other feature scoped services.
This commit is contained in:
@@ -2,17 +2,16 @@ import * as program from 'commander';
|
||||
|
||||
import { CipherType } from 'jslib-common/enums/cipherType';
|
||||
|
||||
import { ActiveAccountService } from 'jslib-common/abstractions/activeAccount.service';
|
||||
import { ApiService } from 'jslib-common/abstractions/api.service';
|
||||
import { AuditService } from 'jslib-common/abstractions/audit.service';
|
||||
import { CipherService } from 'jslib-common/abstractions/cipher.service';
|
||||
import { CollectionService } from 'jslib-common/abstractions/collection.service';
|
||||
import { CryptoService } from 'jslib-common/abstractions/crypto.service';
|
||||
import { EnvironmentService } from 'jslib-common/abstractions/environment.service';
|
||||
import { FolderService } from 'jslib-common/abstractions/folder.service';
|
||||
import { OrganizationService } from 'jslib-common/abstractions/organization.service';
|
||||
import { SearchService } from 'jslib-common/abstractions/search.service';
|
||||
import { SendService } from 'jslib-common/abstractions/send.service';
|
||||
import { TotpService } from 'jslib-common/abstractions/totp.service';
|
||||
import { UserService } from 'jslib-common/abstractions/user.service';
|
||||
|
||||
import { Organization } from 'jslib-common/models/domain/organization';
|
||||
|
||||
@@ -60,9 +59,8 @@ export class GetCommand extends DownloadCommand {
|
||||
constructor(private cipherService: CipherService, private folderService: FolderService,
|
||||
private collectionService: CollectionService, private totpService: TotpService,
|
||||
private auditService: AuditService, cryptoService: CryptoService,
|
||||
private userService: UserService, private searchService: SearchService,
|
||||
private apiService: ApiService, private sendService: SendService,
|
||||
private environmentService: EnvironmentService) {
|
||||
private activeAccount: ActiveAccountService, private searchService: SearchService,
|
||||
private apiService: ApiService, private organizationService: OrganizationService) {
|
||||
super(cryptoService);
|
||||
}
|
||||
|
||||
@@ -228,7 +226,7 @@ export class GetCommand extends DownloadCommand {
|
||||
return Response.error('Couldn\'t generate TOTP code.');
|
||||
}
|
||||
|
||||
const canAccessPremium = await this.userService.canAccessPremium();
|
||||
const canAccessPremium = this.activeAccount.canAccessPremium;
|
||||
if (!canAccessPremium) {
|
||||
const originalCipher = await this.cipherService.get(cipher.id);
|
||||
if (originalCipher == null || originalCipher.organizationId == null ||
|
||||
@@ -299,7 +297,7 @@ export class GetCommand extends DownloadCommand {
|
||||
return Response.multipleResults(attachments.map(a => a.id));
|
||||
}
|
||||
|
||||
if (!(await this.userService.canAccessPremium())) {
|
||||
if (!this.activeAccount.canAccessPremium) {
|
||||
const originalCipher = await this.cipherService.get(cipher.id);
|
||||
if (originalCipher == null || originalCipher.organizationId == null) {
|
||||
return Response.error('Premium status is required to use this feature.');
|
||||
@@ -407,9 +405,9 @@ export class GetCommand extends DownloadCommand {
|
||||
private async getOrganization(id: string) {
|
||||
let org: Organization = null;
|
||||
if (Utils.isGuid(id)) {
|
||||
org = await this.userService.getOrganization(id);
|
||||
org = await this.organizationService.get(id);
|
||||
} else if (id.trim() !== '') {
|
||||
let orgs = await this.userService.getAllOrganizations();
|
||||
let orgs = await this.organizationService.getAll();
|
||||
orgs = CliUtils.searchOrganizations(orgs, id);
|
||||
if (orgs.length > 1) {
|
||||
return Response.multipleResults(orgs.map(c => c.id));
|
||||
@@ -479,7 +477,7 @@ export class GetCommand extends DownloadCommand {
|
||||
private async getFingerprint(id: string) {
|
||||
let fingerprint: string[] = null;
|
||||
if (id === 'me') {
|
||||
fingerprint = await this.cryptoService.getFingerprint(await this.userService.getUserId());
|
||||
fingerprint = await this.cryptoService.getFingerprint(this.activeAccount.userId);
|
||||
} else if (Utils.isGuid(id)) {
|
||||
try {
|
||||
const response = await this.apiService.getUserPublicKey(id);
|
||||
|
||||
Reference in New Issue
Block a user