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';
|
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-04-09 00:46:16 +02:00
|
|
|
import { ValidationService } from 'jslib/angular/services/validation.service';
|
2018-11-15 05:13:50 +01:00
|
|
|
import { ConstantsService } from 'jslib/services/constants.service';
|
|
|
|
|
2018-07-06 21:01:23 +02:00
|
|
|
import { ApiService } from 'jslib/abstractions/api.service';
|
2018-07-11 19:30:17 +02:00
|
|
|
import { CryptoService } from 'jslib/abstractions/crypto.service';
|
2018-07-06 21:01:23 +02:00
|
|
|
import { I18nService } from 'jslib/abstractions/i18n.service';
|
2018-07-10 20:46:13 +02:00
|
|
|
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
2020-05-22 18:26:43 +02:00
|
|
|
import { SearchService } from 'jslib/abstractions/search.service';
|
2018-11-15 05:13:50 +01:00
|
|
|
import { StorageService } from 'jslib/abstractions/storage.service';
|
2018-07-11 20:43:00 +02:00
|
|
|
import { UserService } from 'jslib/abstractions/user.service';
|
2018-07-06 21:01:23 +02:00
|
|
|
|
2018-07-11 19:30:17 +02:00
|
|
|
import { OrganizationUserConfirmRequest } from 'jslib/models/request/organizationUserConfirmRequest';
|
|
|
|
|
2021-05-18 10:27:52 +02:00
|
|
|
import { OrganizationUserBulkRequest } from 'jslib/models/request/organizationUserBulkRequest';
|
2018-07-06 21:01:23 +02:00
|
|
|
import { OrganizationUserUserDetailsResponse } from 'jslib/models/response/organizationUserResponse';
|
|
|
|
|
2018-07-06 21:45:35 +02:00
|
|
|
import { OrganizationUserStatusType } from 'jslib/enums/organizationUserStatusType';
|
|
|
|
import { OrganizationUserType } from 'jslib/enums/organizationUserType';
|
|
|
|
|
2018-07-06 21:01:23 +02:00
|
|
|
import { Utils } from 'jslib/misc/utils';
|
2018-07-06 16:21:08 +02:00
|
|
|
|
2018-07-10 20:46:13 +02:00
|
|
|
import { ModalComponent } from '../../modal.component';
|
2018-07-11 21:22:55 +02:00
|
|
|
import { EntityEventsComponent } from './entity-events.component';
|
2018-07-10 20:46:13 +02:00
|
|
|
import { UserAddEditComponent } from './user-add-edit.component';
|
2018-11-15 05:13:50 +01:00
|
|
|
import { UserConfirmComponent } from './user-confirm.component';
|
2018-07-10 21:03:13 +02:00
|
|
|
import { UserGroupsComponent } from './user-groups.component';
|
2018-07-10 20:46:13 +02:00
|
|
|
|
2021-05-12 16:38:17 +02:00
|
|
|
const MaxCheckedCount = 500;
|
|
|
|
|
2018-07-06 16:21:08 +02:00
|
|
|
@Component({
|
|
|
|
selector: 'app-org-people',
|
|
|
|
templateUrl: 'people.component.html',
|
|
|
|
})
|
2018-07-06 21:01:23 +02:00
|
|
|
export class PeopleComponent 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;
|
2018-07-10 20:46:13 +02:00
|
|
|
|
2018-07-06 21:01:23 +02:00
|
|
|
loading = true;
|
|
|
|
organizationId: string;
|
|
|
|
users: OrganizationUserUserDetailsResponse[];
|
2020-05-22 18:26:43 +02:00
|
|
|
pagedUsers: OrganizationUserUserDetailsResponse[];
|
2018-07-06 21:01:23 +02:00
|
|
|
searchText: string;
|
2018-07-11 22:40:32 +02:00
|
|
|
status: OrganizationUserStatusType = null;
|
|
|
|
statusMap = new Map<OrganizationUserStatusType, OrganizationUserUserDetailsResponse[]>();
|
2018-07-06 21:45:35 +02:00
|
|
|
organizationUserType = OrganizationUserType;
|
|
|
|
organizationUserStatusType = OrganizationUserStatusType;
|
2018-07-11 19:30:17 +02:00
|
|
|
actionPromise: Promise<any>;
|
2018-07-11 20:43:00 +02:00
|
|
|
accessEvents = false;
|
|
|
|
accessGroups = false;
|
2018-07-06 21:01:23 +02:00
|
|
|
|
2020-05-22 18:26:43 +02:00
|
|
|
protected didScroll = false;
|
|
|
|
protected pageSize = 100;
|
|
|
|
|
|
|
|
private pagedUsersCount = 0;
|
2018-07-10 20:46:13 +02:00
|
|
|
private modal: ModalComponent = null;
|
2018-07-11 22:40:32 +02:00
|
|
|
private allUsers: OrganizationUserUserDetailsResponse[];
|
2018-07-10 20:46:13 +02:00
|
|
|
|
2018-07-06 21:01:23 +02:00
|
|
|
constructor(private apiService: ApiService, private route: ActivatedRoute,
|
2018-07-10 20:46:13 +02:00
|
|
|
private i18nService: I18nService, private componentFactoryResolver: ComponentFactoryResolver,
|
2021-04-14 23:43:40 +02:00
|
|
|
private platformUtilsService: PlatformUtilsService, private toasterService: ToasterService,
|
|
|
|
private cryptoService: CryptoService, private userService: UserService, private router: Router,
|
2021-04-09 00:46:16 +02:00
|
|
|
private storageService: StorageService, private searchService: SearchService,
|
|
|
|
private validationService: ValidationService) { }
|
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;
|
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() {
|
|
|
|
const response = await this.apiService.getOrganizationUsers(this.organizationId);
|
2018-07-11 22:40:32 +02:00
|
|
|
this.statusMap.clear();
|
|
|
|
this.allUsers = response.data != null && response.data.length > 0 ? response.data : [];
|
|
|
|
this.allUsers.sort(Utils.getSortFunction(this.i18nService, 'email'));
|
2021-02-03 18:41:33 +01:00
|
|
|
this.allUsers.forEach(u => {
|
2018-07-11 22:40:32 +02:00
|
|
|
if (!this.statusMap.has(u.status)) {
|
|
|
|
this.statusMap.set(u.status, [u]);
|
|
|
|
} else {
|
|
|
|
this.statusMap.get(u.status).push(u);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.filter(this.status);
|
2018-07-06 21:01:23 +02:00
|
|
|
this.loading = false;
|
|
|
|
}
|
2018-07-09 23:07:13 +02:00
|
|
|
|
2018-07-11 22:40:32 +02:00
|
|
|
filter(status: OrganizationUserStatusType) {
|
|
|
|
this.status = status;
|
|
|
|
if (this.status != null) {
|
|
|
|
this.users = this.statusMap.get(this.status);
|
|
|
|
} else {
|
|
|
|
this.users = this.allUsers;
|
|
|
|
}
|
2021-05-12 16:38:17 +02:00
|
|
|
// Reset checkbox selecton
|
|
|
|
this.selectAll(false);
|
2020-05-22 18:26:43 +02:00
|
|
|
this.resetPaging();
|
|
|
|
}
|
|
|
|
|
|
|
|
loadMore() {
|
2020-07-28 15:55:59 +02:00
|
|
|
if (!this.users || this.users.length <= this.pageSize) {
|
2020-05-22 18:26:43 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const pagedLength = this.pagedUsers.length;
|
|
|
|
let pagedSize = this.pageSize;
|
|
|
|
if (pagedLength === 0 && this.pagedUsersCount > this.pageSize) {
|
|
|
|
pagedSize = this.pagedUsersCount;
|
|
|
|
}
|
|
|
|
if (this.users.length > pagedLength) {
|
|
|
|
this.pagedUsers = this.pagedUsers.concat(this.users.slice(pagedLength, pagedLength + pagedSize));
|
|
|
|
}
|
|
|
|
this.pagedUsersCount = this.pagedUsers.length;
|
|
|
|
this.didScroll = this.pagedUsers.length > this.pageSize;
|
2018-07-11 22:40:32 +02:00
|
|
|
}
|
|
|
|
|
2020-03-10 17:06:25 +01:00
|
|
|
get allCount() {
|
2020-04-20 06:17:06 +02:00
|
|
|
return this.allUsers != null ? this.allUsers.length : 0;
|
2020-03-10 17:06:25 +01:00
|
|
|
}
|
|
|
|
|
2018-07-11 22:40:32 +02:00
|
|
|
get invitedCount() {
|
|
|
|
return this.statusMap.has(OrganizationUserStatusType.Invited) ?
|
|
|
|
this.statusMap.get(OrganizationUserStatusType.Invited).length : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
get acceptedCount() {
|
|
|
|
return this.statusMap.has(OrganizationUserStatusType.Accepted) ?
|
|
|
|
this.statusMap.get(OrganizationUserStatusType.Accepted).length : 0;
|
|
|
|
}
|
|
|
|
|
2018-08-06 23:37:54 +02:00
|
|
|
get confirmedCount() {
|
|
|
|
return this.statusMap.has(OrganizationUserStatusType.Confirmed) ?
|
|
|
|
this.statusMap.get(OrganizationUserStatusType.Confirmed).length : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
get showConfirmUsers(): boolean {
|
|
|
|
return this.allUsers != null && this.statusMap != null && this.allUsers.length > 1 &&
|
|
|
|
this.confirmedCount > 0 && this.confirmedCount < 3 && this.acceptedCount > 0;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
childComponent.name = user != null ? user.name || user.email : null;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
invite() {
|
2018-07-10 20:46:13 +02:00
|
|
|
this.edit(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);
|
|
|
|
|
|
|
|
childComponent.name = user != null ? user.name || user.email : null;
|
|
|
|
childComponent.organizationId = this.organizationId;
|
|
|
|
childComponent.organizationUserId = user != null ? user.id : null;
|
|
|
|
childComponent.onSavedUser.subscribe(() => {
|
|
|
|
this.modal.close();
|
|
|
|
});
|
|
|
|
|
|
|
|
this.modal.onClosed.subscribe(() => {
|
|
|
|
this.modal = null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-07-09 23:07:13 +02:00
|
|
|
async remove(user: OrganizationUserUserDetailsResponse) {
|
2018-07-10 20:46:13 +02:00
|
|
|
const confirmed = await this.platformUtilsService.showDialog(
|
|
|
|
this.i18nService.t('removeUserConfirmation'), user.name || user.email,
|
|
|
|
this.i18nService.t('yes'), this.i18nService.t('no'), 'warning');
|
|
|
|
if (!confirmed) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-05-17 15:13:26 +02:00
|
|
|
this.actionPromise = this.apiService.deleteOrganizationUser(this.organizationId, user.id);
|
2018-07-10 20:46:13 +02:00
|
|
|
try {
|
2021-05-17 15:13:26 +02:00
|
|
|
await this.actionPromise;
|
2018-07-10 20:46:13 +02:00
|
|
|
this.toasterService.popAsync('success', null, this.i18nService.t('removedUserId', user.name || user.email));
|
|
|
|
this.removeUser(user);
|
2021-05-17 15:13:26 +02:00
|
|
|
} catch (e) {
|
|
|
|
this.validationService.showError(e);
|
|
|
|
}
|
|
|
|
this.actionPromise = null;
|
2018-07-10 20:46:13 +02:00
|
|
|
}
|
|
|
|
|
2018-07-11 19:30:17 +02:00
|
|
|
async reinvite(user: OrganizationUserUserDetailsResponse) {
|
|
|
|
if (this.actionPromise != null) {
|
|
|
|
return;
|
|
|
|
}
|
2021-05-17 15:13:26 +02:00
|
|
|
|
2018-07-11 19:30:17 +02:00
|
|
|
this.actionPromise = this.apiService.postOrganizationUserReinvite(this.organizationId, user.id);
|
2021-05-17 15:13:26 +02:00
|
|
|
try {
|
|
|
|
await this.actionPromise;
|
|
|
|
this.toasterService.popAsync('success', null, this.i18nService.t('hasBeenReinvited', user.name || user.email));
|
|
|
|
} catch (e) {
|
|
|
|
this.validationService.showError(e);
|
|
|
|
}
|
2018-07-11 19:30:17 +02:00
|
|
|
this.actionPromise = null;
|
|
|
|
}
|
|
|
|
|
2021-05-18 10:27:52 +02:00
|
|
|
async bulkRemove() {
|
|
|
|
if (this.actionPromise != null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const users = this.getCheckedUsers();
|
|
|
|
if (users.length <= 0) {
|
|
|
|
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'),
|
|
|
|
this.i18nService.t('noSelectedUsersApplicable'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const confirmed = await this.platformUtilsService.showDialog(
|
|
|
|
this.i18nService.t('removeSelectedUsersConfirmation'), this.i18nService.t('remove'),
|
|
|
|
this.i18nService.t('yes'), this.i18nService.t('no'), 'warning');
|
|
|
|
if (!confirmed) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const request = new OrganizationUserBulkRequest(users.map(user => user.id));
|
|
|
|
this.actionPromise = this.apiService.deleteManyOrganizationUsers(this.organizationId, request);
|
|
|
|
try {
|
|
|
|
await this.actionPromise;
|
|
|
|
this.toasterService.popAsync('success', null, this.i18nService.t('usersHasBeenRemoved'));
|
|
|
|
await this.load();
|
|
|
|
} catch (e) {
|
|
|
|
this.validationService.showError(e);
|
|
|
|
}
|
|
|
|
this.actionPromise = null;
|
|
|
|
}
|
|
|
|
|
2021-05-12 16:38:17 +02:00
|
|
|
async bulkReinvite() {
|
|
|
|
if (this.actionPromise != null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const users = this.getCheckedUsers().filter(u => u.status === OrganizationUserStatusType.Invited);
|
|
|
|
|
|
|
|
if (users.length <= 0) {
|
|
|
|
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'),
|
|
|
|
this.i18nService.t('noSelectedUsersApplicable'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-18 10:27:52 +02:00
|
|
|
const request = new OrganizationUserBulkRequest(users.map(user => user.id));
|
2021-05-12 16:38:17 +02:00
|
|
|
this.actionPromise = this.apiService.postManyOrganizationUserReinvite(this.organizationId, request);
|
|
|
|
try {
|
|
|
|
await this.actionPromise;
|
|
|
|
this.toasterService.popAsync('success', null, this.i18nService.t('usersHasBeenReinvited'));
|
|
|
|
} catch (e) {
|
|
|
|
this.validationService.showError(e);
|
|
|
|
}
|
|
|
|
this.actionPromise = null;
|
|
|
|
}
|
|
|
|
|
2018-07-11 19:30:17 +02:00
|
|
|
async confirm(user: OrganizationUserUserDetailsResponse) {
|
2018-11-15 05:13:50 +01:00
|
|
|
function updateUser(self: PeopleComponent) {
|
|
|
|
user.status = OrganizationUserStatusType.Confirmed;
|
|
|
|
const mapIndex = self.statusMap.get(OrganizationUserStatusType.Accepted).indexOf(user);
|
|
|
|
if (mapIndex > -1) {
|
|
|
|
self.statusMap.get(OrganizationUserStatusType.Accepted).splice(mapIndex, 1);
|
|
|
|
self.statusMap.get(OrganizationUserStatusType.Confirmed).push(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-09 00:46:16 +02:00
|
|
|
const confirmUser = async (publicKey: Uint8Array) => {
|
|
|
|
try {
|
|
|
|
this.actionPromise = this.doConfirmation(user, publicKey);
|
|
|
|
await this.actionPromise;
|
|
|
|
updateUser(this);
|
|
|
|
this.toasterService.popAsync('success', null, this.i18nService.t('hasBeenConfirmed', user.name || user.email));
|
|
|
|
} catch (e) {
|
|
|
|
this.validationService.showError(e);
|
|
|
|
throw e;
|
|
|
|
} finally {
|
|
|
|
this.actionPromise = null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-07-11 19:30:17 +02:00
|
|
|
if (this.actionPromise != null) {
|
|
|
|
return;
|
|
|
|
}
|
2018-11-15 05:13:50 +01:00
|
|
|
|
|
|
|
const autoConfirm = await this.storageService.get<boolean>(ConstantsService.autoConfirmFingerprints);
|
|
|
|
if (autoConfirm == null || !autoConfirm) {
|
|
|
|
if (this.modal != null) {
|
|
|
|
this.modal.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
|
2019-03-16 02:04:57 +01:00
|
|
|
this.modal = this.confirmModalRef.createComponent(factory).instance;
|
2018-11-15 05:13:50 +01:00
|
|
|
const childComponent = this.modal.show<UserConfirmComponent>(
|
|
|
|
UserConfirmComponent, this.confirmModalRef);
|
|
|
|
|
|
|
|
childComponent.name = user != null ? user.name || user.email : null;
|
|
|
|
childComponent.organizationId = this.organizationId;
|
|
|
|
childComponent.organizationUserId = user != null ? user.id : null;
|
|
|
|
childComponent.userId = user != null ? user.userId : null;
|
2021-04-09 00:46:16 +02:00
|
|
|
childComponent.onConfirmedUser.subscribe(async (publicKey: Uint8Array) => {
|
|
|
|
try {
|
|
|
|
await confirmUser(publicKey);
|
|
|
|
this.modal.close();
|
|
|
|
} catch (e) {
|
|
|
|
// tslint:disable-next-line
|
|
|
|
console.error('Handled exception:', e);
|
|
|
|
}
|
2018-11-15 05:13:50 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
this.modal.onClosed.subscribe(() => {
|
|
|
|
this.modal = null;
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-09 00:46:16 +02:00
|
|
|
try {
|
|
|
|
const publicKeyResponse = await this.apiService.getUserPublicKey(user.userId);
|
|
|
|
const publicKey = Utils.fromB64ToArray(publicKeyResponse.publicKey);
|
|
|
|
try {
|
|
|
|
// tslint:disable-next-line
|
|
|
|
console.log('User\'s fingerprint: ' +
|
|
|
|
(await this.cryptoService.getFingerprint(user.userId, publicKey.buffer)).join('-'));
|
|
|
|
} catch { }
|
|
|
|
await confirmUser(publicKey);
|
|
|
|
} catch (e) {
|
|
|
|
// tslint:disable-next-line
|
|
|
|
console.error('Handled exception:', e);
|
|
|
|
}
|
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
|
|
|
|
2018-07-11 21:22:55 +02:00
|
|
|
childComponent.name = user.name || user.email;
|
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
|
|
|
}
|
|
|
|
|
2020-05-22 18:26:43 +02:00
|
|
|
async resetPaging() {
|
|
|
|
this.pagedUsers = [];
|
|
|
|
this.loadMore();
|
|
|
|
}
|
|
|
|
|
|
|
|
isSearching() {
|
|
|
|
return this.searchService.isSearchable(this.searchText);
|
|
|
|
}
|
|
|
|
|
|
|
|
isPaging() {
|
|
|
|
const searching = this.isSearching();
|
|
|
|
if (searching && this.didScroll) {
|
|
|
|
this.resetPaging();
|
|
|
|
}
|
2020-07-28 15:55:59 +02:00
|
|
|
return !searching && this.users && this.users.length > this.pageSize;
|
2020-05-22 18:26:43 +02:00
|
|
|
}
|
|
|
|
|
2021-05-12 16:38:17 +02:00
|
|
|
checkUser(user: OrganizationUserUserDetailsResponse, select?: boolean) {
|
|
|
|
(user as any).checked = select == null ? !(user as any).checked : select;
|
|
|
|
}
|
|
|
|
|
|
|
|
selectAll(select: boolean) {
|
|
|
|
if (select) {
|
|
|
|
this.selectAll(false);
|
|
|
|
}
|
|
|
|
const selectCount = select && this.users.length > MaxCheckedCount
|
|
|
|
? MaxCheckedCount
|
|
|
|
: this.users.length;
|
|
|
|
for (let i = 0; i < selectCount; i++) {
|
|
|
|
this.checkUser(this.users[i], select);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-09 00:46:16 +02:00
|
|
|
private async doConfirmation(user: OrganizationUserUserDetailsResponse, publicKey: Uint8Array) {
|
2018-07-11 19:30:17 +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);
|
|
|
|
}
|
|
|
|
|
2018-07-10 20:46:13 +02:00
|
|
|
private removeUser(user: OrganizationUserUserDetailsResponse) {
|
2018-08-06 23:37:54 +02:00
|
|
|
let index = this.users.indexOf(user);
|
2018-07-10 20:46:13 +02:00
|
|
|
if (index > -1) {
|
|
|
|
this.users.splice(index, 1);
|
2020-05-22 18:26:43 +02:00
|
|
|
this.resetPaging();
|
2018-07-10 20:46:13 +02:00
|
|
|
}
|
2018-08-06 23:37:54 +02:00
|
|
|
if (this.statusMap.has(OrganizationUserStatusType.Accepted)) {
|
|
|
|
index = this.statusMap.get(OrganizationUserStatusType.Accepted).indexOf(user);
|
|
|
|
if (index > -1) {
|
|
|
|
this.statusMap.get(OrganizationUserStatusType.Accepted).splice(index, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.statusMap.has(OrganizationUserStatusType.Invited)) {
|
|
|
|
index = this.statusMap.get(OrganizationUserStatusType.Invited).indexOf(user);
|
|
|
|
if (index > -1) {
|
|
|
|
this.statusMap.get(OrganizationUserStatusType.Invited).splice(index, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.statusMap.has(OrganizationUserStatusType.Confirmed)) {
|
|
|
|
index = this.statusMap.get(OrganizationUserStatusType.Confirmed).indexOf(user);
|
|
|
|
if (index > -1) {
|
|
|
|
this.statusMap.get(OrganizationUserStatusType.Confirmed).splice(index, 1);
|
|
|
|
}
|
|
|
|
}
|
2018-07-09 23:07:13 +02:00
|
|
|
}
|
2021-05-12 16:38:17 +02:00
|
|
|
|
|
|
|
private getCheckedUsers() {
|
|
|
|
return this.users.filter(u => (u as any).checked);
|
|
|
|
}
|
2018-07-06 21:01:23 +02:00
|
|
|
}
|