diff --git a/apps/browser/src/popup/accounts/set-password.component.ts b/apps/browser/src/popup/accounts/set-password.component.ts index a9d16d7305..25732b0714 100644 --- a/apps/browser/src/popup/accounts/set-password.component.ts +++ b/apps/browser/src/popup/accounts/set-password.component.ts @@ -6,6 +6,7 @@ import { ApiService } from "@bitwarden/common/abstractions/api.service"; import { CryptoService } from "@bitwarden/common/abstractions/crypto.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { MessagingService } from "@bitwarden/common/abstractions/messaging.service"; +import { OrganizationUserService } from "@bitwarden/common/abstractions/organization-user/organization-user.service"; import { OrganizationApiServiceAbstraction } from "@bitwarden/common/abstractions/organization/organization-api.service.abstraction"; import { PasswordGenerationService } from "@bitwarden/common/abstractions/passwordGeneration.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; @@ -32,7 +33,8 @@ export class SetPasswordComponent extends BaseSetPasswordComponent { router: Router, syncService: SyncService, route: ActivatedRoute, - organizationApiService: OrganizationApiServiceAbstraction + organizationApiService: OrganizationApiServiceAbstraction, + organizationUserService: OrganizationUserService ) { super( i18nService, @@ -47,7 +49,8 @@ export class SetPasswordComponent extends BaseSetPasswordComponent { syncService, route, stateService, - organizationApiService + organizationApiService, + organizationUserService ); } } diff --git a/apps/cli/src/bw.ts b/apps/cli/src/bw.ts index 1cb03db67b..4395d935ce 100644 --- a/apps/cli/src/bw.ts +++ b/apps/cli/src/bw.ts @@ -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( diff --git a/apps/cli/src/commands/confirm.command.ts b/apps/cli/src/commands/confirm.command.ts index 824bd5c8e8..6249fb4c2d 100644 --- a/apps/cli/src/commands/confirm.command.ts +++ b/apps/cli/src/commands/confirm.command.ts @@ -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): Promise { 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); diff --git a/apps/cli/src/commands/list.command.ts b/apps/cli/src/commands/list.command.ts index cc40c5bc79..7f7793620f 100644 --- a/apps/cli/src/commands/list.command.ts +++ b/apps/cli/src/commands/list.command.ts @@ -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(); diff --git a/apps/cli/src/commands/serve.command.ts b/apps/cli/src/commands/serve.command.ts index ddba5acbb7..6b5dd97f03 100644 --- a/apps/cli/src/commands/serve.command.ts +++ b/apps/cli/src/commands/serve.command.ts @@ -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); diff --git a/apps/cli/src/vault.program.ts b/apps/cli/src/vault.program.ts index a3edf1a913..4fe87a737a 100644 --- a/apps/cli/src/vault.program.ts +++ b/apps/cli/src/vault.program.ts @@ -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); }); diff --git a/apps/desktop/src/app/accounts/set-password.component.ts b/apps/desktop/src/app/accounts/set-password.component.ts index ca82aaed5e..fd9d41a6ac 100644 --- a/apps/desktop/src/app/accounts/set-password.component.ts +++ b/apps/desktop/src/app/accounts/set-password.component.ts @@ -7,6 +7,7 @@ import { BroadcasterService } from "@bitwarden/common/abstractions/broadcaster.s import { CryptoService } from "@bitwarden/common/abstractions/crypto.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { MessagingService } from "@bitwarden/common/abstractions/messaging.service"; +import { OrganizationUserService } from "@bitwarden/common/abstractions/organization-user/organization-user.service"; import { OrganizationApiServiceAbstraction } from "@bitwarden/common/abstractions/organization/organization-api.service.abstraction"; import { PasswordGenerationService } from "@bitwarden/common/abstractions/passwordGeneration.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; @@ -37,7 +38,8 @@ export class SetPasswordComponent extends BaseSetPasswordComponent implements On private broadcasterService: BroadcasterService, private ngZone: NgZone, stateService: StateService, - organizationApiService: OrganizationApiServiceAbstraction + organizationApiService: OrganizationApiServiceAbstraction, + organizationUserService: OrganizationUserService ) { super( i18nService, @@ -52,7 +54,8 @@ export class SetPasswordComponent extends BaseSetPasswordComponent implements On syncService, route, stateService, - organizationApiService + organizationApiService, + organizationUserService ); } diff --git a/apps/web/src/app/accounts/accept-organization.component.ts b/apps/web/src/app/accounts/accept-organization.component.ts index be3826fe18..ab6157a32f 100644 --- a/apps/web/src/app/accounts/accept-organization.component.ts +++ b/apps/web/src/app/accounts/accept-organization.component.ts @@ -5,6 +5,8 @@ import { ApiService } from "@bitwarden/common/abstractions/api.service"; import { CryptoService } from "@bitwarden/common/abstractions/crypto.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/abstractions/log.service"; +import { OrganizationUserService } from "@bitwarden/common/abstractions/organization-user/organization-user.service"; +import { OrganizationUserAcceptRequest } from "@bitwarden/common/abstractions/organization-user/requests"; import { OrganizationApiServiceAbstraction } from "@bitwarden/common/abstractions/organization/organization-api.service.abstraction"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { PolicyApiServiceAbstraction } from "@bitwarden/common/abstractions/policy/policy-api.service.abstraction"; @@ -12,7 +14,6 @@ import { PolicyService } from "@bitwarden/common/abstractions/policy/policy.serv import { StateService } from "@bitwarden/common/abstractions/state.service"; import { Utils } from "@bitwarden/common/misc/utils"; import { Policy } from "@bitwarden/common/models/domain/policy"; -import { OrganizationUserAcceptRequest } from "@bitwarden/common/models/request/organization-user-accept.request"; import { BaseAcceptComponent } from "../common/base.accept.component"; @@ -36,14 +37,15 @@ export class AcceptOrganizationComponent extends BaseAcceptComponent { private policyApiService: PolicyApiServiceAbstraction, private policyService: PolicyService, private logService: LogService, - private organizationApiService: OrganizationApiServiceAbstraction + private organizationApiService: OrganizationApiServiceAbstraction, + private organizationUserService: OrganizationUserService ) { super(router, platformUtilsService, i18nService, route, stateService); } async authedHandler(qParams: Params): Promise { this.actionPromise = this.prepareAcceptRequest(qParams).then(async (request) => { - await this.apiService.postOrganizationUserAccept( + await this.organizationUserService.postOrganizationUserAccept( qParams.organizationId, qParams.organizationUserId, request diff --git a/apps/web/src/app/accounts/set-password.component.ts b/apps/web/src/app/accounts/set-password.component.ts index 7e33731412..2e6deb2f5f 100644 --- a/apps/web/src/app/accounts/set-password.component.ts +++ b/apps/web/src/app/accounts/set-password.component.ts @@ -6,6 +6,7 @@ import { ApiService } from "@bitwarden/common/abstractions/api.service"; import { CryptoService } from "@bitwarden/common/abstractions/crypto.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { MessagingService } from "@bitwarden/common/abstractions/messaging.service"; +import { OrganizationUserService } from "@bitwarden/common/abstractions/organization-user/organization-user.service"; import { OrganizationApiServiceAbstraction } from "@bitwarden/common/abstractions/organization/organization-api.service.abstraction"; import { PasswordGenerationService } from "@bitwarden/common/abstractions/passwordGeneration.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; @@ -32,7 +33,8 @@ export class SetPasswordComponent extends BaseSetPasswordComponent { syncService: SyncService, route: ActivatedRoute, stateService: StateService, - organizationApiService: OrganizationApiServiceAbstraction + organizationApiService: OrganizationApiServiceAbstraction, + organizationUserService: OrganizationUserService ) { super( i18nService, @@ -47,7 +49,8 @@ export class SetPasswordComponent extends BaseSetPasswordComponent { syncService, route, stateService, - organizationApiService + organizationApiService, + organizationUserService ); } } diff --git a/apps/web/src/app/common/base.people.component.ts b/apps/web/src/app/common/base.people.component.ts index c3ee6bb209..4f2e1937e7 100644 --- a/apps/web/src/app/common/base.people.component.ts +++ b/apps/web/src/app/common/base.people.component.ts @@ -7,6 +7,7 @@ import { ApiService } from "@bitwarden/common/abstractions/api.service"; import { CryptoService } from "@bitwarden/common/abstractions/crypto.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/abstractions/log.service"; +import { OrganizationUserUserDetailsResponse } from "@bitwarden/common/abstractions/organization-user/responses"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { SearchService } from "@bitwarden/common/abstractions/search.service"; import { StateService } from "@bitwarden/common/abstractions/state.service"; @@ -17,7 +18,6 @@ import { ProviderUserStatusType } from "@bitwarden/common/enums/providerUserStat import { ProviderUserType } from "@bitwarden/common/enums/providerUserType"; import { Utils } from "@bitwarden/common/misc/utils"; import { ListResponse } from "@bitwarden/common/models/response/list.response"; -import { OrganizationUserUserDetailsResponse } from "@bitwarden/common/models/response/organization-user.response"; import { ProviderUserUserDetailsResponse } from "@bitwarden/common/models/response/provider/provider-user.response"; import { UserConfirmComponent } from "../organizations/manage/user-confirm.component"; diff --git a/apps/web/src/app/organizations/manage/bulk/bulk-confirm.component.ts b/apps/web/src/app/organizations/manage/bulk/bulk-confirm.component.ts index dc54300f6f..30813be02d 100644 --- a/apps/web/src/app/organizations/manage/bulk/bulk-confirm.component.ts +++ b/apps/web/src/app/organizations/manage/bulk/bulk-confirm.component.ts @@ -3,10 +3,10 @@ import { Component, Input, OnInit } from "@angular/core"; import { ApiService } from "@bitwarden/common/abstractions/api.service"; import { CryptoService } from "@bitwarden/common/abstractions/crypto.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; +import { OrganizationUserService } from "@bitwarden/common/abstractions/organization-user/organization-user.service"; +import { OrganizationUserBulkConfirmRequest } from "@bitwarden/common/abstractions/organization-user/requests"; import { OrganizationUserStatusType } from "@bitwarden/common/enums/organizationUserStatusType"; import { Utils } from "@bitwarden/common/misc/utils"; -import { OrganizationUserBulkConfirmRequest } from "@bitwarden/common/models/request/organization-user-bulk-confirm.request"; -import { OrganizationUserBulkRequest } from "@bitwarden/common/models/request/organization-user-bulk.request"; import { BulkUserDetails } from "./bulk-status.component"; @@ -31,6 +31,7 @@ export class BulkConfirmComponent implements OnInit { constructor( protected cryptoService: CryptoService, protected apiService: ApiService, + private organizationUserService: OrganizationUserService, private i18nService: I18nService ) {} @@ -91,8 +92,10 @@ export class BulkConfirmComponent implements OnInit { } protected async getPublicKeys() { - const request = new OrganizationUserBulkRequest(this.filteredUsers.map((user) => user.id)); - return await this.apiService.postOrganizationUsersPublicKey(this.organizationId, request); + return await this.organizationUserService.postOrganizationUsersPublicKey( + this.organizationId, + this.filteredUsers.map((user) => user.id) + ); } protected getCryptoKey() { @@ -101,6 +104,9 @@ export class BulkConfirmComponent implements OnInit { protected async postConfirmRequest(userIdsWithKeys: any[]) { const request = new OrganizationUserBulkConfirmRequest(userIdsWithKeys); - return await this.apiService.postOrganizationUserBulkConfirm(this.organizationId, request); + return await this.organizationUserService.postOrganizationUserBulkConfirm( + this.organizationId, + request + ); } } diff --git a/apps/web/src/app/organizations/manage/bulk/bulk-remove.component.ts b/apps/web/src/app/organizations/manage/bulk/bulk-remove.component.ts index 6a73de05df..792be72920 100644 --- a/apps/web/src/app/organizations/manage/bulk/bulk-remove.component.ts +++ b/apps/web/src/app/organizations/manage/bulk/bulk-remove.component.ts @@ -2,7 +2,7 @@ import { Component, Input } from "@angular/core"; import { ApiService } from "@bitwarden/common/abstractions/api.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; -import { OrganizationUserBulkRequest } from "@bitwarden/common/models/request/organization-user-bulk.request"; +import { OrganizationUserService } from "@bitwarden/common/abstractions/organization-user/organization-user.service"; import { BulkUserDetails } from "./bulk-status.component"; @@ -20,7 +20,11 @@ export class BulkRemoveComponent { done = false; error: string; - constructor(protected apiService: ApiService, protected i18nService: I18nService) {} + constructor( + protected apiService: ApiService, + protected i18nService: I18nService, + private organizationUserService: OrganizationUserService + ) {} async submit() { this.loading = true; @@ -40,8 +44,10 @@ export class BulkRemoveComponent { } protected async deleteUsers() { - const request = new OrganizationUserBulkRequest(this.users.map((user) => user.id)); - return await this.apiService.deleteManyOrganizationUsers(this.organizationId, request); + return await this.organizationUserService.deleteManyOrganizationUsers( + this.organizationId, + this.users.map((user) => user.id) + ); } protected get removeUsersWarning() { diff --git a/apps/web/src/app/organizations/manage/bulk/bulk-restore-revoke.component.ts b/apps/web/src/app/organizations/manage/bulk/bulk-restore-revoke.component.ts index 7f12111d60..b039db7878 100644 --- a/apps/web/src/app/organizations/manage/bulk/bulk-restore-revoke.component.ts +++ b/apps/web/src/app/organizations/manage/bulk/bulk-restore-revoke.component.ts @@ -1,9 +1,8 @@ import { Component } from "@angular/core"; import { ModalConfig } from "@bitwarden/angular/services/modal.service"; -import { ApiService } from "@bitwarden/common/abstractions/api.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; -import { OrganizationUserBulkRequest } from "@bitwarden/common/models/request/organization-user-bulk.request"; +import { OrganizationUserService } from "@bitwarden/common/abstractions/organization-user/organization-user.service"; import { BulkUserDetails } from "./bulk-status.component"; @@ -23,8 +22,8 @@ export class BulkRestoreRevokeComponent { error: string; constructor( - protected apiService: ApiService, protected i18nService: I18nService, + private organizationUserService: OrganizationUserService, config: ModalConfig ) { this.isRevoking = config.data.isRevoking; @@ -56,11 +55,17 @@ export class BulkRestoreRevokeComponent { } protected async performBulkUserAction() { - const request = new OrganizationUserBulkRequest(this.users.map((user) => user.id)); + const userIds = this.users.map((user) => user.id); if (this.isRevoking) { - return await this.apiService.revokeManyOrganizationUsers(this.organizationId, request); + return await this.organizationUserService.revokeManyOrganizationUsers( + this.organizationId, + userIds + ); } else { - return await this.apiService.restoreManyOrganizationUsers(this.organizationId, request); + return await this.organizationUserService.restoreManyOrganizationUsers( + this.organizationId, + userIds + ); } } } diff --git a/apps/web/src/app/organizations/manage/entity-events.component.ts b/apps/web/src/app/organizations/manage/entity-events.component.ts index 0eac612cd0..31e92d336e 100644 --- a/apps/web/src/app/organizations/manage/entity-events.component.ts +++ b/apps/web/src/app/organizations/manage/entity-events.component.ts @@ -4,6 +4,7 @@ import { UserNamePipe } from "@bitwarden/angular/pipes/user-name.pipe"; import { ApiService } from "@bitwarden/common/abstractions/api.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/abstractions/log.service"; +import { OrganizationUserService } from "@bitwarden/common/abstractions/organization-user/organization-user.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { EventResponse } from "@bitwarden/common/models/response/event.response"; import { ListResponse } from "@bitwarden/common/models/response/list.response"; @@ -40,7 +41,8 @@ export class EntityEventsComponent implements OnInit { private eventService: EventService, private platformUtilsService: PlatformUtilsService, private userNamePipe: UserNamePipe, - private logService: LogService + private logService: LogService, + private organizationUserService: OrganizationUserService ) {} async ngOnInit() { @@ -52,7 +54,7 @@ export class EntityEventsComponent implements OnInit { async load() { if (this.showUser) { - const response = await this.apiService.getOrganizationUsers(this.organizationId); + const response = await this.organizationUserService.getAllUsers(this.organizationId); response.data.forEach((u) => { const name = this.userNamePipe.transform(u); this.orgUsersIdMap.set(u.id, { name: name, email: u.email }); diff --git a/apps/web/src/app/organizations/manage/entity-users.component.ts b/apps/web/src/app/organizations/manage/entity-users.component.ts index f2e443bce5..28e38e266b 100644 --- a/apps/web/src/app/organizations/manage/entity-users.component.ts +++ b/apps/web/src/app/organizations/manage/entity-users.component.ts @@ -4,12 +4,13 @@ import { SearchPipe } from "@bitwarden/angular/pipes/search.pipe"; import { ApiService } from "@bitwarden/common/abstractions/api.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/abstractions/log.service"; +import { OrganizationUserService } from "@bitwarden/common/abstractions/organization-user/organization-user.service"; +import { OrganizationUserUserDetailsResponse } from "@bitwarden/common/abstractions/organization-user/responses"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { OrganizationUserStatusType } from "@bitwarden/common/enums/organizationUserStatusType"; import { OrganizationUserType } from "@bitwarden/common/enums/organizationUserType"; import { Utils } from "@bitwarden/common/misc/utils"; import { SelectionReadOnlyRequest } from "@bitwarden/common/models/request/selection-read-only.request"; -import { OrganizationUserUserDetailsResponse } from "@bitwarden/common/models/response/organization-user.response"; @Component({ selector: "app-entity-users", @@ -39,6 +40,7 @@ export class EntityUsersComponent implements OnInit { private apiService: ApiService, private i18nService: I18nService, private platformUtilsService: PlatformUtilsService, + private organizationUserService: OrganizationUserService, private logService: LogService ) {} @@ -64,7 +66,7 @@ export class EntityUsersComponent implements OnInit { } async loadUsers() { - const users = await this.apiService.getOrganizationUsers(this.organizationId); + const users = await this.organizationUserService.getAllUsers(this.organizationId); this.allUsers = users.data.map((r) => r).sort(Utils.getSortFunction(this.i18nService, "email")); if (this.entity === "group") { const response = await this.apiService.getGroupUsers(this.organizationId, this.entityId); diff --git a/apps/web/src/app/organizations/manage/events.component.ts b/apps/web/src/app/organizations/manage/events.component.ts index dd31169914..3104bed759 100644 --- a/apps/web/src/app/organizations/manage/events.component.ts +++ b/apps/web/src/app/organizations/manage/events.component.ts @@ -8,6 +8,7 @@ import { ExportService } from "@bitwarden/common/abstractions/export.service"; import { FileDownloadService } from "@bitwarden/common/abstractions/fileDownload/fileDownload.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/abstractions/log.service"; +import { OrganizationUserService } from "@bitwarden/common/abstractions/organization-user/organization-user.service"; import { OrganizationService } from "@bitwarden/common/abstractions/organization/organization.service.abstraction"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { ProviderService } from "@bitwarden/common/abstractions/provider.service"; @@ -41,6 +42,7 @@ export class EventsComponent extends BaseEventsComponent implements OnInit, OnDe logService: LogService, private userNamePipe: UserNamePipe, private organizationService: OrganizationService, + private organizationUserService: OrganizationUserService, private providerService: ProviderService, fileDownloadService: FileDownloadService ) { @@ -72,7 +74,7 @@ export class EventsComponent extends BaseEventsComponent implements OnInit, OnDe } async load() { - const response = await this.apiService.getOrganizationUsers(this.organizationId); + const response = await this.organizationUserService.getAllUsers(this.organizationId); response.data.forEach((u) => { const name = this.userNamePipe.transform(u); this.orgUsersUserIdMap.set(u.userId, { name: name, email: u.email }); diff --git a/apps/web/src/app/organizations/manage/people.component.ts b/apps/web/src/app/organizations/manage/people.component.ts index 0055b59717..c4f62b1992 100644 --- a/apps/web/src/app/organizations/manage/people.component.ts +++ b/apps/web/src/app/organizations/manage/people.component.ts @@ -9,6 +9,12 @@ import { ApiService } from "@bitwarden/common/abstractions/api.service"; import { CryptoService } from "@bitwarden/common/abstractions/crypto.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/abstractions/log.service"; +import { OrganizationUserService } from "@bitwarden/common/abstractions/organization-user/organization-user.service"; +import { OrganizationUserConfirmRequest } from "@bitwarden/common/abstractions/organization-user/requests"; +import { + OrganizationUserBulkResponse, + OrganizationUserUserDetailsResponse, +} from "@bitwarden/common/abstractions/organization-user/responses"; import { OrganizationApiServiceAbstraction } from "@bitwarden/common/abstractions/organization/organization-api.service.abstraction"; import { OrganizationService } from "@bitwarden/common/abstractions/organization/organization.service.abstraction"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; @@ -23,11 +29,7 @@ import { PolicyType } from "@bitwarden/common/enums/policyType"; import { ProductType } from "@bitwarden/common/enums/productType"; import { Organization } from "@bitwarden/common/models/domain/organization"; import { OrganizationKeysRequest } from "@bitwarden/common/models/request/organization-keys.request"; -import { OrganizationUserBulkRequest } from "@bitwarden/common/models/request/organization-user-bulk.request"; -import { OrganizationUserConfirmRequest } from "@bitwarden/common/models/request/organization-user-confirm.request"; import { ListResponse } from "@bitwarden/common/models/response/list.response"; -import { OrganizationUserBulkResponse } from "@bitwarden/common/models/response/organization-user-bulk.response"; -import { OrganizationUserUserDetailsResponse } from "@bitwarden/common/models/response/organization-user.response"; import { DialogService } from "@bitwarden/components"; import { BasePeopleComponent } from "../../common/base.people.component"; @@ -92,6 +94,7 @@ export class PeopleComponent stateService: StateService, private organizationService: OrganizationService, private organizationApiService: OrganizationApiServiceAbstraction, + private organizationUserService: OrganizationUserService, private dialogService: DialogService ) { super( @@ -167,23 +170,23 @@ export class PeopleComponent } getUsers(): Promise> { - return this.apiService.getOrganizationUsers(this.organization.id); + return this.organizationUserService.getAllUsers(this.organization.id); } deleteUser(id: string): Promise { - return this.apiService.deleteOrganizationUser(this.organization.id, id); + return this.organizationUserService.deleteOrganizationUser(this.organization.id, id); } revokeUser(id: string): Promise { - return this.apiService.revokeOrganizationUser(this.organization.id, id); + return this.organizationUserService.revokeOrganizationUser(this.organization.id, id); } restoreUser(id: string): Promise { - return this.apiService.restoreOrganizationUser(this.organization.id, id); + return this.organizationUserService.restoreOrganizationUser(this.organization.id, id); } reinviteUser(id: string): Promise { - return this.apiService.postOrganizationUserReinvite(this.organization.id, id); + return this.organizationUserService.postOrganizationUserReinvite(this.organization.id, id); } async confirmUser( @@ -194,7 +197,11 @@ export class PeopleComponent const key = await this.cryptoService.rsaEncrypt(orgKey.key, publicKey.buffer); const request = new OrganizationUserConfirmRequest(); request.key = key.encryptedString; - await this.apiService.postOrganizationUserConfirm(this.organization.id, user.id, request); + await this.organizationUserService.postOrganizationUserConfirm( + this.organization.id, + user.id, + request + ); } allowResetPassword(orgUser: OrganizationUserUserDetailsResponse): boolean { @@ -377,10 +384,9 @@ export class PeopleComponent } try { - const request = new OrganizationUserBulkRequest(filteredUsers.map((user) => user.id)); - const response = this.apiService.postManyOrganizationUserReinvite( + const response = this.organizationUserService.postManyOrganizationUserReinvite( this.organization.id, - request + filteredUsers.map((user) => user.id) ); this.showBulkStatus( users, diff --git a/apps/web/src/app/organizations/manage/reset-password.component.ts b/apps/web/src/app/organizations/manage/reset-password.component.ts index 8899e6684c..3d96426f70 100644 --- a/apps/web/src/app/organizations/manage/reset-password.component.ts +++ b/apps/web/src/app/organizations/manage/reset-password.component.ts @@ -11,17 +11,17 @@ import { Subject, takeUntil } from "rxjs"; import zxcvbn from "zxcvbn"; import { PasswordStrengthComponent } from "@bitwarden/angular/shared/components/password-strength/password-strength.component"; -import { ApiService } from "@bitwarden/common/abstractions/api.service"; import { CryptoService } from "@bitwarden/common/abstractions/crypto.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/abstractions/log.service"; +import { OrganizationUserService } from "@bitwarden/common/abstractions/organization-user/organization-user.service"; +import { OrganizationUserResetPasswordRequest } from "@bitwarden/common/abstractions/organization-user/requests"; import { PasswordGenerationService } from "@bitwarden/common/abstractions/passwordGeneration.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { PolicyService } from "@bitwarden/common/abstractions/policy/policy.service.abstraction"; import { EncString } from "@bitwarden/common/models/domain/enc-string"; import { MasterPasswordPolicyOptions } from "@bitwarden/common/models/domain/master-password-policy-options"; import { SymmetricCryptoKey } from "@bitwarden/common/models/domain/symmetric-crypto-key"; -import { OrganizationUserResetPasswordRequest } from "@bitwarden/common/models/request/organization-user-reset-password.request"; @Component({ selector: "app-reset-password", @@ -44,13 +44,13 @@ export class ResetPasswordComponent implements OnInit, OnDestroy { private destroy$ = new Subject(); constructor( - private apiService: ApiService, private i18nService: I18nService, private platformUtilsService: PlatformUtilsService, private passwordGenerationService: PasswordGenerationService, private policyService: PolicyService, private cryptoService: CryptoService, - private logService: LogService + private logService: LogService, + private organizationUserService: OrganizationUserService ) {} async ngOnInit() { @@ -147,7 +147,7 @@ export class ResetPasswordComponent implements OnInit, OnDestroy { // Get user Information (kdf type, kdf iterations, resetPasswordKey, private key) and change password try { - this.formPromise = this.apiService + this.formPromise = this.organizationUserService .getOrganizationUserResetPasswordDetails(this.organizationId, this.id) .then(async (response) => { if (response == null) { @@ -188,7 +188,7 @@ export class ResetPasswordComponent implements OnInit, OnDestroy { request.newMasterPasswordHash = newPasswordHash; // Change user's password - return this.apiService.putOrganizationUserResetPassword( + return this.organizationUserService.putOrganizationUserResetPassword( this.organizationId, this.id, request diff --git a/apps/web/src/app/organizations/manage/user-add-edit.component.ts b/apps/web/src/app/organizations/manage/user-add-edit.component.ts index 52506568d9..b4cb7065f5 100644 --- a/apps/web/src/app/organizations/manage/user-add-edit.component.ts +++ b/apps/web/src/app/organizations/manage/user-add-edit.component.ts @@ -4,6 +4,11 @@ import { ApiService } from "@bitwarden/common/abstractions/api.service"; import { CollectionService } from "@bitwarden/common/abstractions/collection.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/abstractions/log.service"; +import { OrganizationUserService } from "@bitwarden/common/abstractions/organization-user/organization-user.service"; +import { + OrganizationUserInviteRequest, + OrganizationUserUpdateRequest, +} from "@bitwarden/common/abstractions/organization-user/requests"; import { OrganizationService } from "@bitwarden/common/abstractions/organization/organization.service.abstraction"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { OrganizationUserStatusType } from "@bitwarden/common/enums/organizationUserStatusType"; @@ -11,8 +16,6 @@ import { OrganizationUserType } from "@bitwarden/common/enums/organizationUserTy import { PermissionsApi } from "@bitwarden/common/models/api/permissions.api"; import { CollectionData } from "@bitwarden/common/models/data/collection.data"; import { Collection } from "@bitwarden/common/models/domain/collection"; -import { OrganizationUserInviteRequest } from "@bitwarden/common/models/request/organization-user-invite.request"; -import { OrganizationUserUpdateRequest } from "@bitwarden/common/models/request/organization-user-update.request"; import { SelectionReadOnlyRequest } from "@bitwarden/common/models/request/selection-read-only.request"; import { CollectionDetailsResponse } from "@bitwarden/common/models/response/collection.response"; import { CollectionView } from "@bitwarden/common/models/view/collection.view"; @@ -87,7 +90,8 @@ export class UserAddEditComponent implements OnInit { private collectionService: CollectionService, private platformUtilsService: PlatformUtilsService, private organizationService: OrganizationService, - private logService: LogService + private logService: LogService, + private organizationUserService: OrganizationUserService ) {} async ngOnInit() { @@ -100,7 +104,7 @@ export class UserAddEditComponent implements OnInit { this.editMode = true; this.title = this.i18nService.t("editUser"); try { - const user = await this.apiService.getOrganizationUser( + const user = await this.organizationUserService.getOrganizationUser( this.organizationId, this.organizationUserId ); @@ -224,7 +228,7 @@ export class UserAddEditComponent implements OnInit { } try { - this.deletePromise = this.apiService.deleteOrganizationUser( + this.deletePromise = this.organizationUserService.deleteOrganizationUser( this.organizationId, this.organizationUserId ); @@ -259,7 +263,7 @@ export class UserAddEditComponent implements OnInit { } try { - this.formPromise = this.apiService.revokeOrganizationUser( + this.formPromise = this.organizationUserService.revokeOrganizationUser( this.organizationId, this.organizationUserId ); @@ -282,7 +286,7 @@ export class UserAddEditComponent implements OnInit { } try { - this.formPromise = this.apiService.restoreOrganizationUser( + this.formPromise = this.organizationUserService.restoreOrganizationUser( this.organizationId, this.organizationUserId ); @@ -308,7 +312,7 @@ export class UserAddEditComponent implements OnInit { request.permissions ?? new PermissionsApi(), request.type !== OrganizationUserType.Custom ); - this.formPromise = this.apiService.putOrganizationUser( + this.formPromise = this.organizationUserService.putOrganizationUser( this.organizationId, this.organizationUserId, request @@ -325,6 +329,9 @@ export class UserAddEditComponent implements OnInit { request.type !== OrganizationUserType.Custom ); request.collections = collections; - this.formPromise = this.apiService.postOrganizationUserInvite(this.organizationId, request); + this.formPromise = this.organizationUserService.postOrganizationUserInvite( + this.organizationId, + request + ); } } diff --git a/apps/web/src/app/organizations/manage/user-groups.component.ts b/apps/web/src/app/organizations/manage/user-groups.component.ts index 999fba57a3..c2b20791fd 100644 --- a/apps/web/src/app/organizations/manage/user-groups.component.ts +++ b/apps/web/src/app/organizations/manage/user-groups.component.ts @@ -3,9 +3,10 @@ import { Component, EventEmitter, Input, OnInit, Output } from "@angular/core"; import { ApiService } from "@bitwarden/common/abstractions/api.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/abstractions/log.service"; +import { OrganizationUserService } from "@bitwarden/common/abstractions/organization-user/organization-user.service"; +import { OrganizationUserUpdateGroupsRequest } from "@bitwarden/common/abstractions/organization-user/requests"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { Utils } from "@bitwarden/common/misc/utils"; -import { OrganizationUserUpdateGroupsRequest } from "@bitwarden/common/models/request/organization-user-update-groups.request"; import { GroupResponse } from "@bitwarden/common/models/response/group.response"; @Component({ @@ -26,7 +27,8 @@ export class UserGroupsComponent implements OnInit { private apiService: ApiService, private i18nService: I18nService, private platformUtilsService: PlatformUtilsService, - private logService: LogService + private logService: LogService, + private organizationUserService: OrganizationUserService ) {} async ngOnInit() { @@ -36,7 +38,7 @@ export class UserGroupsComponent implements OnInit { this.groups = groups; try { - const userGroups = await this.apiService.getOrganizationUserGroups( + const userGroups = await this.organizationUserService.getOrganizationUserGroups( this.organizationId, this.organizationUserId ); @@ -71,7 +73,7 @@ export class UserGroupsComponent implements OnInit { request.groupIds = this.groups.filter((g) => (g as any).checked).map((g) => g.id); try { - this.formPromise = this.apiService.putOrganizationUserGroups( + this.formPromise = this.organizationUserService.putOrganizationUserGroups( this.organizationId, this.organizationUserId, request diff --git a/apps/web/src/app/organizations/users/enroll-master-password-reset.component.ts b/apps/web/src/app/organizations/users/enroll-master-password-reset.component.ts index 1a7661fc36..1b117636fa 100644 --- a/apps/web/src/app/organizations/users/enroll-master-password-reset.component.ts +++ b/apps/web/src/app/organizations/users/enroll-master-password-reset.component.ts @@ -2,17 +2,17 @@ import { Component } from "@angular/core"; import { ModalRef } from "@bitwarden/angular/components/modal/modal.ref"; import { ModalConfig } from "@bitwarden/angular/services/modal.service"; -import { ApiService } from "@bitwarden/common/abstractions/api.service"; import { CryptoService } from "@bitwarden/common/abstractions/crypto.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/abstractions/log.service"; +import { OrganizationUserService } from "@bitwarden/common/abstractions/organization-user/organization-user.service"; +import { OrganizationUserResetPasswordEnrollmentRequest } from "@bitwarden/common/abstractions/organization-user/requests"; import { OrganizationApiServiceAbstraction } from "@bitwarden/common/abstractions/organization/organization-api.service.abstraction"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { UserVerificationService } from "@bitwarden/common/abstractions/userVerification/userVerification.service.abstraction"; import { Utils } from "@bitwarden/common/misc/utils"; import { Organization } from "@bitwarden/common/models/domain/organization"; -import { OrganizationUserResetPasswordEnrollmentRequest } from "@bitwarden/common/models/request/organization-user-reset-password-enrollment.request"; import { Verification } from "@bitwarden/common/types/verification"; @Component({ @@ -27,7 +27,6 @@ export class EnrollMasterPasswordReset { constructor( private userVerificationService: UserVerificationService, - private apiService: ApiService, private platformUtilsService: PlatformUtilsService, private i18nService: I18nService, private cryptoService: CryptoService, @@ -35,7 +34,8 @@ export class EnrollMasterPasswordReset { private logService: LogService, private modalRef: ModalRef, config: ModalConfig, - private organizationApiService: OrganizationApiServiceAbstraction + private organizationApiService: OrganizationApiServiceAbstraction, + private organizationUserService: OrganizationUserService ) { this.organization = config.data.organization; } @@ -65,7 +65,7 @@ export class EnrollMasterPasswordReset { // Create request and execute enrollment request.resetPasswordKey = keyString; - await this.apiService.putOrganizationUserResetPasswordEnrollment( + await this.organizationUserService.putOrganizationUserResetPasswordEnrollment( this.organization.id, this.organization.userId, request diff --git a/apps/web/src/app/settings/change-password.component.ts b/apps/web/src/app/settings/change-password.component.ts index e6e1709d22..8d0266410f 100644 --- a/apps/web/src/app/settings/change-password.component.ts +++ b/apps/web/src/app/settings/change-password.component.ts @@ -10,6 +10,8 @@ import { FolderService } from "@bitwarden/common/abstractions/folder/folder.serv import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { KeyConnectorService } from "@bitwarden/common/abstractions/keyConnector.service"; import { MessagingService } from "@bitwarden/common/abstractions/messaging.service"; +import { OrganizationUserService } from "@bitwarden/common/abstractions/organization-user/organization-user.service"; +import { OrganizationUserResetPasswordEnrollmentRequest } from "@bitwarden/common/abstractions/organization-user/requests"; import { OrganizationApiServiceAbstraction } from "@bitwarden/common/abstractions/organization/organization-api.service.abstraction"; import { OrganizationService } from "@bitwarden/common/abstractions/organization/organization.service.abstraction"; import { PasswordGenerationService } from "@bitwarden/common/abstractions/passwordGeneration.service"; @@ -25,7 +27,6 @@ import { SymmetricCryptoKey } from "@bitwarden/common/models/domain/symmetric-cr import { CipherWithIdRequest } from "@bitwarden/common/models/request/cipher-with-id.request"; import { EmergencyAccessUpdateRequest } from "@bitwarden/common/models/request/emergency-access-update.request"; import { FolderWithIdRequest } from "@bitwarden/common/models/request/folder-with-id.request"; -import { OrganizationUserResetPasswordEnrollmentRequest } from "@bitwarden/common/models/request/organization-user-reset-password-enrollment.request"; import { PasswordRequest } from "@bitwarden/common/models/request/password.request"; import { SendWithIdRequest } from "@bitwarden/common/models/request/send-with-id.request"; import { UpdateKeyRequest } from "@bitwarden/common/models/request/update-key.request"; @@ -55,7 +56,8 @@ export class ChangePasswordComponent extends BaseChangePasswordComponent { private organizationService: OrganizationService, private keyConnectorService: KeyConnectorService, private router: Router, - private organizationApiService: OrganizationApiServiceAbstraction + private organizationApiService: OrganizationApiServiceAbstraction, + private organizationUserService: OrganizationUserService ) { super( i18nService, @@ -280,7 +282,11 @@ export class ChangePasswordComponent extends BaseChangePasswordComponent { request.masterPasswordHash = masterPasswordHash; request.resetPasswordKey = encryptedKey.encryptedString; - await this.apiService.putOrganizationUserResetPasswordEnrollment(org.id, org.userId, request); + await this.organizationUserService.putOrganizationUserResetPasswordEnrollment( + org.id, + org.userId, + request + ); } } } diff --git a/apps/web/src/app/vault/vault-filter/organization-filter/organization-options.component.ts b/apps/web/src/app/vault/vault-filter/organization-filter/organization-options.component.ts index 06b88bd0e4..d898bd6354 100644 --- a/apps/web/src/app/vault/vault-filter/organization-filter/organization-options.component.ts +++ b/apps/web/src/app/vault/vault-filter/organization-filter/organization-options.component.ts @@ -5,6 +5,8 @@ import { ModalService } from "@bitwarden/angular/services/modal.service"; import { ApiService } from "@bitwarden/common/abstractions/api.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/abstractions/log.service"; +import { OrganizationUserService } from "@bitwarden/common/abstractions/organization-user/organization-user.service"; +import { OrganizationUserResetPasswordEnrollmentRequest } from "@bitwarden/common/abstractions/organization-user/requests"; import { OrganizationApiServiceAbstraction } from "@bitwarden/common/abstractions/organization/organization-api.service.abstraction"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { PolicyService } from "@bitwarden/common/abstractions/policy/policy.service.abstraction"; @@ -12,7 +14,6 @@ import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.ab import { PolicyType } from "@bitwarden/common/enums/policyType"; import { Organization } from "@bitwarden/common/models/domain/organization"; import { Policy } from "@bitwarden/common/models/domain/policy"; -import { OrganizationUserResetPasswordEnrollmentRequest } from "@bitwarden/common/models/request/organization-user-reset-password-enrollment.request"; import { EnrollMasterPasswordReset } from "../../../organizations/users/enroll-master-password-reset.component"; @@ -37,7 +38,8 @@ export class OrganizationOptionsComponent implements OnInit, OnDestroy { private policyService: PolicyService, private modalService: ModalService, private logService: LogService, - private organizationApiService: OrganizationApiServiceAbstraction + private organizationApiService: OrganizationApiServiceAbstraction, + private organizationUserService: OrganizationUserService ) {} async ngOnInit() { @@ -133,7 +135,7 @@ export class OrganizationOptionsComponent implements OnInit, OnDestroy { const request = new OrganizationUserResetPasswordEnrollmentRequest(); request.masterPasswordHash = "ignored"; request.resetPasswordKey = null; - this.actionPromise = this.apiService.putOrganizationUserResetPasswordEnrollment( + this.actionPromise = this.organizationUserService.putOrganizationUserResetPasswordEnrollment( this.organization.id, this.organization.userId, request diff --git a/libs/angular/src/components/set-password.component.ts b/libs/angular/src/components/set-password.component.ts index 3c98e58516..7fd59c9bb1 100644 --- a/libs/angular/src/components/set-password.component.ts +++ b/libs/angular/src/components/set-password.component.ts @@ -6,6 +6,8 @@ import { ApiService } from "@bitwarden/common/abstractions/api.service"; import { CryptoService } from "@bitwarden/common/abstractions/crypto.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { MessagingService } from "@bitwarden/common/abstractions/messaging.service"; +import { OrganizationUserService } from "@bitwarden/common/abstractions/organization-user/organization-user.service"; +import { OrganizationUserResetPasswordEnrollmentRequest } from "@bitwarden/common/abstractions/organization-user/requests"; import { OrganizationApiServiceAbstraction } from "@bitwarden/common/abstractions/organization/organization-api.service.abstraction"; import { PasswordGenerationService } from "@bitwarden/common/abstractions/passwordGeneration.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; @@ -19,7 +21,6 @@ import { Utils } from "@bitwarden/common/misc/utils"; import { EncString } from "@bitwarden/common/models/domain/enc-string"; import { SymmetricCryptoKey } from "@bitwarden/common/models/domain/symmetric-crypto-key"; import { KeysRequest } from "@bitwarden/common/models/request/keys.request"; -import { OrganizationUserResetPasswordEnrollmentRequest } from "@bitwarden/common/models/request/organization-user-reset-password-enrollment.request"; import { SetPasswordRequest } from "@bitwarden/common/models/request/set-password.request"; import { ChangePasswordComponent as BaseChangePasswordComponent } from "./change-password.component"; @@ -49,7 +50,8 @@ export class SetPasswordComponent extends BaseChangePasswordComponent { private syncService: SyncService, private route: ActivatedRoute, stateService: StateService, - private organizationApiService: OrganizationApiServiceAbstraction + private organizationApiService: OrganizationApiServiceAbstraction, + private organizationUserService: OrganizationUserService ) { super( i18nService, @@ -136,7 +138,7 @@ export class SetPasswordComponent extends BaseChangePasswordComponent { resetRequest.masterPasswordHash = masterPasswordHash; resetRequest.resetPasswordKey = encryptedKey.encryptedString; - return this.apiService.putOrganizationUserResetPasswordEnrollment( + return this.organizationUserService.putOrganizationUserResetPasswordEnrollment( this.orgId, userId, resetRequest diff --git a/libs/angular/src/services/jslib-services.module.ts b/libs/angular/src/services/jslib-services.module.ts index 6c01fc9b33..a7d32a8909 100644 --- a/libs/angular/src/services/jslib-services.module.ts +++ b/libs/angular/src/services/jslib-services.module.ts @@ -2,8 +2,8 @@ import { Injector, LOCALE_ID, NgModule } from "@angular/core"; import { AccountApiService as AccountApiServiceAbstraction } from "@bitwarden/common/abstractions/account/account-api.service"; import { - InternalAccountService, AccountService as AccountServiceAbstraction, + InternalAccountService, } from "@bitwarden/common/abstractions/account/account.service"; import { AnonymousHubService as AnonymousHubServiceAbstraction } from "@bitwarden/common/abstractions/anonymousHub.service"; import { ApiService as ApiServiceAbstraction } from "@bitwarden/common/abstractions/api.service"; @@ -35,6 +35,7 @@ import { LogService } from "@bitwarden/common/abstractions/log.service"; import { LoginService as LoginServiceAbstraction } from "@bitwarden/common/abstractions/login.service"; import { MessagingService as MessagingServiceAbstraction } from "@bitwarden/common/abstractions/messaging.service"; import { NotificationsService as NotificationsServiceAbstraction } from "@bitwarden/common/abstractions/notifications.service"; +import { OrganizationUserService } from "@bitwarden/common/abstractions/organization-user/organization-user.service"; import { OrganizationApiServiceAbstraction } from "@bitwarden/common/abstractions/organization/organization-api.service.abstraction"; import { InternalOrganizationService, @@ -45,8 +46,8 @@ import { PasswordRepromptService as PasswordRepromptServiceAbstraction } from "@ import { PlatformUtilsService as PlatformUtilsServiceAbstraction } from "@bitwarden/common/abstractions/platformUtils.service"; import { PolicyApiServiceAbstraction } from "@bitwarden/common/abstractions/policy/policy-api.service.abstraction"; import { - PolicyService as PolicyServiceAbstraction, InternalPolicyService, + PolicyService as PolicyServiceAbstraction, } from "@bitwarden/common/abstractions/policy/policy.service.abstraction"; import { ProviderService as ProviderServiceAbstraction } from "@bitwarden/common/abstractions/provider.service"; import { SearchService as SearchServiceAbstraction } from "@bitwarden/common/abstractions/search.service"; @@ -96,6 +97,7 @@ import { FormValidationErrorsService } from "@bitwarden/common/services/formVali import { KeyConnectorService } from "@bitwarden/common/services/keyConnector.service"; import { LoginService } from "@bitwarden/common/services/login.service"; import { NotificationsService } from "@bitwarden/common/services/notifications.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"; @@ -126,16 +128,16 @@ import { UnauthGuard } from "../guards/unauth.guard"; import { BroadcasterService } from "./broadcaster.service"; import { - WINDOW, + LOCALES_DIRECTORY, + LOCKED_CALLBACK, + LOG_MAC_FAILURES, + LOGOUT_CALLBACK, MEMORY_STORAGE, SECURE_STORAGE, STATE_FACTORY, STATE_SERVICE_USE_CACHE, - LOGOUT_CALLBACK, - LOCKED_CALLBACK, - LOCALES_DIRECTORY, SYSTEM_LANGUAGE, - LOG_MAC_FAILURES, + WINDOW, } from "./injection-tokens"; import { ModalService } from "./modal.service"; import { PasswordRepromptService } from "./passwordReprompt.service"; @@ -539,6 +541,11 @@ import { AbstractThemingService } from "./theming/theming.service.abstraction"; provide: InternalOrganizationService, useExisting: OrganizationServiceAbstraction, }, + { + provide: OrganizationUserService, + useClass: OrganizationUserServiceImplementation, + deps: [ApiServiceAbstraction], + }, { provide: ProviderServiceAbstraction, useClass: ProviderService, diff --git a/libs/common/src/abstractions/api.service.ts b/libs/common/src/abstractions/api.service.ts index d130f51413..83360607e1 100644 --- a/libs/common/src/abstractions/api.service.ts +++ b/libs/common/src/abstractions/api.service.ts @@ -34,15 +34,6 @@ import { KeyConnectorUserKeyRequest } from "../models/request/key-connector-user import { KeysRequest } from "../models/request/keys.request"; import { OrganizationConnectionRequest } from "../models/request/organization-connection.request"; import { OrganizationImportRequest } from "../models/request/organization-import.request"; -import { OrganizationUserAcceptRequest } from "../models/request/organization-user-accept.request"; -import { OrganizationUserBulkConfirmRequest } from "../models/request/organization-user-bulk-confirm.request"; -import { OrganizationUserBulkRequest } from "../models/request/organization-user-bulk.request"; -import { OrganizationUserConfirmRequest } from "../models/request/organization-user-confirm.request"; -import { OrganizationUserInviteRequest } from "../models/request/organization-user-invite.request"; -import { OrganizationUserResetPasswordEnrollmentRequest } from "../models/request/organization-user-reset-password-enrollment.request"; -import { OrganizationUserResetPasswordRequest } from "../models/request/organization-user-reset-password.request"; -import { OrganizationUserUpdateGroupsRequest } from "../models/request/organization-user-update-groups.request"; -import { OrganizationUserUpdateRequest } from "../models/request/organization-user-update.request"; import { OrganizationSponsorshipCreateRequest } from "../models/request/organization/organization-sponsorship-create.request"; import { OrganizationSponsorshipRedeemRequest } from "../models/request/organization/organization-sponsorship-redeem.request"; import { PasswordHintRequest } from "../models/request/password-hint.request"; @@ -117,13 +108,6 @@ import { } from "../models/response/organization-connection.response"; import { OrganizationExportResponse } from "../models/response/organization-export.response"; import { OrganizationSponsorshipSyncStatusResponse } from "../models/response/organization-sponsorship-sync-status.response"; -import { OrganizationUserBulkPublicKeyResponse } from "../models/response/organization-user-bulk-public-key.response"; -import { OrganizationUserBulkResponse } from "../models/response/organization-user-bulk.response"; -import { - OrganizationUserDetailsResponse, - OrganizationUserUserDetailsResponse, - OrganizationUserResetPasswordDetailsReponse, -} from "../models/response/organization-user.response"; import { PaymentResponse } from "../models/response/payment.response"; import { PlanResponse } from "../models/response/plan.response"; import { PolicyResponse } from "../models/response/policy.response"; @@ -136,8 +120,8 @@ import { import { ProviderUserBulkPublicKeyResponse } from "../models/response/provider/provider-user-bulk-public-key.response"; import { ProviderUserBulkResponse } from "../models/response/provider/provider-user-bulk.response"; import { - ProviderUserUserDetailsResponse, ProviderUserResponse, + ProviderUserUserDetailsResponse, } from "../models/response/provider/provider-user.response"; import { ProviderResponse } from "../models/response/provider/provider.response"; import { SelectionReadOnlyResponse } from "../models/response/selection-read-only.response"; @@ -156,8 +140,8 @@ import { TwoFactorEmailResponse } from "../models/response/two-factor-email.resp import { TwoFactorProviderResponse } from "../models/response/two-factor-provider.response"; import { TwoFactorRecoverResponse } from "../models/response/two-factor-recover.response"; import { - TwoFactorWebAuthnResponse, ChallengeResponse, + TwoFactorWebAuthnResponse, } from "../models/response/two-factor-web-authn.response"; import { TwoFactorYubiKeyResponse } from "../models/response/two-factor-yubi-key.response"; import { UserKeyResponse } from "../models/response/user-key.response"; @@ -355,82 +339,6 @@ export abstract class ApiService { deleteGroup: (organizationId: string, id: string) => Promise; deleteGroupUser: (organizationId: string, id: string, organizationUserId: string) => Promise; - getOrganizationUser: ( - organizationId: string, - id: string - ) => Promise; - getOrganizationUserGroups: (organizationId: string, id: string) => Promise; - getOrganizationUsers: ( - organizationId: string - ) => Promise>; - getOrganizationUserResetPasswordDetails: ( - organizationId: string, - id: string - ) => Promise; - postOrganizationUserInvite: ( - organizationId: string, - request: OrganizationUserInviteRequest - ) => Promise; - postOrganizationUserReinvite: (organizationId: string, id: string) => Promise; - postManyOrganizationUserReinvite: ( - organizationId: string, - request: OrganizationUserBulkRequest - ) => Promise>; - postOrganizationUserAccept: ( - organizationId: string, - id: string, - request: OrganizationUserAcceptRequest - ) => Promise; - postOrganizationUserConfirm: ( - organizationId: string, - id: string, - request: OrganizationUserConfirmRequest - ) => Promise; - postOrganizationUsersPublicKey: ( - organizationId: string, - request: OrganizationUserBulkRequest - ) => Promise>; - postOrganizationUserBulkConfirm: ( - organizationId: string, - request: OrganizationUserBulkConfirmRequest - ) => Promise>; - - putOrganizationUser: ( - organizationId: string, - id: string, - request: OrganizationUserUpdateRequest - ) => Promise; - putOrganizationUserGroups: ( - organizationId: string, - id: string, - request: OrganizationUserUpdateGroupsRequest - ) => Promise; - putOrganizationUserResetPasswordEnrollment: ( - organizationId: string, - userId: string, - request: OrganizationUserResetPasswordEnrollmentRequest - ) => Promise; - putOrganizationUserResetPassword: ( - organizationId: string, - id: string, - request: OrganizationUserResetPasswordRequest - ) => Promise; - deleteOrganizationUser: (organizationId: string, id: string) => Promise; - deleteManyOrganizationUsers: ( - organizationId: string, - request: OrganizationUserBulkRequest - ) => Promise>; - revokeOrganizationUser: (organizationId: string, id: string) => Promise; - revokeManyOrganizationUsers: ( - organizationId: string, - request: OrganizationUserBulkRequest - ) => Promise>; - restoreOrganizationUser: (organizationId: string, id: string) => Promise; - restoreManyOrganizationUsers: ( - organizationId: string, - request: OrganizationUserBulkRequest - ) => Promise>; - getSync: () => Promise; postPublicImportDirectory: (request: OrganizationImportRequest) => Promise; diff --git a/libs/common/src/abstractions/organization-user/organization-user.service.ts b/libs/common/src/abstractions/organization-user/organization-user.service.ts new file mode 100644 index 0000000000..4485ac883d --- /dev/null +++ b/libs/common/src/abstractions/organization-user/organization-user.service.ts @@ -0,0 +1,233 @@ +import { ListResponse } from "../../models/response/list.response"; + +import { + OrganizationUserAcceptRequest, + OrganizationUserBulkConfirmRequest, + OrganizationUserConfirmRequest, + OrganizationUserInviteRequest, + OrganizationUserResetPasswordEnrollmentRequest, + OrganizationUserResetPasswordRequest, + OrganizationUserUpdateGroupsRequest, + OrganizationUserUpdateRequest, +} from "./requests"; +import { + OrganizationUserBulkPublicKeyResponse, + OrganizationUserBulkResponse, + OrganizationUserDetailsResponse, + OrganizationUserResetPasswordDetailsReponse, + OrganizationUserUserDetailsResponse, +} from "./responses"; + +/** + * Service for interacting with Organization Users via the API + */ +export abstract class OrganizationUserService { + /** + * Retrieve a single organization user by Id + * @param organizationId - Identifier for the user's organization + * @param id - Organization user identifier + */ + abstract getOrganizationUser( + organizationId: string, + id: string + ): Promise; + + /** + * Retrieve a list of groups Ids the specified organization user belongs to + * @param organizationId - Identifier for the user's organization + * @param id - Organization user identifier + */ + abstract getOrganizationUserGroups(organizationId: string, id: string): Promise; + + /** + * Retrieve a list of all users that belong to the specified organization + * @param organizationId - Identifier for the organization + */ + abstract getAllUsers( + organizationId: string + ): Promise>; + + /** + * Retrieve reset password details for the specified organization user + * @param organizationId - Identifier for the user's organization + * @param id - Organization user identifier + */ + abstract getOrganizationUserResetPasswordDetails( + organizationId: string, + id: string + ): Promise; + + /** + * Create new organization user invite(s) for the specified organization + * @param organizationId - Identifier for the organization + * @param request - New user invitation request details + */ + abstract postOrganizationUserInvite( + organizationId: string, + request: OrganizationUserInviteRequest + ): Promise; + + /** + * Re-invite the specified organization user + * @param organizationId - Identifier for the user's organization + * @param id - Organization user identifier + */ + abstract postOrganizationUserReinvite(organizationId: string, id: string): Promise; + + /** + * Re-invite many organization users for the specified organization + * @param organizationId - Identifier for the organization + * @param ids - A list of organization user identifiers + * @return List of user ids, including both those that were successfully re-invited and those that had an error + */ + abstract postManyOrganizationUserReinvite( + organizationId: string, + ids: string[] + ): Promise>; + + /** + * Accept an organization user invitation + * @param organizationId - Identifier for the organization to accept + * @param id - Organization user identifier + * @param request - Request details for accepting the invitation + */ + abstract postOrganizationUserAccept( + organizationId: string, + id: string, + request: OrganizationUserAcceptRequest + ): Promise; + + /** + * Confirm an organization user that has accepted their invitation + * @param organizationId - Identifier for the organization to confirm + * @param id - Organization user identifier + * @param request - Request details for confirming the user + */ + abstract postOrganizationUserConfirm( + organizationId: string, + id: string, + request: OrganizationUserConfirmRequest + ): Promise; + + /** + * Retrieve a list of the specified users' public keys + * @param organizationId - Identifier for the organization to accept + * @param ids - A list of organization user identifiers to retrieve public keys for + */ + abstract postOrganizationUsersPublicKey( + organizationId: string, + ids: string[] + ): Promise>; + + /** + * Confirm many organization users that have accepted their invitations + * @param organizationId - Identifier for the organization to confirm users + * @param request - Bulk request details for confirming the user + */ + abstract postOrganizationUserBulkConfirm( + organizationId: string, + request: OrganizationUserBulkConfirmRequest + ): Promise>; + + /** + * Update an organization users + * @param organizationId - Identifier for the organization the user belongs to + * @param id - Organization user identifier + * @param request - Request details for updating the user + */ + abstract putOrganizationUser( + organizationId: string, + id: string, + request: OrganizationUserUpdateRequest + ): Promise; + + /** + * Update an organization user's groups + * @param organizationId - Identifier for the organization the user belongs to + * @param id - Organization user identifier + * @param groupIds - List of group ids to associate the user with + */ + abstract putOrganizationUserGroups( + organizationId: string, + id: string, + groupIds: OrganizationUserUpdateGroupsRequest + ): Promise; + + /** + * Update an organization user's reset password enrollment + * @param organizationId - Identifier for the organization the user belongs to + * @param userId - Organization user identifier + * @param request - Reset password enrollment details + */ + abstract putOrganizationUserResetPasswordEnrollment( + organizationId: string, + userId: string, + request: OrganizationUserResetPasswordEnrollmentRequest + ): Promise; + + /** + * Reset an organization user's password + * @param organizationId - Identifier for the organization the user belongs to + * @param id - Organization user identifier + * @param request - Reset password details + */ + abstract putOrganizationUserResetPassword( + organizationId: string, + id: string, + request: OrganizationUserResetPasswordRequest + ): Promise; + + /** + * Delete an organization user + * @param organizationId - Identifier for the organization the user belongs to + * @param id - Organization user identifier + */ + abstract deleteOrganizationUser(organizationId: string, id: string): Promise; + + /** + * Delete many organization users + * @param organizationId - Identifier for the organization the users belongs to + * @param ids - List of organization user identifiers to delete + * @return List of user ids, including both those that were successfully deleted and those that had an error + */ + abstract deleteManyOrganizationUsers( + organizationId: string, + ids: string[] + ): Promise>; + + /** + * Revoke an organization user's access to the organization + * @param organizationId - Identifier for the organization the user belongs to + * @param id - Organization user identifier + */ + abstract revokeOrganizationUser(organizationId: string, id: string): Promise; + + /** + * Revoke many organization users' access to the organization + * @param organizationId - Identifier for the organization the users belongs to + * @param ids - List of organization user identifiers to revoke + * @return List of user ids, including both those that were successfully revoked and those that had an error + */ + abstract revokeManyOrganizationUsers( + organizationId: string, + ids: string[] + ): Promise>; + + /** + * Restore an organization user's access to the organization + * @param organizationId - Identifier for the organization the user belongs to + * @param id - Organization user identifier + */ + abstract restoreOrganizationUser(organizationId: string, id: string): Promise; + + /** + * Restore many organization users' access to the organization + * @param organizationId - Identifier for the organization the users belongs to + * @param ids - List of organization user identifiers to restore + * @return List of user ids, including both those that were successfully restored and those that had an error + */ + abstract restoreManyOrganizationUsers( + organizationId: string, + ids: string[] + ): Promise>; +} diff --git a/libs/common/src/abstractions/organization-user/requests/index.ts b/libs/common/src/abstractions/organization-user/requests/index.ts new file mode 100644 index 0000000000..8f45e585ee --- /dev/null +++ b/libs/common/src/abstractions/organization-user/requests/index.ts @@ -0,0 +1,8 @@ +export * from "./organization-user-accept.request"; +export * from "./organization-user-bulk-confirm.request"; +export * from "./organization-user-confirm.request"; +export * from "./organization-user-invite.request"; +export * from "./organization-user-reset-password.request"; +export * from "./organization-user-reset-password-enrollment.request"; +export * from "./organization-user-update.request"; +export * from "./organization-user-update-groups.request"; diff --git a/libs/common/src/models/request/organization-user-accept.request.ts b/libs/common/src/abstractions/organization-user/requests/organization-user-accept.request.ts similarity index 100% rename from libs/common/src/models/request/organization-user-accept.request.ts rename to libs/common/src/abstractions/organization-user/requests/organization-user-accept.request.ts diff --git a/libs/common/src/models/request/organization-user-bulk-confirm.request.ts b/libs/common/src/abstractions/organization-user/requests/organization-user-bulk-confirm.request.ts similarity index 100% rename from libs/common/src/models/request/organization-user-bulk-confirm.request.ts rename to libs/common/src/abstractions/organization-user/requests/organization-user-bulk-confirm.request.ts diff --git a/libs/common/src/models/request/organization-user-confirm.request.ts b/libs/common/src/abstractions/organization-user/requests/organization-user-confirm.request.ts similarity index 100% rename from libs/common/src/models/request/organization-user-confirm.request.ts rename to libs/common/src/abstractions/organization-user/requests/organization-user-confirm.request.ts diff --git a/libs/common/src/abstractions/organization-user/requests/organization-user-invite.request.ts b/libs/common/src/abstractions/organization-user/requests/organization-user-invite.request.ts new file mode 100644 index 0000000000..0117df600e --- /dev/null +++ b/libs/common/src/abstractions/organization-user/requests/organization-user-invite.request.ts @@ -0,0 +1,11 @@ +import { OrganizationUserType } from "../../../enums/organizationUserType"; +import { PermissionsApi } from "../../../models/api/permissions.api"; +import { SelectionReadOnlyRequest } from "../../../models/request/selection-read-only.request"; + +export class OrganizationUserInviteRequest { + emails: string[] = []; + type: OrganizationUserType; + accessAll: boolean; + collections: SelectionReadOnlyRequest[] = []; + permissions: PermissionsApi; +} diff --git a/libs/common/src/models/request/organization-user-reset-password-enrollment.request.ts b/libs/common/src/abstractions/organization-user/requests/organization-user-reset-password-enrollment.request.ts similarity index 56% rename from libs/common/src/models/request/organization-user-reset-password-enrollment.request.ts rename to libs/common/src/abstractions/organization-user/requests/organization-user-reset-password-enrollment.request.ts index b1f08430da..aff5d58c80 100644 --- a/libs/common/src/models/request/organization-user-reset-password-enrollment.request.ts +++ b/libs/common/src/abstractions/organization-user/requests/organization-user-reset-password-enrollment.request.ts @@ -1,4 +1,4 @@ -import { SecretVerificationRequest } from "./secret-verification.request"; +import { SecretVerificationRequest } from "../../../models/request/secret-verification.request"; export class OrganizationUserResetPasswordEnrollmentRequest extends SecretVerificationRequest { resetPasswordKey: string; diff --git a/libs/common/src/models/request/organization-user-reset-password.request.ts b/libs/common/src/abstractions/organization-user/requests/organization-user-reset-password.request.ts similarity index 100% rename from libs/common/src/models/request/organization-user-reset-password.request.ts rename to libs/common/src/abstractions/organization-user/requests/organization-user-reset-password.request.ts diff --git a/libs/common/src/models/request/organization-user-update-groups.request.ts b/libs/common/src/abstractions/organization-user/requests/organization-user-update-groups.request.ts similarity index 100% rename from libs/common/src/models/request/organization-user-update-groups.request.ts rename to libs/common/src/abstractions/organization-user/requests/organization-user-update-groups.request.ts diff --git a/libs/common/src/abstractions/organization-user/requests/organization-user-update.request.ts b/libs/common/src/abstractions/organization-user/requests/organization-user-update.request.ts new file mode 100644 index 0000000000..18f9fe05af --- /dev/null +++ b/libs/common/src/abstractions/organization-user/requests/organization-user-update.request.ts @@ -0,0 +1,10 @@ +import { OrganizationUserType } from "../../../enums/organizationUserType"; +import { PermissionsApi } from "../../../models/api/permissions.api"; +import { SelectionReadOnlyRequest } from "../../../models/request/selection-read-only.request"; + +export class OrganizationUserUpdateRequest { + type: OrganizationUserType; + accessAll: boolean; + collections: SelectionReadOnlyRequest[] = []; + permissions: PermissionsApi; +} diff --git a/libs/common/src/abstractions/organization-user/responses/index.ts b/libs/common/src/abstractions/organization-user/responses/index.ts new file mode 100644 index 0000000000..29c82fb18b --- /dev/null +++ b/libs/common/src/abstractions/organization-user/responses/index.ts @@ -0,0 +1,3 @@ +export * from "./organization-user.response"; +export * from "./organization-user-bulk.response"; +export * from "./organization-user-bulk-public-key.response"; diff --git a/libs/common/src/models/response/organization-user-bulk-public-key.response.ts b/libs/common/src/abstractions/organization-user/responses/organization-user-bulk-public-key.response.ts similarity index 82% rename from libs/common/src/models/response/organization-user-bulk-public-key.response.ts rename to libs/common/src/abstractions/organization-user/responses/organization-user-bulk-public-key.response.ts index ea611219a2..a0fffe9ea1 100644 --- a/libs/common/src/models/response/organization-user-bulk-public-key.response.ts +++ b/libs/common/src/abstractions/organization-user/responses/organization-user-bulk-public-key.response.ts @@ -1,4 +1,4 @@ -import { BaseResponse } from "./base.response"; +import { BaseResponse } from "../../../models/response/base.response"; export class OrganizationUserBulkPublicKeyResponse extends BaseResponse { id: string; diff --git a/libs/common/src/models/response/organization-user-bulk.response.ts b/libs/common/src/abstractions/organization-user/responses/organization-user-bulk.response.ts similarity index 78% rename from libs/common/src/models/response/organization-user-bulk.response.ts rename to libs/common/src/abstractions/organization-user/responses/organization-user-bulk.response.ts index 577c2b7dca..77a844f198 100644 --- a/libs/common/src/models/response/organization-user-bulk.response.ts +++ b/libs/common/src/abstractions/organization-user/responses/organization-user-bulk.response.ts @@ -1,4 +1,4 @@ -import { BaseResponse } from "./base.response"; +import { BaseResponse } from "../../../models/response/base.response"; export class OrganizationUserBulkResponse extends BaseResponse { id: string; diff --git a/libs/common/src/models/response/organization-user.response.ts b/libs/common/src/abstractions/organization-user/responses/organization-user.response.ts similarity index 82% rename from libs/common/src/models/response/organization-user.response.ts rename to libs/common/src/abstractions/organization-user/responses/organization-user.response.ts index 0a92a1fdce..e912a73000 100644 --- a/libs/common/src/models/response/organization-user.response.ts +++ b/libs/common/src/abstractions/organization-user/responses/organization-user.response.ts @@ -1,10 +1,9 @@ -import { KdfType } from "../../enums/kdfType"; -import { OrganizationUserStatusType } from "../../enums/organizationUserStatusType"; -import { OrganizationUserType } from "../../enums/organizationUserType"; -import { PermissionsApi } from "../api/permissions.api"; - -import { BaseResponse } from "./base.response"; -import { SelectionReadOnlyResponse } from "./selection-read-only.response"; +import { KdfType } from "../../../enums/kdfType"; +import { OrganizationUserStatusType } from "../../../enums/organizationUserStatusType"; +import { OrganizationUserType } from "../../../enums/organizationUserType"; +import { PermissionsApi } from "../../../models/api/permissions.api"; +import { BaseResponse } from "../../../models/response/base.response"; +import { SelectionReadOnlyResponse } from "../../../models/response/selection-read-only.response"; export class OrganizationUserResponse extends BaseResponse { id: string; diff --git a/libs/common/src/models/request/organization-user-invite.request.ts b/libs/common/src/models/request/organization-user-invite.request.ts deleted file mode 100644 index 90a0bff446..0000000000 --- a/libs/common/src/models/request/organization-user-invite.request.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { OrganizationUserType } from "../../enums/organizationUserType"; -import { PermissionsApi } from "../api/permissions.api"; - -import { SelectionReadOnlyRequest } from "./selection-read-only.request"; - -export class OrganizationUserInviteRequest { - emails: string[] = []; - type: OrganizationUserType; - accessAll: boolean; - collections: SelectionReadOnlyRequest[] = []; - permissions: PermissionsApi; -} diff --git a/libs/common/src/models/request/organization-user-update.request.ts b/libs/common/src/models/request/organization-user-update.request.ts deleted file mode 100644 index 5921b662c2..0000000000 --- a/libs/common/src/models/request/organization-user-update.request.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { OrganizationUserType } from "../../enums/organizationUserType"; -import { PermissionsApi } from "../api/permissions.api"; - -import { SelectionReadOnlyRequest } from "./selection-read-only.request"; - -export class OrganizationUserUpdateRequest { - type: OrganizationUserType; - accessAll: boolean; - collections: SelectionReadOnlyRequest[] = []; - permissions: PermissionsApi; -} diff --git a/libs/common/src/models/request/update-temp-password.request.ts b/libs/common/src/models/request/update-temp-password.request.ts index 1a403caff0..fa35e37f9e 100644 --- a/libs/common/src/models/request/update-temp-password.request.ts +++ b/libs/common/src/models/request/update-temp-password.request.ts @@ -1,4 +1,4 @@ -import { OrganizationUserResetPasswordRequest } from "./organization-user-reset-password.request"; +import { OrganizationUserResetPasswordRequest } from "../../abstractions/organization-user/requests"; export class UpdateTempPasswordRequest extends OrganizationUserResetPasswordRequest { masterPasswordHint: string; diff --git a/libs/common/src/models/response/provider/provider-user-bulk-public-key.response.ts b/libs/common/src/models/response/provider/provider-user-bulk-public-key.response.ts index f5bdc9fe19..39e5747ade 100644 --- a/libs/common/src/models/response/provider/provider-user-bulk-public-key.response.ts +++ b/libs/common/src/models/response/provider/provider-user-bulk-public-key.response.ts @@ -1,3 +1,3 @@ -import { OrganizationUserBulkPublicKeyResponse } from "../organization-user-bulk-public-key.response"; +import { OrganizationUserBulkPublicKeyResponse } from "../../../abstractions/organization-user/responses"; export class ProviderUserBulkPublicKeyResponse extends OrganizationUserBulkPublicKeyResponse {} diff --git a/libs/common/src/services/api.service.ts b/libs/common/src/services/api.service.ts index dddbe7a58b..42e413aebf 100644 --- a/libs/common/src/services/api.service.ts +++ b/libs/common/src/services/api.service.ts @@ -42,15 +42,6 @@ import { KeyConnectorUserKeyRequest } from "../models/request/key-connector-user import { KeysRequest } from "../models/request/keys.request"; import { OrganizationConnectionRequest } from "../models/request/organization-connection.request"; import { OrganizationImportRequest } from "../models/request/organization-import.request"; -import { OrganizationUserAcceptRequest } from "../models/request/organization-user-accept.request"; -import { OrganizationUserBulkConfirmRequest } from "../models/request/organization-user-bulk-confirm.request"; -import { OrganizationUserBulkRequest } from "../models/request/organization-user-bulk.request"; -import { OrganizationUserConfirmRequest } from "../models/request/organization-user-confirm.request"; -import { OrganizationUserInviteRequest } from "../models/request/organization-user-invite.request"; -import { OrganizationUserResetPasswordEnrollmentRequest } from "../models/request/organization-user-reset-password-enrollment.request"; -import { OrganizationUserResetPasswordRequest } from "../models/request/organization-user-reset-password.request"; -import { OrganizationUserUpdateGroupsRequest } from "../models/request/organization-user-update-groups.request"; -import { OrganizationUserUpdateRequest } from "../models/request/organization-user-update.request"; import { OrganizationSponsorshipCreateRequest } from "../models/request/organization/organization-sponsorship-create.request"; import { OrganizationSponsorshipRedeemRequest } from "../models/request/organization/organization-sponsorship-redeem.request"; import { PasswordHintRequest } from "../models/request/password-hint.request"; @@ -126,13 +117,6 @@ import { } from "../models/response/organization-connection.response"; import { OrganizationExportResponse } from "../models/response/organization-export.response"; import { OrganizationSponsorshipSyncStatusResponse } from "../models/response/organization-sponsorship-sync-status.response"; -import { OrganizationUserBulkPublicKeyResponse } from "../models/response/organization-user-bulk-public-key.response"; -import { OrganizationUserBulkResponse } from "../models/response/organization-user-bulk.response"; -import { - OrganizationUserDetailsResponse, - OrganizationUserUserDetailsResponse, - OrganizationUserResetPasswordDetailsReponse, -} from "../models/response/organization-user.response"; import { PaymentResponse } from "../models/response/payment.response"; import { PlanResponse } from "../models/response/plan.response"; import { PolicyResponse } from "../models/response/policy.response"; @@ -165,8 +149,8 @@ import { TwoFactorEmailResponse } from "../models/response/two-factor-email.resp import { TwoFactorProviderResponse } from "../models/response/two-factor-provider.response"; import { TwoFactorRecoverResponse } from "../models/response/two-factor-recover.response"; import { - TwoFactorWebAuthnResponse, ChallengeResponse, + TwoFactorWebAuthnResponse, } from "../models/response/two-factor-web-authn.response"; import { TwoFactorYubiKeyResponse } from "../models/response/two-factor-yubi-key.response"; import { UserKeyResponse } from "../models/response/user-key.response"; @@ -1016,281 +1000,6 @@ export class ApiService implements ApiServiceAbstraction { ); } - // Organization User APIs - - async getOrganizationUser( - organizationId: string, - id: string - ): Promise { - const r = await this.send( - "GET", - "/organizations/" + organizationId + "/users/" + id, - null, - true, - true - ); - return new OrganizationUserDetailsResponse(r); - } - - async getOrganizationUserGroups(organizationId: string, id: string): Promise { - const r = await this.send( - "GET", - "/organizations/" + organizationId + "/users/" + id + "/groups", - null, - true, - true - ); - return r; - } - - async getOrganizationUsers( - organizationId: string - ): Promise> { - const r = await this.send( - "GET", - "/organizations/" + organizationId + "/users", - null, - true, - true - ); - return new ListResponse(r, OrganizationUserUserDetailsResponse); - } - - async getOrganizationUserResetPasswordDetails( - organizationId: string, - id: string - ): Promise { - const r = await this.send( - "GET", - "/organizations/" + organizationId + "/users/" + id + "/reset-password-details", - null, - true, - true - ); - return new OrganizationUserResetPasswordDetailsReponse(r); - } - - postOrganizationUserInvite( - organizationId: string, - request: OrganizationUserInviteRequest - ): Promise { - return this.send( - "POST", - "/organizations/" + organizationId + "/users/invite", - request, - true, - false - ); - } - - postOrganizationUserReinvite(organizationId: string, id: string): Promise { - return this.send( - "POST", - "/organizations/" + organizationId + "/users/" + id + "/reinvite", - null, - true, - false - ); - } - - async postManyOrganizationUserReinvite( - organizationId: string, - request: OrganizationUserBulkRequest - ): Promise> { - const r = await this.send( - "POST", - "/organizations/" + organizationId + "/users/reinvite", - request, - true, - true - ); - return new ListResponse(r, OrganizationUserBulkResponse); - } - - postOrganizationUserAccept( - organizationId: string, - id: string, - request: OrganizationUserAcceptRequest - ): Promise { - return this.send( - "POST", - "/organizations/" + organizationId + "/users/" + id + "/accept", - request, - true, - false - ); - } - - postOrganizationUserConfirm( - organizationId: string, - id: string, - request: OrganizationUserConfirmRequest - ): Promise { - return this.send( - "POST", - "/organizations/" + organizationId + "/users/" + id + "/confirm", - request, - true, - false - ); - } - - async postOrganizationUsersPublicKey( - organizationId: string, - request: OrganizationUserBulkRequest - ): Promise> { - const r = await this.send( - "POST", - "/organizations/" + organizationId + "/users/public-keys", - request, - true, - true - ); - return new ListResponse(r, OrganizationUserBulkPublicKeyResponse); - } - - async postOrganizationUserBulkConfirm( - organizationId: string, - request: OrganizationUserBulkConfirmRequest - ): Promise> { - const r = await this.send( - "POST", - "/organizations/" + organizationId + "/users/confirm", - request, - true, - true - ); - return new ListResponse(r, OrganizationUserBulkResponse); - } - - putOrganizationUser( - organizationId: string, - id: string, - request: OrganizationUserUpdateRequest - ): Promise { - return this.send( - "PUT", - "/organizations/" + organizationId + "/users/" + id, - request, - true, - false - ); - } - - putOrganizationUserGroups( - organizationId: string, - id: string, - request: OrganizationUserUpdateGroupsRequest - ): Promise { - return this.send( - "PUT", - "/organizations/" + organizationId + "/users/" + id + "/groups", - request, - true, - false - ); - } - - putOrganizationUserResetPasswordEnrollment( - organizationId: string, - userId: string, - request: OrganizationUserResetPasswordEnrollmentRequest - ): Promise { - return this.send( - "PUT", - "/organizations/" + organizationId + "/users/" + userId + "/reset-password-enrollment", - request, - true, - false - ); - } - - putOrganizationUserResetPassword( - organizationId: string, - id: string, - request: OrganizationUserResetPasswordRequest - ): Promise { - return this.send( - "PUT", - "/organizations/" + organizationId + "/users/" + id + "/reset-password", - request, - true, - false - ); - } - - deleteOrganizationUser(organizationId: string, id: string): Promise { - return this.send( - "DELETE", - "/organizations/" + organizationId + "/users/" + id, - null, - true, - false - ); - } - - async deleteManyOrganizationUsers( - organizationId: string, - request: OrganizationUserBulkRequest - ): Promise> { - const r = await this.send( - "DELETE", - "/organizations/" + organizationId + "/users", - request, - true, - true - ); - return new ListResponse(r, OrganizationUserBulkResponse); - } - - revokeOrganizationUser(organizationId: string, id: string): Promise { - return this.send( - "PUT", - "/organizations/" + organizationId + "/users/" + id + "/revoke", - null, - true, - false - ); - } - - async revokeManyOrganizationUsers( - organizationId: string, - request: OrganizationUserBulkRequest - ): Promise> { - const r = await this.send( - "PUT", - "/organizations/" + organizationId + "/users/revoke", - request, - true, - true - ); - return new ListResponse(r, OrganizationUserBulkResponse); - } - - restoreOrganizationUser(organizationId: string, id: string): Promise { - return this.send( - "PUT", - "/organizations/" + organizationId + "/users/" + id + "/restore", - null, - true, - false - ); - } - - async restoreManyOrganizationUsers( - organizationId: string, - request: OrganizationUserBulkRequest - ): Promise> { - const r = await this.send( - "PUT", - "/organizations/" + organizationId + "/users/restore", - request, - true, - true - ); - return new ListResponse(r, OrganizationUserBulkResponse); - } - // Plan APIs async getPlans(): Promise> { diff --git a/libs/common/src/services/organization-user/organization-user.service.implementation.ts b/libs/common/src/services/organization-user/organization-user.service.implementation.ts new file mode 100644 index 0000000000..af243143ed --- /dev/null +++ b/libs/common/src/services/organization-user/organization-user.service.implementation.ts @@ -0,0 +1,299 @@ +import { ApiService } from "../../abstractions/api.service"; +import { OrganizationUserService } from "../../abstractions/organization-user/organization-user.service"; +import { + OrganizationUserAcceptRequest, + OrganizationUserBulkConfirmRequest, + OrganizationUserConfirmRequest, + OrganizationUserInviteRequest, + OrganizationUserResetPasswordEnrollmentRequest, + OrganizationUserResetPasswordRequest, + OrganizationUserUpdateGroupsRequest, + OrganizationUserUpdateRequest, +} from "../../abstractions/organization-user/requests"; +import { + OrganizationUserBulkPublicKeyResponse, + OrganizationUserBulkResponse, + OrganizationUserDetailsResponse, + OrganizationUserResetPasswordDetailsReponse, + OrganizationUserUserDetailsResponse, +} from "../../abstractions/organization-user/responses"; +import { ListResponse } from "../../models/response/list.response"; + +import { OrganizationUserBulkRequest } from "./requests"; + +export class OrganizationUserServiceImplementation implements OrganizationUserService { + constructor(private apiService: ApiService) {} + + async getOrganizationUser( + organizationId: string, + id: string + ): Promise { + const r = await this.apiService.send( + "GET", + "/organizations/" + organizationId + "/users/" + id, + null, + true, + true + ); + return new OrganizationUserDetailsResponse(r); + } + + async getOrganizationUserGroups(organizationId: string, id: string): Promise { + const r = await this.apiService.send( + "GET", + "/organizations/" + organizationId + "/users/" + id + "/groups", + null, + true, + true + ); + return r; + } + + async getAllUsers( + organizationId: string + ): Promise> { + const r = await this.apiService.send( + "GET", + "/organizations/" + organizationId + "/users", + null, + true, + true + ); + return new ListResponse(r, OrganizationUserUserDetailsResponse); + } + + async getOrganizationUserResetPasswordDetails( + organizationId: string, + id: string + ): Promise { + const r = await this.apiService.send( + "GET", + "/organizations/" + organizationId + "/users/" + id + "/reset-password-details", + null, + true, + true + ); + return new OrganizationUserResetPasswordDetailsReponse(r); + } + + postOrganizationUserInvite( + organizationId: string, + request: OrganizationUserInviteRequest + ): Promise { + return this.apiService.send( + "POST", + "/organizations/" + organizationId + "/users/invite", + request, + true, + false + ); + } + + postOrganizationUserReinvite(organizationId: string, id: string): Promise { + return this.apiService.send( + "POST", + "/organizations/" + organizationId + "/users/" + id + "/reinvite", + null, + true, + false + ); + } + + async postManyOrganizationUserReinvite( + organizationId: string, + ids: string[] + ): Promise> { + const r = await this.apiService.send( + "POST", + "/organizations/" + organizationId + "/users/reinvite", + new OrganizationUserBulkRequest(ids), + true, + true + ); + return new ListResponse(r, OrganizationUserBulkResponse); + } + + postOrganizationUserAccept( + organizationId: string, + id: string, + request: OrganizationUserAcceptRequest + ): Promise { + return this.apiService.send( + "POST", + "/organizations/" + organizationId + "/users/" + id + "/accept", + request, + true, + false + ); + } + + postOrganizationUserConfirm( + organizationId: string, + id: string, + request: OrganizationUserConfirmRequest + ): Promise { + return this.apiService.send( + "POST", + "/organizations/" + organizationId + "/users/" + id + "/confirm", + request, + true, + false + ); + } + + async postOrganizationUsersPublicKey( + organizationId: string, + ids: string[] + ): Promise> { + const r = await this.apiService.send( + "POST", + "/organizations/" + organizationId + "/users/public-keys", + new OrganizationUserBulkRequest(ids), + true, + true + ); + return new ListResponse(r, OrganizationUserBulkPublicKeyResponse); + } + + async postOrganizationUserBulkConfirm( + organizationId: string, + request: OrganizationUserBulkConfirmRequest + ): Promise> { + const r = await this.apiService.send( + "POST", + "/organizations/" + organizationId + "/users/confirm", + request, + true, + true + ); + return new ListResponse(r, OrganizationUserBulkResponse); + } + + putOrganizationUser( + organizationId: string, + id: string, + request: OrganizationUserUpdateRequest + ): Promise { + return this.apiService.send( + "PUT", + "/organizations/" + organizationId + "/users/" + id, + request, + true, + false + ); + } + + putOrganizationUserGroups( + organizationId: string, + id: string, + request: OrganizationUserUpdateGroupsRequest + ): Promise { + return this.apiService.send( + "PUT", + "/organizations/" + organizationId + "/users/" + id + "/groups", + request, + true, + false + ); + } + + putOrganizationUserResetPasswordEnrollment( + organizationId: string, + userId: string, + request: OrganizationUserResetPasswordEnrollmentRequest + ): Promise { + return this.apiService.send( + "PUT", + "/organizations/" + organizationId + "/users/" + userId + "/reset-password-enrollment", + request, + true, + false + ); + } + + putOrganizationUserResetPassword( + organizationId: string, + id: string, + request: OrganizationUserResetPasswordRequest + ): Promise { + return this.apiService.send( + "PUT", + "/organizations/" + organizationId + "/users/" + id + "/reset-password", + request, + true, + false + ); + } + + deleteOrganizationUser(organizationId: string, id: string): Promise { + return this.apiService.send( + "DELETE", + "/organizations/" + organizationId + "/users/" + id, + null, + true, + false + ); + } + + async deleteManyOrganizationUsers( + organizationId: string, + ids: string[] + ): Promise> { + const r = await this.apiService.send( + "DELETE", + "/organizations/" + organizationId + "/users", + new OrganizationUserBulkRequest(ids), + true, + true + ); + return new ListResponse(r, OrganizationUserBulkResponse); + } + + revokeOrganizationUser(organizationId: string, id: string): Promise { + return this.apiService.send( + "PUT", + "/organizations/" + organizationId + "/users/" + id + "/revoke", + null, + true, + false + ); + } + + async revokeManyOrganizationUsers( + organizationId: string, + ids: string[] + ): Promise> { + const r = await this.apiService.send( + "PUT", + "/organizations/" + organizationId + "/users/revoke", + new OrganizationUserBulkRequest(ids), + true, + true + ); + return new ListResponse(r, OrganizationUserBulkResponse); + } + + restoreOrganizationUser(organizationId: string, id: string): Promise { + return this.apiService.send( + "PUT", + "/organizations/" + organizationId + "/users/" + id + "/restore", + null, + true, + false + ); + } + + async restoreManyOrganizationUsers( + organizationId: string, + ids: string[] + ): Promise> { + const r = await this.apiService.send( + "PUT", + "/organizations/" + organizationId + "/users/restore", + new OrganizationUserBulkRequest(ids), + true, + true + ); + return new ListResponse(r, OrganizationUserBulkResponse); + } +} diff --git a/libs/common/src/services/organization-user/requests/index.ts b/libs/common/src/services/organization-user/requests/index.ts new file mode 100644 index 0000000000..4daafb4c6a --- /dev/null +++ b/libs/common/src/services/organization-user/requests/index.ts @@ -0,0 +1 @@ +export * from "./organization-user-bulk.request"; diff --git a/libs/common/src/models/request/organization-user-bulk.request.ts b/libs/common/src/services/organization-user/requests/organization-user-bulk.request.ts similarity index 100% rename from libs/common/src/models/request/organization-user-bulk.request.ts rename to libs/common/src/services/organization-user/requests/organization-user-bulk.request.ts