2021-06-07 20:13:58 +02:00
|
|
|
import { Component, OnInit, ViewChild, ViewContainerRef } from "@angular/core";
|
2021-06-02 18:35:49 +02:00
|
|
|
import { ActivatedRoute, Router } from "@angular/router";
|
2022-02-24 12:10:07 +01:00
|
|
|
import { first } from "rxjs/operators";
|
2018-07-06 21:01:23 +02:00
|
|
|
|
2022-06-14 17:10:53 +02:00
|
|
|
import { SearchPipe } from "@bitwarden/angular/pipes/search.pipe";
|
|
|
|
import { UserNamePipe } from "@bitwarden/angular/pipes/user-name.pipe";
|
|
|
|
import { ModalService } from "@bitwarden/angular/services/modal.service";
|
|
|
|
import { ValidationService } from "@bitwarden/angular/services/validation.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 { OrganizationService } from "@bitwarden/common/abstractions/organization.service";
|
2022-08-24 18:33:05 +02:00
|
|
|
import { OrganizationApiServiceAbstraction } from "@bitwarden/common/abstractions/organization/organization-api.service.abstraction";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
|
2022-08-08 11:04:36 +02:00
|
|
|
import { PolicyApiServiceAbstraction } from "@bitwarden/common/abstractions/policy/policy-api.service.abstraction";
|
|
|
|
import { PolicyService } from "@bitwarden/common/abstractions/policy/policy.service.abstraction";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { SearchService } from "@bitwarden/common/abstractions/search.service";
|
|
|
|
import { StateService } from "@bitwarden/common/abstractions/state.service";
|
|
|
|
import { SyncService } from "@bitwarden/common/abstractions/sync.service";
|
|
|
|
import { OrganizationUserStatusType } from "@bitwarden/common/enums/organizationUserStatusType";
|
|
|
|
import { OrganizationUserType } from "@bitwarden/common/enums/organizationUserType";
|
|
|
|
import { PolicyType } from "@bitwarden/common/enums/policyType";
|
|
|
|
import { OrganizationKeysRequest } from "@bitwarden/common/models/request/organizationKeysRequest";
|
|
|
|
import { OrganizationUserBulkRequest } from "@bitwarden/common/models/request/organizationUserBulkRequest";
|
|
|
|
import { OrganizationUserConfirmRequest } from "@bitwarden/common/models/request/organizationUserConfirmRequest";
|
|
|
|
import { ListResponse } from "@bitwarden/common/models/response/listResponse";
|
|
|
|
import { OrganizationUserBulkResponse } from "@bitwarden/common/models/response/organizationUserBulkResponse";
|
|
|
|
import { OrganizationUserUserDetailsResponse } from "@bitwarden/common/models/response/organizationUserResponse";
|
2018-07-09 23:07:13 +02:00
|
|
|
|
2021-06-02 18:35:49 +02:00
|
|
|
import { BasePeopleComponent } from "../../common/base.people.component";
|
2022-02-24 12:10:07 +01:00
|
|
|
|
2021-06-09 17:04:21 +02:00
|
|
|
import { BulkConfirmComponent } from "./bulk/bulk-confirm.component";
|
2021-06-02 18:35:49 +02:00
|
|
|
import { BulkRemoveComponent } from "./bulk/bulk-remove.component";
|
2022-07-25 02:47:56 +02:00
|
|
|
import { BulkRestoreRevokeComponent } from "./bulk/bulk-restore-revoke.component";
|
2021-06-02 18:35:49 +02:00
|
|
|
import { BulkStatusComponent } from "./bulk/bulk-status.component";
|
|
|
|
import { EntityEventsComponent } from "./entity-events.component";
|
|
|
|
import { ResetPasswordComponent } from "./reset-password.component";
|
|
|
|
import { UserAddEditComponent } from "./user-add-edit.component";
|
|
|
|
import { UserGroupsComponent } from "./user-groups.component";
|
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
@Component({
|
|
|
|
selector: "app-org-people",
|
2018-07-06 16:21:08 +02:00
|
|
|
templateUrl: "people.component.html",
|
2021-08-27 14:50:58 +02:00
|
|
|
})
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
|
2021-07-21 11:32:27 +02:00
|
|
|
export class PeopleComponent
|
2021-08-27 14:50:58 +02:00
|
|
|
extends BasePeopleComponent<OrganizationUserUserDetailsResponse>
|
|
|
|
implements OnInit
|
2021-12-17 15:57:11 +01:00
|
|
|
{
|
2021-08-27 14:50:58 +02:00
|
|
|
@ViewChild("addEdit", { read: ViewContainerRef, static: true }) addEditModalRef: ViewContainerRef;
|
2020-08-17 16:04:38 +02:00
|
|
|
@ViewChild("groupsTemplate", { read: ViewContainerRef, static: true })
|
|
|
|
groupsModalRef: ViewContainerRef;
|
2021-08-27 14:50:58 +02:00
|
|
|
@ViewChild("eventsTemplate", { read: ViewContainerRef, static: true })
|
2020-08-17 16:04:38 +02:00
|
|
|
eventsModalRef: ViewContainerRef;
|
|
|
|
@ViewChild("confirmTemplate", { read: ViewContainerRef, static: true })
|
2021-08-27 14:50:58 +02:00
|
|
|
confirmModalRef: ViewContainerRef;
|
2021-06-02 18:35:49 +02:00
|
|
|
@ViewChild("resetPasswordTemplate", { read: ViewContainerRef, static: true })
|
|
|
|
resetPasswordModalRef: ViewContainerRef;
|
2021-05-25 19:24:09 +02:00
|
|
|
@ViewChild("bulkStatusTemplate", { read: ViewContainerRef, static: true })
|
|
|
|
bulkStatusModalRef: ViewContainerRef;
|
2021-06-09 17:04:21 +02:00
|
|
|
@ViewChild("bulkConfirmTemplate", { read: ViewContainerRef, static: true })
|
|
|
|
bulkConfirmModalRef: ViewContainerRef;
|
|
|
|
@ViewChild("bulkRemoveTemplate", { read: ViewContainerRef, static: true })
|
|
|
|
bulkRemoveModalRef: ViewContainerRef;
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
userType = OrganizationUserType;
|
2021-07-21 11:32:27 +02:00
|
|
|
userStatusType = OrganizationUserStatusType;
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2018-07-06 21:01:23 +02:00
|
|
|
organizationId: string;
|
2018-07-11 22:40:32 +02:00
|
|
|
status: OrganizationUserStatusType = null;
|
2018-07-11 20:43:00 +02:00
|
|
|
accessEvents = false;
|
|
|
|
accessGroups = false;
|
2021-08-27 14:50:58 +02:00
|
|
|
canResetPassword = false; // User permission (admin/custom)
|
2021-06-02 18:35:49 +02:00
|
|
|
orgUseResetPassword = false; // Org plan ability
|
|
|
|
orgHasKeys = false; // Org public/private keys
|
2021-08-27 14:50:58 +02:00
|
|
|
orgResetPasswordPolicyEnabled = false;
|
2021-06-02 18:35:49 +02:00
|
|
|
callingUserType: OrganizationUserType = null;
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
constructor(
|
|
|
|
apiService: ApiService,
|
2021-12-14 17:10:26 +01:00
|
|
|
private route: ActivatedRoute,
|
|
|
|
i18nService: I18nService,
|
2021-08-27 14:50:58 +02:00
|
|
|
modalService: ModalService,
|
|
|
|
platformUtilsService: PlatformUtilsService,
|
|
|
|
cryptoService: CryptoService,
|
|
|
|
private router: Router,
|
2021-12-14 17:10:26 +01:00
|
|
|
searchService: SearchService,
|
2021-08-27 14:50:58 +02:00
|
|
|
validationService: ValidationService,
|
2022-08-08 11:04:36 +02:00
|
|
|
private policyApiService: PolicyApiServiceAbstraction,
|
2021-12-14 17:10:26 +01:00
|
|
|
private policyService: PolicyService,
|
|
|
|
logService: LogService,
|
|
|
|
searchPipe: SearchPipe,
|
2021-08-27 14:50:58 +02:00
|
|
|
userNamePipe: UserNamePipe,
|
2021-12-14 17:10:26 +01:00
|
|
|
private syncService: SyncService,
|
|
|
|
stateService: StateService,
|
2022-08-24 18:33:05 +02:00
|
|
|
private organizationService: OrganizationService,
|
|
|
|
private organizationApiService: OrganizationApiServiceAbstraction
|
2021-12-17 15:57:11 +01:00
|
|
|
) {
|
|
|
|
super(
|
2021-12-14 17:10:26 +01:00
|
|
|
apiService,
|
|
|
|
searchService,
|
|
|
|
i18nService,
|
|
|
|
platformUtilsService,
|
|
|
|
cryptoService,
|
|
|
|
validationService,
|
|
|
|
modalService,
|
|
|
|
logService,
|
|
|
|
searchPipe,
|
|
|
|
userNamePipe,
|
|
|
|
stateService
|
2021-08-27 14:50:58 +02:00
|
|
|
);
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2018-07-06 21:01:23 +02:00
|
|
|
async ngOnInit() {
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe
|
2021-08-27 14:50:58 +02:00
|
|
|
this.route.parent.parent.params.subscribe(async (params) => {
|
|
|
|
this.organizationId = params.organizationId;
|
|
|
|
const organization = await this.organizationService.get(this.organizationId);
|
2018-07-11 20:43:00 +02:00
|
|
|
this.accessEvents = organization.useEvents;
|
|
|
|
this.accessGroups = organization.useGroups;
|
2021-08-27 14:50:58 +02:00
|
|
|
this.canResetPassword = organization.canManageUsersPassword;
|
|
|
|
this.orgUseResetPassword = organization.useResetPassword;
|
2021-06-02 18:35:49 +02:00
|
|
|
this.callingUserType = organization.type;
|
2021-07-02 22:23:04 +02:00
|
|
|
this.orgHasKeys = organization.hasPublicAndPrivateKeys;
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
// Backfill pub/priv key if necessary
|
2021-11-22 18:39:20 +01:00
|
|
|
if (this.canResetPassword && !this.orgHasKeys) {
|
|
|
|
const orgShareKey = await this.cryptoService.getOrgKey(this.organizationId);
|
|
|
|
const orgKeys = await this.cryptoService.makeKeyPair(orgShareKey);
|
|
|
|
const request = new OrganizationKeysRequest(orgKeys[0], orgKeys[1].encryptedString);
|
2022-08-24 18:33:05 +02:00
|
|
|
const response = await this.organizationApiService.updateKeys(this.organizationId, request);
|
2021-08-27 14:50:58 +02:00
|
|
|
if (response != null) {
|
|
|
|
this.orgHasKeys = response.publicKey != null && response.privateKey != null;
|
|
|
|
await this.syncService.fullSync(true); // Replace oganizations with new data
|
|
|
|
} else {
|
|
|
|
throw new Error(this.i18nService.t("resetPasswordOrgKeysError"));
|
2018-07-09 23:07:13 +02:00
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2018-07-09 23:07:13 +02:00
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
await this.load();
|
2018-07-10 21:03:13 +02:00
|
|
|
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe, rxjs/no-nested-subscribe
|
2021-05-18 10:27:52 +02:00
|
|
|
this.route.queryParams.pipe(first()).subscribe(async (qParams) => {
|
|
|
|
this.searchText = qParams.search;
|
|
|
|
if (qParams.viewEvents != null) {
|
|
|
|
const user = this.users.filter((u) => u.id === qParams.viewEvents);
|
|
|
|
if (user.length > 0 && user[0].status === OrganizationUserStatusType.Confirmed) {
|
|
|
|
this.events(user[0]);
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2021-05-18 10:27:52 +02:00
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-07-06 21:01:23 +02:00
|
|
|
async load() {
|
2022-08-08 11:04:36 +02:00
|
|
|
const resetPasswordPolicy = await this.policyApiService.getPolicyForOrganization(
|
2021-09-01 23:51:04 +02:00
|
|
|
PolicyType.ResetPassword,
|
2018-07-06 21:01:23 +02:00
|
|
|
this.organizationId
|
2021-12-17 15:57:11 +01:00
|
|
|
);
|
2021-09-01 23:51:04 +02:00
|
|
|
this.orgResetPasswordPolicyEnabled = resetPasswordPolicy?.enabled;
|
2021-07-21 11:32:27 +02:00
|
|
|
super.load();
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2021-05-25 19:24:09 +02:00
|
|
|
getUsers(): Promise<ListResponse<OrganizationUserUserDetailsResponse>> {
|
2021-07-21 11:32:27 +02:00
|
|
|
return this.apiService.getOrganizationUsers(this.organizationId);
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2022-08-24 18:33:05 +02:00
|
|
|
deleteUser(id: string): Promise<void> {
|
2021-07-21 11:32:27 +02:00
|
|
|
return this.apiService.deleteOrganizationUser(this.organizationId, id);
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2022-08-24 18:33:05 +02:00
|
|
|
revokeUser(id: string): Promise<void> {
|
2022-07-25 02:47:56 +02:00
|
|
|
return this.apiService.revokeOrganizationUser(this.organizationId, id);
|
2022-06-20 16:21:50 +02:00
|
|
|
}
|
|
|
|
|
2022-08-24 18:33:05 +02:00
|
|
|
restoreUser(id: string): Promise<void> {
|
2022-07-25 02:47:56 +02:00
|
|
|
return this.apiService.restoreOrganizationUser(this.organizationId, id);
|
2022-06-20 16:21:50 +02:00
|
|
|
}
|
|
|
|
|
2022-08-24 18:33:05 +02:00
|
|
|
reinviteUser(id: string): Promise<void> {
|
2021-05-25 19:24:09 +02:00
|
|
|
return this.apiService.postOrganizationUserReinvite(this.organizationId, id);
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2021-07-21 11:32:27 +02:00
|
|
|
async confirmUser(
|
2021-06-02 18:35:49 +02:00
|
|
|
user: OrganizationUserUserDetailsResponse,
|
2021-07-21 11:32:27 +02:00
|
|
|
publicKey: Uint8Array
|
2022-08-24 18:33:05 +02:00
|
|
|
): Promise<void> {
|
2021-07-21 11:32:27 +02:00
|
|
|
const orgKey = await this.cryptoService.getOrgKey(this.organizationId);
|
|
|
|
const key = await this.cryptoService.rsaEncrypt(orgKey.key, publicKey.buffer);
|
|
|
|
const request = new OrganizationUserConfirmRequest();
|
|
|
|
request.key = key.encryptedString;
|
|
|
|
await this.apiService.postOrganizationUserConfirm(this.organizationId, user.id, request);
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2021-06-02 18:35:49 +02:00
|
|
|
allowResetPassword(orgUser: OrganizationUserUserDetailsResponse): boolean {
|
|
|
|
// Hierarchy check
|
|
|
|
let callingUserHasPermission = false;
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2021-06-02 18:35:49 +02:00
|
|
|
switch (this.callingUserType) {
|
|
|
|
case OrganizationUserType.Owner:
|
|
|
|
callingUserHasPermission = true;
|
2021-12-17 15:57:11 +01:00
|
|
|
break;
|
2021-06-02 18:35:49 +02:00
|
|
|
case OrganizationUserType.Admin:
|
|
|
|
callingUserHasPermission = orgUser.type !== OrganizationUserType.Owner;
|
2021-12-17 15:57:11 +01:00
|
|
|
break;
|
2021-06-02 18:35:49 +02:00
|
|
|
case OrganizationUserType.Custom:
|
|
|
|
callingUserHasPermission =
|
|
|
|
orgUser.type !== OrganizationUserType.Owner &&
|
|
|
|
orgUser.type !== OrganizationUserType.Admin;
|
2021-12-17 15:57:11 +01:00
|
|
|
break;
|
|
|
|
}
|
2021-05-18 10:27:52 +02:00
|
|
|
|
2021-12-17 15:57:11 +01:00
|
|
|
// Final
|
2021-08-27 14:50:58 +02:00
|
|
|
return (
|
|
|
|
this.canResetPassword &&
|
|
|
|
callingUserHasPermission &&
|
2021-06-02 18:35:49 +02:00
|
|
|
this.orgUseResetPassword &&
|
|
|
|
this.orgHasKeys &&
|
|
|
|
orgUser.resetPasswordEnrolled &&
|
2021-08-27 14:50:58 +02:00
|
|
|
this.orgResetPasswordPolicyEnabled &&
|
|
|
|
orgUser.status === OrganizationUserStatusType.Confirmed
|
2021-12-17 15:57:11 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
showEnrolledStatus(orgUser: OrganizationUserUserDetailsResponse): boolean {
|
2021-12-17 15:57:11 +01:00
|
|
|
return (
|
2021-06-02 18:35:49 +02:00
|
|
|
this.orgUseResetPassword &&
|
|
|
|
orgUser.resetPasswordEnrolled &&
|
|
|
|
this.orgResetPasswordPolicyEnabled
|
2021-12-17 15:57:11 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-07-11 19:30:17 +02:00
|
|
|
async edit(user: OrganizationUserUserDetailsResponse) {
|
2021-08-27 14:50:58 +02:00
|
|
|
const [modal] = await this.modalService.openViewRef(
|
|
|
|
UserAddEditComponent,
|
|
|
|
this.addEditModalRef,
|
|
|
|
(comp) => {
|
|
|
|
comp.name = this.userNamePipe.transform(user);
|
|
|
|
comp.organizationId = this.organizationId;
|
|
|
|
comp.organizationUserId = user != null ? user.id : null;
|
|
|
|
comp.usesKeyConnector = user?.usesKeyConnector;
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
|
2021-08-27 14:50:58 +02:00
|
|
|
comp.onSavedUser.subscribe(() => {
|
|
|
|
modal.close();
|
|
|
|
this.load();
|
2021-06-09 17:04:21 +02:00
|
|
|
});
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
|
2021-08-27 14:50:58 +02:00
|
|
|
comp.onDeletedUser.subscribe(() => {
|
|
|
|
modal.close();
|
2021-11-19 15:13:55 +01:00
|
|
|
this.removeUser(user);
|
2021-12-17 15:57:11 +01:00
|
|
|
});
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
|
2022-07-25 02:47:56 +02:00
|
|
|
comp.onRevokedUser.subscribe(() => {
|
2022-06-20 16:21:50 +02:00
|
|
|
modal.close();
|
|
|
|
this.load();
|
|
|
|
});
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
|
2022-07-25 02:47:56 +02:00
|
|
|
comp.onRestoredUser.subscribe(() => {
|
2022-06-20 16:21:50 +02:00
|
|
|
modal.close();
|
|
|
|
this.load();
|
|
|
|
});
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
async groups(user: OrganizationUserUserDetailsResponse) {
|
|
|
|
const [modal] = await this.modalService.openViewRef(
|
|
|
|
UserGroupsComponent,
|
|
|
|
this.groupsModalRef,
|
2021-12-17 15:57:11 +01:00
|
|
|
(comp) => {
|
2021-08-27 14:50:58 +02:00
|
|
|
comp.name = this.userNamePipe.transform(user);
|
|
|
|
comp.organizationId = this.organizationId;
|
|
|
|
comp.organizationUserId = user != null ? user.id : null;
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
|
2021-08-27 14:50:58 +02:00
|
|
|
comp.onSavedUser.subscribe(() => {
|
|
|
|
modal.close();
|
2021-12-17 15:57:11 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2021-08-27 14:50:58 +02:00
|
|
|
|
|
|
|
async bulkRemove() {
|
|
|
|
if (this.actionPromise != null) {
|
|
|
|
return;
|
2021-05-18 10:27:52 +02:00
|
|
|
}
|
|
|
|
|
2021-05-25 19:24:09 +02:00
|
|
|
const [modal] = await this.modalService.openViewRef(
|
|
|
|
BulkRemoveComponent,
|
2021-12-07 20:41:45 +01:00
|
|
|
this.bulkRemoveModalRef,
|
2021-05-12 16:38:17 +02:00
|
|
|
(comp) => {
|
2021-05-25 19:24:09 +02:00
|
|
|
comp.organizationId = this.organizationId;
|
|
|
|
comp.users = this.getCheckedUsers();
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2021-05-25 19:24:09 +02:00
|
|
|
await modal.onClosedPromise();
|
|
|
|
await this.load();
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2022-07-25 02:47:56 +02:00
|
|
|
async bulkRevoke() {
|
|
|
|
await this.bulkRevokeOrRestore(true);
|
2022-06-20 16:21:50 +02:00
|
|
|
}
|
|
|
|
|
2022-07-25 02:47:56 +02:00
|
|
|
async bulkRestore() {
|
|
|
|
await this.bulkRevokeOrRestore(false);
|
2022-06-20 16:21:50 +02:00
|
|
|
}
|
|
|
|
|
2022-07-25 02:47:56 +02:00
|
|
|
async bulkRevokeOrRestore(isRevoking: boolean) {
|
2022-06-20 16:21:50 +02:00
|
|
|
if (this.actionPromise != null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-25 02:47:56 +02:00
|
|
|
const ref = this.modalService.open(BulkRestoreRevokeComponent, {
|
2022-06-20 16:21:50 +02:00
|
|
|
allowMultipleModals: true,
|
|
|
|
data: {
|
|
|
|
organizationId: this.organizationId,
|
|
|
|
users: this.getCheckedUsers(),
|
2022-07-25 02:47:56 +02:00
|
|
|
isRevoking: isRevoking,
|
2022-06-20 16:21:50 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
await ref.onClosedPromise();
|
|
|
|
await this.load();
|
|
|
|
}
|
|
|
|
|
2021-05-25 19:24:09 +02:00
|
|
|
async bulkReinvite() {
|
2021-05-12 16:38:17 +02:00
|
|
|
if (this.actionPromise != null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
const users = this.getCheckedUsers();
|
2021-05-25 19:24:09 +02:00
|
|
|
const filteredUsers = users.filter((u) => u.status === OrganizationUserStatusType.Invited);
|
2021-08-27 14:50:58 +02:00
|
|
|
|
|
|
|
if (filteredUsers.length <= 0) {
|
|
|
|
this.platformUtilsService.showToast(
|
2021-12-17 15:57:11 +01:00
|
|
|
"error",
|
2021-12-07 20:41:45 +01:00
|
|
|
this.i18nService.t("errorOccurred"),
|
2021-05-12 16:38:17 +02:00
|
|
|
this.i18nService.t("noSelectedUsersApplicable")
|
2021-08-27 14:50:58 +02:00
|
|
|
);
|
2021-12-17 15:57:11 +01:00
|
|
|
return;
|
2021-06-09 17:04:21 +02:00
|
|
|
}
|
2021-05-25 19:24:09 +02:00
|
|
|
|
2018-07-11 19:30:17 +02:00
|
|
|
try {
|
|
|
|
const request = new OrganizationUserBulkRequest(filteredUsers.map((user) => user.id));
|
2021-08-27 14:50:58 +02:00
|
|
|
const response = this.apiService.postManyOrganizationUserReinvite(
|
|
|
|
this.organizationId,
|
2021-12-17 15:57:11 +01:00
|
|
|
request
|
2021-08-27 14:50:58 +02:00
|
|
|
);
|
|
|
|
this.showBulkStatus(
|
|
|
|
users,
|
2021-05-25 19:24:09 +02:00
|
|
|
filteredUsers,
|
2021-12-17 15:57:11 +01:00
|
|
|
response,
|
2021-08-27 14:50:58 +02:00
|
|
|
this.i18nService.t("bulkReinviteMessage")
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
this.validationService.showError(e);
|
2018-07-11 19:30:17 +02:00
|
|
|
}
|
2021-05-25 19:24:09 +02:00
|
|
|
this.actionPromise = null;
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2018-07-11 19:30:17 +02:00
|
|
|
|
2021-06-02 18:35:49 +02:00
|
|
|
async bulkConfirm() {
|
2021-08-27 14:50:58 +02:00
|
|
|
if (this.actionPromise != null) {
|
|
|
|
return;
|
2021-06-02 18:35:49 +02:00
|
|
|
}
|
|
|
|
|
2021-11-19 15:13:55 +01:00
|
|
|
const [modal] = await this.modalService.openViewRef(
|
2021-08-27 14:50:58 +02:00
|
|
|
BulkConfirmComponent,
|
|
|
|
this.bulkConfirmModalRef,
|
2021-12-17 15:57:11 +01:00
|
|
|
(comp) => {
|
2021-11-19 15:13:55 +01:00
|
|
|
comp.organizationId = this.organizationId;
|
|
|
|
comp.users = this.getCheckedUsers();
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2021-11-19 15:13:55 +01:00
|
|
|
await modal.onClosedPromise();
|
2018-07-07 05:08:10 +02:00
|
|
|
await this.load();
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2021-11-19 15:13:55 +01:00
|
|
|
async events(user: OrganizationUserUserDetailsResponse) {
|
2022-02-24 12:10:07 +01:00
|
|
|
await this.modalService.openViewRef(EntityEventsComponent, this.eventsModalRef, (comp) => {
|
|
|
|
comp.name = this.userNamePipe.transform(user);
|
|
|
|
comp.organizationId = this.organizationId;
|
|
|
|
comp.entityId = user.id;
|
|
|
|
comp.showUser = false;
|
|
|
|
comp.entity = "user";
|
|
|
|
});
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2021-11-19 15:13:55 +01:00
|
|
|
async resetPassword(user: OrganizationUserUserDetailsResponse) {
|
|
|
|
const [modal] = await this.modalService.openViewRef(
|
|
|
|
ResetPasswordComponent,
|
2021-08-27 14:50:58 +02:00
|
|
|
this.resetPasswordModalRef,
|
2021-12-17 15:57:11 +01:00
|
|
|
(comp) => {
|
2021-11-19 15:13:55 +01:00
|
|
|
comp.name = this.userNamePipe.transform(user);
|
|
|
|
comp.email = user != null ? user.email : null;
|
|
|
|
comp.organizationId = this.organizationId;
|
|
|
|
comp.id = user != null ? user.id : null;
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
|
2021-08-27 14:50:58 +02:00
|
|
|
comp.onPasswordReset.subscribe(() => {
|
|
|
|
modal.close();
|
|
|
|
this.load();
|
2021-12-17 15:57:11 +01:00
|
|
|
});
|
2021-11-19 15:13:55 +01:00
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
);
|
|
|
|
}
|
2021-11-19 15:13:55 +01:00
|
|
|
|
2022-07-20 03:41:27 +02:00
|
|
|
protected async removeUserConfirmationDialog(user: OrganizationUserUserDetailsResponse) {
|
|
|
|
const warningMessage = user.usesKeyConnector
|
|
|
|
? this.i18nService.t("removeUserConfirmationKeyConnector")
|
|
|
|
: this.i18nService.t("removeOrgUserConfirmation");
|
|
|
|
|
|
|
|
return this.platformUtilsService.showDialog(
|
|
|
|
warningMessage,
|
|
|
|
this.i18nService.t("removeUserIdAccess", this.userNamePipe.transform(user)),
|
|
|
|
this.i18nService.t("yes"),
|
|
|
|
this.i18nService.t("no"),
|
|
|
|
"warning"
|
|
|
|
);
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2021-05-25 19:24:09 +02:00
|
|
|
private async showBulkStatus(
|
|
|
|
users: OrganizationUserUserDetailsResponse[],
|
|
|
|
filteredUsers: OrganizationUserUserDetailsResponse[],
|
|
|
|
request: Promise<ListResponse<OrganizationUserBulkResponse>>,
|
|
|
|
successfullMessage: string
|
|
|
|
) {
|
2021-08-27 14:50:58 +02:00
|
|
|
const [modal, childComponent] = await this.modalService.openViewRef(
|
|
|
|
BulkStatusComponent,
|
|
|
|
this.bulkStatusModalRef,
|
|
|
|
(comp) => {
|
|
|
|
comp.loading = true;
|
|
|
|
}
|
|
|
|
);
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2021-05-25 19:24:09 +02:00
|
|
|
// Workaround to handle closing the modal shortly after it has been opened
|
|
|
|
let close = false;
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
|
2021-08-27 14:50:58 +02:00
|
|
|
modal.onShown.subscribe(() => {
|
2021-05-25 19:24:09 +02:00
|
|
|
if (close) {
|
2021-08-27 14:50:58 +02:00
|
|
|
modal.close();
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
try {
|
2021-05-25 19:24:09 +02:00
|
|
|
const response = await request;
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
if (modal) {
|
2021-06-02 18:35:49 +02:00
|
|
|
const keyedErrors: any = response.data
|
|
|
|
.filter((r) => r.error !== "")
|
|
|
|
.reduce((a, x) => ({ ...a, [x.id]: x.error }), {});
|
|
|
|
const keyedFilteredUsers: any = filteredUsers.reduce((a, x) => ({ ...a, [x.id]: x }), {});
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2021-05-25 19:24:09 +02:00
|
|
|
childComponent.users = users.map((user) => {
|
|
|
|
let message = keyedErrors[user.id] ?? successfullMessage;
|
2022-02-24 12:10:07 +01:00
|
|
|
// eslint-disable-next-line
|
2021-05-25 19:24:09 +02:00
|
|
|
if (!keyedFilteredUsers.hasOwnProperty(user.id)) {
|
|
|
|
message = this.i18nService.t("bulkFilteredMessage");
|
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
|
|
|
|
return {
|
2021-05-25 19:24:09 +02:00
|
|
|
user: user,
|
2022-02-24 12:10:07 +01:00
|
|
|
error: keyedErrors.hasOwnProperty(user.id), // eslint-disable-line
|
2021-05-25 19:24:09 +02:00
|
|
|
message: message,
|
2021-12-17 15:57:11 +01:00
|
|
|
};
|
2021-05-25 19:24:09 +02:00
|
|
|
});
|
|
|
|
childComponent.loading = false;
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
close = true;
|
2021-08-27 14:50:58 +02:00
|
|
|
modal.close();
|
2021-05-25 19:24:09 +02:00
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2018-07-06 21:01:23 +02:00
|
|
|
}
|