2018-07-06 21:01:23 +02:00
|
|
|
import {
|
|
|
|
Component,
|
2018-07-10 20:46:13 +02:00
|
|
|
ComponentFactoryResolver,
|
2018-07-06 21:01:23 +02:00
|
|
|
OnInit,
|
2018-07-10 20:46:13 +02:00
|
|
|
ViewChild,
|
|
|
|
ViewContainerRef,
|
2018-07-06 21:01:23 +02:00
|
|
|
} from '@angular/core';
|
2021-06-02 18:35:49 +02:00
|
|
|
|
2018-10-17 16:53:04 +02:00
|
|
|
import {
|
|
|
|
ActivatedRoute,
|
|
|
|
Router,
|
|
|
|
} from '@angular/router';
|
2018-07-06 21:01:23 +02:00
|
|
|
|
2018-07-10 20:46:13 +02:00
|
|
|
import { ToasterService } from 'angular2-toaster';
|
|
|
|
|
2021-06-07 20:13:58 +02:00
|
|
|
import { ValidationService } from 'jslib-angular/services/validation.service';
|
|
|
|
|
|
|
|
import { ApiService } from 'jslib-common/abstractions/api.service';
|
|
|
|
import { CryptoService } from 'jslib-common/abstractions/crypto.service';
|
|
|
|
import { I18nService } from 'jslib-common/abstractions/i18n.service';
|
2021-07-21 11:32:27 +02:00
|
|
|
import { LogService } from 'jslib-common/abstractions/log.service';
|
2021-06-07 20:13:58 +02:00
|
|
|
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
|
|
|
|
import { PolicyService } from 'jslib-common/abstractions/policy.service';
|
|
|
|
import { SearchService } from 'jslib-common/abstractions/search.service';
|
|
|
|
import { StorageService } from 'jslib-common/abstractions/storage.service';
|
2021-07-01 16:10:34 +02:00
|
|
|
import { SyncService } from 'jslib-common/abstractions/sync.service';
|
2021-06-07 20:13:58 +02:00
|
|
|
import { UserService } from 'jslib-common/abstractions/user.service';
|
|
|
|
|
|
|
|
import { OrganizationKeysRequest } from 'jslib-common/models/request/organizationKeysRequest';
|
|
|
|
import { OrganizationUserBulkRequest } from 'jslib-common/models/request/organizationUserBulkRequest';
|
|
|
|
import { OrganizationUserConfirmRequest } from 'jslib-common/models/request/organizationUserConfirmRequest';
|
|
|
|
|
|
|
|
import { ListResponse } from 'jslib-common/models/response/listResponse';
|
|
|
|
import { OrganizationUserBulkResponse } from 'jslib-common/models/response/organizationUserBulkResponse';
|
|
|
|
import { OrganizationUserUserDetailsResponse } from 'jslib-common/models/response/organizationUserResponse';
|
|
|
|
|
|
|
|
import { OrganizationUserStatusType } from 'jslib-common/enums/organizationUserStatusType';
|
|
|
|
import { OrganizationUserType } from 'jslib-common/enums/organizationUserType';
|
|
|
|
import { PolicyType } from 'jslib-common/enums/policyType';
|
2021-07-21 11:32:27 +02:00
|
|
|
import { ProviderUserType } from 'jslib-common/enums/providerUserType';
|
2021-06-07 20:13:58 +02:00
|
|
|
|
2021-06-10 16:36:30 +02:00
|
|
|
import { SearchPipe } from 'jslib-angular/pipes/search.pipe';
|
2021-07-19 10:47:34 +02:00
|
|
|
import { UserNamePipe } from 'jslib-angular/pipes/user-name.pipe';
|
2021-06-10 16:36:30 +02:00
|
|
|
|
2021-07-21 11:32:27 +02:00
|
|
|
import { BasePeopleComponent } from '../../common/base.people.component';
|
2018-07-10 20:46:13 +02:00
|
|
|
import { ModalComponent } from '../../modal.component';
|
2021-06-09 17:04:21 +02:00
|
|
|
import { BulkConfirmComponent } from './bulk/bulk-confirm.component';
|
|
|
|
import { BulkRemoveComponent } from './bulk/bulk-remove.component';
|
|
|
|
import { BulkStatusComponent } from './bulk/bulk-status.component';
|
2018-07-11 21:22:55 +02:00
|
|
|
import { EntityEventsComponent } from './entity-events.component';
|
2021-06-02 18:35:49 +02:00
|
|
|
import { ResetPasswordComponent } from './reset-password.component';
|
2018-07-10 20:46:13 +02:00
|
|
|
import { UserAddEditComponent } from './user-add-edit.component';
|
2018-07-10 21:03:13 +02:00
|
|
|
import { UserGroupsComponent } from './user-groups.component';
|
2018-07-10 20:46:13 +02:00
|
|
|
|
2018-07-06 16:21:08 +02:00
|
|
|
@Component({
|
|
|
|
selector: 'app-org-people',
|
|
|
|
templateUrl: 'people.component.html',
|
|
|
|
})
|
2021-07-21 11:32:27 +02:00
|
|
|
export class PeopleComponent extends BasePeopleComponent<OrganizationUserUserDetailsResponse> implements OnInit {
|
2020-08-17 16:04:38 +02:00
|
|
|
@ViewChild('addEdit', { read: ViewContainerRef, static: true }) addEditModalRef: ViewContainerRef;
|
|
|
|
@ViewChild('groupsTemplate', { read: ViewContainerRef, static: true }) groupsModalRef: ViewContainerRef;
|
|
|
|
@ViewChild('eventsTemplate', { read: ViewContainerRef, static: true }) eventsModalRef: ViewContainerRef;
|
|
|
|
@ViewChild('confirmTemplate', { read: ViewContainerRef, static: true }) 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;
|
2018-07-10 20:46:13 +02:00
|
|
|
|
2021-08-20 21:36:13 +02:00
|
|
|
userType = OrganizationUserType;
|
2021-07-21 11:32:27 +02:00
|
|
|
userStatusType = OrganizationUserStatusType;
|
|
|
|
|
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-06-02 18:35:49 +02:00
|
|
|
canResetPassword = false; // User permission (admin/custom)
|
|
|
|
orgUseResetPassword = false; // Org plan ability
|
|
|
|
orgHasKeys = false; // Org public/private keys
|
|
|
|
orgResetPasswordPolicyEnabled = false;
|
|
|
|
callingUserType: OrganizationUserType = null;
|
2018-07-06 21:01:23 +02:00
|
|
|
|
2021-07-21 11:32:27 +02:00
|
|
|
constructor(apiService: ApiService, private route: ActivatedRoute,
|
|
|
|
i18nService: I18nService, componentFactoryResolver: ComponentFactoryResolver,
|
|
|
|
platformUtilsService: PlatformUtilsService, toasterService: ToasterService,
|
|
|
|
cryptoService: CryptoService, private userService: UserService, private router: Router,
|
|
|
|
storageService: StorageService, searchService: SearchService,
|
|
|
|
validationService: ValidationService, private policyService: PolicyService,
|
|
|
|
logService: LogService, searchPipe: SearchPipe, userNamePipe: UserNamePipe, private syncService: SyncService) {
|
|
|
|
super(apiService, searchService, i18nService, platformUtilsService, toasterService, cryptoService,
|
|
|
|
storageService, validationService, componentFactoryResolver, logService, searchPipe, userNamePipe);
|
|
|
|
}
|
2018-07-06 21:01:23 +02:00
|
|
|
|
|
|
|
async ngOnInit() {
|
2021-02-03 18:41:33 +01:00
|
|
|
this.route.parent.parent.params.subscribe(async params => {
|
2018-07-06 21:01:23 +02:00
|
|
|
this.organizationId = params.organizationId;
|
2018-07-11 20:43:00 +02:00
|
|
|
const organization = await this.userService.getOrganization(this.organizationId);
|
2021-01-12 21:31:22 +01:00
|
|
|
if (!organization.canManageUsers) {
|
2018-10-17 16:53:04 +02:00
|
|
|
this.router.navigate(['../collections'], { relativeTo: this.route });
|
|
|
|
return;
|
|
|
|
}
|
2018-07-11 20:43:00 +02:00
|
|
|
this.accessEvents = organization.useEvents;
|
|
|
|
this.accessGroups = organization.useGroups;
|
2021-06-02 18:35:49 +02:00
|
|
|
this.canResetPassword = organization.canManageUsersPassword;
|
|
|
|
this.orgUseResetPassword = organization.useResetPassword;
|
|
|
|
this.callingUserType = organization.type;
|
2021-07-02 22:23:04 +02:00
|
|
|
this.orgHasKeys = organization.hasPublicAndPrivateKeys;
|
2021-06-02 18:35:49 +02:00
|
|
|
|
|
|
|
// Backfill pub/priv key if necessary
|
2021-07-02 22:23:04 +02:00
|
|
|
if (this.canResetPassword && !this.orgHasKeys) {
|
2021-06-02 18:35:49 +02:00
|
|
|
const orgShareKey = await this.cryptoService.getOrgKey(this.organizationId);
|
|
|
|
const orgKeys = await this.cryptoService.makeKeyPair(orgShareKey);
|
|
|
|
const request = new OrganizationKeysRequest(orgKeys[0], orgKeys[1].encryptedString);
|
|
|
|
const response = await this.apiService.postOrganizationKeys(this.organizationId, request);
|
|
|
|
if (response != null) {
|
|
|
|
this.orgHasKeys = response.publicKey != null && response.privateKey != null;
|
2021-07-01 16:10:34 +02:00
|
|
|
await this.syncService.fullSync(true); // Replace oganizations with new data
|
2021-06-02 18:35:49 +02:00
|
|
|
} else {
|
|
|
|
throw new Error(this.i18nService.t('resetPasswordOrgKeysError'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-07 05:08:10 +02:00
|
|
|
await this.load();
|
2018-07-11 21:44:40 +02:00
|
|
|
|
2021-02-03 18:41:33 +01:00
|
|
|
const queryParamsSub = this.route.queryParams.subscribe(async qParams => {
|
2018-07-11 21:44:40 +02:00
|
|
|
this.searchText = qParams.search;
|
|
|
|
if (qParams.viewEvents != null) {
|
2021-02-03 18:41:33 +01:00
|
|
|
const user = this.users.filter(u => u.id === qParams.viewEvents);
|
2018-07-12 16:14:33 +02:00
|
|
|
if (user.length > 0 && user[0].status === OrganizationUserStatusType.Confirmed) {
|
2018-07-11 21:44:40 +02:00
|
|
|
this.events(user[0]);
|
|
|
|
}
|
|
|
|
}
|
2019-01-17 05:30:32 +01:00
|
|
|
if (queryParamsSub != null) {
|
|
|
|
queryParamsSub.unsubscribe();
|
|
|
|
}
|
2018-07-11 21:44:40 +02:00
|
|
|
});
|
2018-07-06 21:01:23 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async load() {
|
2021-06-02 18:35:49 +02:00
|
|
|
const policies = await this.policyService.getAll(PolicyType.ResetPassword);
|
|
|
|
this.orgResetPasswordPolicyEnabled = policies.some(p => p.organizationId === this.organizationId && p.enabled);
|
2021-07-21 11:32:27 +02:00
|
|
|
super.load();
|
|
|
|
}
|
|
|
|
|
|
|
|
getUsers(): Promise<ListResponse<OrganizationUserUserDetailsResponse>> {
|
|
|
|
return this.apiService.getOrganizationUsers(this.organizationId);
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteUser(id: string): Promise<any> {
|
|
|
|
return this.apiService.deleteOrganizationUser(this.organizationId, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
reinviteUser(id: string): Promise<any> {
|
|
|
|
return this.apiService.postOrganizationUserReinvite(this.organizationId, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
async confirmUser(user: OrganizationUserUserDetailsResponse, publicKey: Uint8Array): Promise<any> {
|
|
|
|
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);
|
2018-07-06 21:01:23 +02:00
|
|
|
}
|
2018-07-09 23:07:13 +02:00
|
|
|
|
2021-06-02 18:35:49 +02:00
|
|
|
allowResetPassword(orgUser: OrganizationUserUserDetailsResponse): boolean {
|
|
|
|
// Hierarchy check
|
|
|
|
let callingUserHasPermission = false;
|
|
|
|
|
|
|
|
switch (this.callingUserType) {
|
|
|
|
case OrganizationUserType.Owner:
|
|
|
|
callingUserHasPermission = true;
|
|
|
|
break;
|
|
|
|
case OrganizationUserType.Admin:
|
|
|
|
callingUserHasPermission = orgUser.type !== OrganizationUserType.Owner;
|
|
|
|
break;
|
|
|
|
case OrganizationUserType.Custom:
|
|
|
|
callingUserHasPermission = orgUser.type !== OrganizationUserType.Owner
|
|
|
|
&& orgUser.type !== OrganizationUserType.Admin;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Final
|
|
|
|
return this.canResetPassword && callingUserHasPermission && this.orgUseResetPassword && this.orgHasKeys
|
|
|
|
&& orgUser.resetPasswordEnrolled && this.orgResetPasswordPolicyEnabled
|
|
|
|
&& orgUser.status === OrganizationUserStatusType.Confirmed;
|
|
|
|
}
|
|
|
|
|
|
|
|
showEnrolledStatus(orgUser: OrganizationUserUserDetailsResponse): boolean {
|
|
|
|
return this.orgUseResetPassword && orgUser.resetPasswordEnrolled && this.orgResetPasswordPolicyEnabled;
|
|
|
|
}
|
|
|
|
|
2018-07-09 23:07:13 +02:00
|
|
|
edit(user: OrganizationUserUserDetailsResponse) {
|
2018-07-10 20:46:13 +02:00
|
|
|
if (this.modal != null) {
|
|
|
|
this.modal.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
|
|
|
|
this.modal = this.addEditModalRef.createComponent(factory).instance;
|
|
|
|
const childComponent = this.modal.show<UserAddEditComponent>(
|
|
|
|
UserAddEditComponent, this.addEditModalRef);
|
|
|
|
|
2021-07-19 10:47:34 +02:00
|
|
|
childComponent.name = this.userNamePipe.transform(user);
|
2018-07-10 20:46:13 +02:00
|
|
|
childComponent.organizationId = this.organizationId;
|
|
|
|
childComponent.organizationUserId = user != null ? user.id : null;
|
|
|
|
childComponent.onSavedUser.subscribe(() => {
|
|
|
|
this.modal.close();
|
|
|
|
this.load();
|
|
|
|
});
|
|
|
|
childComponent.onDeletedUser.subscribe(() => {
|
|
|
|
this.modal.close();
|
|
|
|
this.removeUser(user);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.modal.onClosed.subscribe(() => {
|
|
|
|
this.modal = null;
|
|
|
|
});
|
2018-07-09 23:07:13 +02:00
|
|
|
}
|
|
|
|
|
2018-07-10 21:03:13 +02:00
|
|
|
groups(user: OrganizationUserUserDetailsResponse) {
|
|
|
|
if (this.modal != null) {
|
|
|
|
this.modal.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
|
|
|
|
this.modal = this.groupsModalRef.createComponent(factory).instance;
|
|
|
|
const childComponent = this.modal.show<UserGroupsComponent>(
|
|
|
|
UserGroupsComponent, this.groupsModalRef);
|
|
|
|
|
2021-07-19 10:47:34 +02:00
|
|
|
childComponent.name = this.userNamePipe.transform(user);
|
2018-07-10 21:03:13 +02:00
|
|
|
childComponent.organizationId = this.organizationId;
|
|
|
|
childComponent.organizationUserId = user != null ? user.id : null;
|
|
|
|
childComponent.onSavedUser.subscribe(() => {
|
|
|
|
this.modal.close();
|
|
|
|
});
|
|
|
|
|
|
|
|
this.modal.onClosed.subscribe(() => {
|
|
|
|
this.modal = null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-05-18 10:27:52 +02:00
|
|
|
async bulkRemove() {
|
|
|
|
if (this.actionPromise != null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-09 17:04:21 +02:00
|
|
|
if (this.modal != null) {
|
|
|
|
this.modal.close();
|
2021-05-18 10:27:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-09 17:04:21 +02:00
|
|
|
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
|
|
|
|
this.modal = this.bulkRemoveModalRef.createComponent(factory).instance;
|
|
|
|
const childComponent = this.modal.show(BulkRemoveComponent, this.bulkRemoveModalRef);
|
2021-05-18 10:27:52 +02:00
|
|
|
|
2021-06-09 17:04:21 +02:00
|
|
|
childComponent.organizationId = this.organizationId;
|
|
|
|
childComponent.users = this.getCheckedUsers();
|
|
|
|
|
|
|
|
this.modal.onClosed.subscribe(async () => {
|
2021-05-18 10:27:52 +02:00
|
|
|
await this.load();
|
2021-06-09 17:04:21 +02:00
|
|
|
this.modal = null;
|
|
|
|
});
|
2021-05-18 10:27:52 +02:00
|
|
|
}
|
|
|
|
|
2021-05-12 16:38:17 +02:00
|
|
|
async bulkReinvite() {
|
|
|
|
if (this.actionPromise != null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-25 19:24:09 +02:00
|
|
|
const users = this.getCheckedUsers();
|
|
|
|
const filteredUsers = users.filter(u => u.status === OrganizationUserStatusType.Invited);
|
2021-05-12 16:38:17 +02:00
|
|
|
|
2021-05-25 19:24:09 +02:00
|
|
|
if (filteredUsers.length <= 0) {
|
2021-05-12 16:38:17 +02:00
|
|
|
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'),
|
|
|
|
this.i18nService.t('noSelectedUsersApplicable'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-25 19:24:09 +02:00
|
|
|
|
2021-05-12 16:38:17 +02:00
|
|
|
try {
|
2021-05-25 19:24:09 +02:00
|
|
|
const request = new OrganizationUserBulkRequest(filteredUsers.map(user => user.id));
|
|
|
|
const response = this.apiService.postManyOrganizationUserReinvite(this.organizationId, request);
|
|
|
|
this.showBulkStatus(users, filteredUsers, response, this.i18nService.t('bulkReinviteMessage'));
|
2021-05-12 16:38:17 +02:00
|
|
|
} catch (e) {
|
|
|
|
this.validationService.showError(e);
|
|
|
|
}
|
|
|
|
this.actionPromise = null;
|
|
|
|
}
|
|
|
|
|
2021-05-25 19:24:09 +02:00
|
|
|
async bulkConfirm() {
|
|
|
|
if (this.actionPromise != null) {
|
|
|
|
return;
|
2018-11-15 05:13:50 +01:00
|
|
|
}
|
|
|
|
|
2021-06-09 17:04:21 +02:00
|
|
|
if (this.modal != null) {
|
|
|
|
this.modal.close();
|
2018-07-11 19:30:17 +02:00
|
|
|
}
|
2018-11-15 05:13:50 +01:00
|
|
|
|
2021-06-09 17:04:21 +02:00
|
|
|
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
|
|
|
|
this.modal = this.bulkConfirmModalRef.createComponent(factory).instance;
|
|
|
|
const childComponent = this.modal.show(BulkConfirmComponent, this.bulkConfirmModalRef);
|
|
|
|
|
|
|
|
childComponent.organizationId = this.organizationId;
|
|
|
|
childComponent.users = this.getCheckedUsers();
|
2021-05-25 19:24:09 +02:00
|
|
|
|
2021-06-09 17:04:21 +02:00
|
|
|
this.modal.onClosed.subscribe(async () => {
|
|
|
|
await this.load();
|
|
|
|
this.modal = null;
|
2021-05-25 19:24:09 +02:00
|
|
|
});
|
2021-06-09 17:04:21 +02:00
|
|
|
}
|
2021-05-25 19:24:09 +02:00
|
|
|
|
2018-07-11 19:30:17 +02:00
|
|
|
async events(user: OrganizationUserUserDetailsResponse) {
|
2018-07-11 20:43:00 +02:00
|
|
|
if (this.modal != null) {
|
|
|
|
this.modal.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
|
|
|
|
this.modal = this.eventsModalRef.createComponent(factory).instance;
|
2018-07-11 21:22:55 +02:00
|
|
|
const childComponent = this.modal.show<EntityEventsComponent>(
|
|
|
|
EntityEventsComponent, this.eventsModalRef);
|
2018-07-11 20:43:00 +02:00
|
|
|
|
2021-07-19 10:47:34 +02:00
|
|
|
childComponent.name = this.userNamePipe.transform(user);
|
2018-07-11 20:43:00 +02:00
|
|
|
childComponent.organizationId = this.organizationId;
|
2018-07-11 21:22:55 +02:00
|
|
|
childComponent.entityId = user.id;
|
|
|
|
childComponent.showUser = false;
|
|
|
|
childComponent.entity = 'user';
|
2018-07-11 19:30:17 +02:00
|
|
|
|
2018-07-11 20:43:00 +02:00
|
|
|
this.modal.onClosed.subscribe(() => {
|
|
|
|
this.modal = null;
|
|
|
|
});
|
2018-07-11 19:30:17 +02:00
|
|
|
}
|
|
|
|
|
2021-06-02 18:35:49 +02:00
|
|
|
async resetPassword(user: OrganizationUserUserDetailsResponse) {
|
|
|
|
if (this.modal != null) {
|
|
|
|
this.modal.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
|
|
|
|
this.modal = this.resetPasswordModalRef.createComponent(factory).instance;
|
|
|
|
const childComponent = this.modal.show<ResetPasswordComponent>(
|
|
|
|
ResetPasswordComponent, this.resetPasswordModalRef);
|
|
|
|
|
2021-07-19 10:47:34 +02:00
|
|
|
childComponent.name = this.userNamePipe.transform(user);
|
2021-06-02 18:35:49 +02:00
|
|
|
childComponent.email = user != null ? user.email : null;
|
|
|
|
childComponent.organizationId = this.organizationId;
|
|
|
|
childComponent.id = user != null ? user.id : null;
|
|
|
|
|
|
|
|
childComponent.onPasswordReset.subscribe(() => {
|
|
|
|
this.modal.close();
|
|
|
|
this.load();
|
|
|
|
});
|
|
|
|
|
|
|
|
this.modal.onClosed.subscribe(() => {
|
|
|
|
this.modal = null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-05-25 19:24:09 +02:00
|
|
|
private async showBulkStatus(users: OrganizationUserUserDetailsResponse[], filteredUsers: OrganizationUserUserDetailsResponse[],
|
|
|
|
request: Promise<ListResponse<OrganizationUserBulkResponse>>, successfullMessage: string) {
|
|
|
|
|
|
|
|
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
|
2021-06-09 17:04:21 +02:00
|
|
|
this.modal = this.bulkStatusModalRef.createComponent(factory).instance;
|
2021-05-25 19:24:09 +02:00
|
|
|
const childComponent = this.modal.show<BulkStatusComponent>(
|
2021-06-09 17:04:21 +02:00
|
|
|
BulkStatusComponent, this.bulkStatusModalRef);
|
2021-05-25 19:24:09 +02:00
|
|
|
|
|
|
|
childComponent.loading = true;
|
|
|
|
|
|
|
|
// Workaround to handle closing the modal shortly after it has been opened
|
|
|
|
let close = false;
|
|
|
|
this.modal.onShown.subscribe(() => {
|
|
|
|
if (close) {
|
|
|
|
this.modal.close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.modal.onClosed.subscribe(() => {
|
|
|
|
this.modal = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
try {
|
|
|
|
const response = await request;
|
|
|
|
|
|
|
|
if (this.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-05-25 19:24:09 +02:00
|
|
|
|
|
|
|
childComponent.users = users.map(user => {
|
|
|
|
let message = keyedErrors[user.id] ?? successfullMessage;
|
|
|
|
if (!keyedFilteredUsers.hasOwnProperty(user.id)) {
|
|
|
|
message = this.i18nService.t('bulkFilteredMessage');
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
user: user,
|
|
|
|
error: keyedErrors.hasOwnProperty(user.id),
|
|
|
|
message: message,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
childComponent.loading = false;
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
close = true;
|
|
|
|
if (this.modal) {
|
|
|
|
this.modal.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-06 21:01:23 +02:00
|
|
|
}
|