1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-10 13:23:34 +00:00

[EC 784] Refactor organization user service (#4163)

* [EC-784] Introduce OrganizationUserService and abstraction

* [EC-784] Move API response models into abstraction folder

* [EC-784] Register OrganizationUserService in JsLib

* [EC-784] Add OrganizationUserService to CLI Main

* [EC-784] Move getOrganizationUser()

- Move getOrganizationUser() implementation to OrganizationUserService
- Update any references to the API service in the CLI and Web projects

* [EC-784] Move getOrganizationUserGroups()

* [EC-784] Move and rename getOrganizationUsers()

* [EC-784] Move getOrganizationUserResetPasswordDetails()

* [EC-784] Move OrganizationUser API request models into abstraction folder

* [EC-784] Move postOrganizationUserInvite()

* [EC-784] Move postOrganizationUserReinvite()

* [EC-784] Move postManyOrganizationUserReinvite()

Also tweak the signature to avoid exposing the API request model

* [EC-784] Move postOrganizationUserAccept()

* [EC-784] Move postOrganizationUserConfirm()

* [EC-784] Move postOrganizationUsersPublicKey()

Also modify signature to avoid exposing API request model

* [EC-784] Move postOrganizationUserBulkConfirm()

* [EC-784] Move putOrganizationUser()

* [EC-784] Move putOrganizationUserGroups()

* [EC-784] Update abstraction method definitions to use abstract keyword

* [EC-784] Move putOrganizationUserResetPasswordEnrollment()

* [EC-784] Move putOrganizationUserResetPassword()

* [EC-784] Move deleteOrganizationUser()

* [EC-784] Move deleteManyOrganizationUsers()

* [EC-784] Move revokeOrganizationUser()

* [EC-784] Move revokeManyOrganizationUsers()

* [EC-784] Move restoreOrganizationUser()

* [EC-784] Move restoreManyOrganizationUsers()

* [EC-784] Move internal OrganizationUserBulkRequest model out of service abstraction

* [EC-784] Rename organizationUser folder to organization-user
This commit is contained in:
Shane Melton
2022-12-19 10:56:16 -08:00
committed by GitHub
parent d18c32ab32
commit f67fffcc08
48 changed files with 764 additions and 511 deletions

View File

@@ -5,6 +5,7 @@ import * as program from "commander";
import * as jsdom from "jsdom";
import { InternalFolderService } from "@bitwarden/common/abstractions/folder/folder.service.abstraction";
import { OrganizationUserService } from "@bitwarden/common/abstractions/organization-user/organization-user.service";
import { OrganizationApiServiceAbstraction } from "@bitwarden/common/abstractions/organization/organization-api.service.abstraction";
import { ClientType } from "@bitwarden/common/enums/clientType";
import { KeySuffixOptions } from "@bitwarden/common/enums/keySuffixOptions";
@@ -30,6 +31,7 @@ import { ImportService } from "@bitwarden/common/services/import.service";
import { KeyConnectorService } from "@bitwarden/common/services/keyConnector.service";
import { MemoryStorageService } from "@bitwarden/common/services/memoryStorage.service";
import { NoopMessagingService } from "@bitwarden/common/services/noopMessaging.service";
import { OrganizationUserServiceImplementation } from "@bitwarden/common/services/organization-user/organization-user.service.implementation";
import { OrganizationApiService } from "@bitwarden/common/services/organization/organization-api.service";
import { OrganizationService } from "@bitwarden/common/services/organization/organization.service";
import { PasswordGenerationService } from "@bitwarden/common/services/passwordGeneration.service";
@@ -82,6 +84,7 @@ export class Main {
settingsService: SettingsService;
cipherService: CipherService;
folderService: InternalFolderService;
organizationUserService: OrganizationUserService;
collectionService: CollectionService;
vaultTimeoutService: VaultTimeoutService;
vaultTimeoutSettingsService: VaultTimeoutSettingsService;
@@ -242,6 +245,8 @@ export class Main {
this.organizationService = new OrganizationService(this.stateService);
this.organizationUserService = new OrganizationUserServiceImplementation(this.apiService);
this.policyService = new PolicyService(this.stateService, this.organizationService);
this.sendService = new SendService(

View File

@@ -1,12 +1,17 @@
import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { CryptoService } from "@bitwarden/common/abstractions/crypto.service";
import { OrganizationUserService } from "@bitwarden/common/abstractions/organization-user/organization-user.service";
import { OrganizationUserConfirmRequest } from "@bitwarden/common/abstractions/organization-user/requests";
import { Utils } from "@bitwarden/common/misc/utils";
import { OrganizationUserConfirmRequest } from "@bitwarden/common/models/request/organization-user-confirm.request";
import { Response } from "../models/response";
export class ConfirmCommand {
constructor(private apiService: ApiService, private cryptoService: CryptoService) {}
constructor(
private apiService: ApiService,
private cryptoService: CryptoService,
private organizationUserService: OrganizationUserService
) {}
async run(object: string, id: string, cmdOptions: Record<string, any>): Promise<Response> {
if (id != null) {
@@ -37,7 +42,10 @@ export class ConfirmCommand {
if (orgKey == null) {
throw new Error("No encryption key for this organization.");
}
const orgUser = await this.apiService.getOrganizationUser(options.organizationId, id);
const orgUser = await this.organizationUserService.getOrganizationUser(
options.organizationId,
id
);
if (orgUser == null) {
throw new Error("Member id does not exist for this organization.");
}
@@ -46,7 +54,11 @@ export class ConfirmCommand {
const key = await this.cryptoService.rsaEncrypt(orgKey.key, publicKey.buffer);
const req = new OrganizationUserConfirmRequest();
req.key = key.encryptedString;
await this.apiService.postOrganizationUserConfirm(options.organizationId, id, req);
await this.organizationUserService.postOrganizationUserConfirm(
options.organizationId,
id,
req
);
return Response.success();
} catch (e) {
return Response.error(e);

View File

@@ -2,6 +2,7 @@ import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { CipherService } from "@bitwarden/common/abstractions/cipher.service";
import { CollectionService } from "@bitwarden/common/abstractions/collection.service";
import { FolderService } from "@bitwarden/common/abstractions/folder/folder.service.abstraction";
import { OrganizationUserService } from "@bitwarden/common/abstractions/organization-user/organization-user.service";
import { OrganizationService } from "@bitwarden/common/abstractions/organization/organization.service.abstraction";
import { SearchService } from "@bitwarden/common/abstractions/search.service";
import { Utils } from "@bitwarden/common/misc/utils";
@@ -30,6 +31,7 @@ export class ListCommand {
private collectionService: CollectionService,
private organizationService: OrganizationService,
private searchService: SearchService,
private organizationUserService: OrganizationUserService,
private apiService: ApiService
) {}
@@ -202,7 +204,7 @@ export class ListCommand {
}
try {
const response = await this.apiService.getOrganizationUsers(options.organizationId);
const response = await this.organizationUserService.getAllUsers(options.organizationId);
const res = new ListResponse(
response.data.map((r) => {
const u = new OrganizationUserResponse();

View File

@@ -73,6 +73,7 @@ export class ServeCommand {
this.main.collectionService,
this.main.organizationService,
this.main.searchService,
this.main.organizationUserService,
this.main.apiService
);
this.createCommand = new CreateCommand(
@@ -108,7 +109,11 @@ export class ServeCommand {
this.main.apiService,
this.main.folderApiService
);
this.confirmCommand = new ConfirmCommand(this.main.apiService, this.main.cryptoService);
this.confirmCommand = new ConfirmCommand(
this.main.apiService,
this.main.cryptoService,
this.main.organizationUserService
);
this.restoreCommand = new RestoreCommand(this.main.cipherService);
this.shareCommand = new ShareCommand(this.main.cipherService);
this.lockCommand = new LockCommand(this.main.vaultTimeoutService);

View File

@@ -115,6 +115,7 @@ export class VaultProgram extends Program {
this.main.collectionService,
this.main.organizationService,
this.main.searchService,
this.main.organizationUserService,
this.main.apiService
);
const response = await command.run(object, cmd);
@@ -410,7 +411,11 @@ export class VaultProgram extends Program {
}
await this.exitIfLocked();
const command = new ConfirmCommand(this.main.apiService, this.main.cryptoService);
const command = new ConfirmCommand(
this.main.apiService,
this.main.cryptoService,
this.main.organizationUserService
);
const response = await command.run(object, id, cmd);
this.processResponse(response);
});