bitwarden-estensione-browser/src/app/organizations/manage/events.component.ts

102 lines
3.9 KiB
TypeScript
Raw Normal View History

2018-07-07 05:08:10 +02:00
import {
Component,
OnInit,
} from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
2018-07-09 18:22:32 +02:00
2021-07-19 10:47:34 +02:00
import { UserNamePipe } from 'jslib-angular/pipes/user-name.pipe';
import { ApiService } from 'jslib-common/abstractions/api.service';
import { ExportService } from 'jslib-common/abstractions/export.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { LogService } from 'jslib-common/abstractions/log.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { UserService } from 'jslib-common/abstractions/user.service';
2018-07-07 05:08:10 +02:00
import { Organization } from 'jslib-common/models/domain/organization';
import { EventResponse } from 'jslib-common/models/response/eventResponse';
2018-07-06 16:21:08 +02:00
import { EventService } from '../../services/event.service';
2018-07-09 17:47:57 +02:00
import { BaseEventsComponent } from '../../common/base.events.component';
2018-07-06 16:21:08 +02:00
@Component({
selector: 'app-org-events',
templateUrl: 'events.component.html',
})
export class EventsComponent extends BaseEventsComponent implements OnInit {
exportFileName: string = 'org-events';
2018-07-07 05:08:10 +02:00
organizationId: string;
organization: Organization;
2018-07-07 05:08:10 +02:00
2018-07-09 18:22:32 +02:00
private orgUsersUserIdMap = new Map<string, any>();
constructor(private apiService: ApiService, private route: ActivatedRoute, eventService: EventService,
2021-12-07 20:41:45 +01:00
i18nService: I18nService, private userService: UserService,
exportService: ExportService, platformUtilsService: PlatformUtilsService, private router: Router,
logService: LogService, private userNamePipe: UserNamePipe) {
2021-12-07 20:41:45 +01:00
super(eventService, i18nService, exportService, platformUtilsService, logService);
}
2018-07-07 05:08:10 +02:00
async ngOnInit() {
this.route.parent.parent.params.subscribe(async params => {
2018-07-07 05:08:10 +02:00
this.organizationId = params.organizationId;
this.organization = await this.userService.getOrganization(this.organizationId);
if (this.organization == null || !this.organization.useEvents) {
this.router.navigate(['/organizations', this.organizationId]);
return;
}
2018-07-07 05:08:10 +02:00
await this.load();
});
}
async load() {
2018-07-09 18:22:32 +02:00
const response = await this.apiService.getOrganizationUsers(this.organizationId);
response.data.forEach(u => {
2021-07-19 10:47:34 +02:00
const name = this.userNamePipe.transform(u);
2018-07-09 18:22:32 +02:00
this.orgUsersUserIdMap.set(u.userId, { name: name, email: u.email });
});
if (this.organization.providerId != null) {
try {
const provider = await this.userService.getProvider(this.organization.providerId);
if (provider != null && (await this.userService.getProvider(this.organization.providerId)).canManageUsers) {
const providerUsersResponse = await this.apiService.getProviderUsers(this.organization.providerId);
providerUsersResponse.data.forEach(u => {
const name = this.userNamePipe.transform(u);
this.orgUsersUserIdMap.set(u.userId, { name: `${name} (${this.organization.providerName})`, email: u.email });
});
}
} catch (e) {
this.logService.warning(e);
}
}
await this.loadEvents(true);
this.loaded = true;
}
protected requestEvents(startDate: string, endDate: string, continuationToken: string) {
return this.apiService.getEventsOrganization(this.organizationId, startDate, endDate, continuationToken);
}
protected getUserName(r: EventResponse, userId: string) {
if (userId == null) {
return null;
}
if (this.orgUsersUserIdMap.has(userId)) {
return this.orgUsersUserIdMap.get(userId);
}
2018-07-09 17:47:57 +02:00
if (r.providerId != null && r.providerId === this.organization.providerId) {
return {
'name': this.organization.providerName,
};
2018-07-09 17:47:57 +02:00
}
return null;
}
2018-07-07 05:08:10 +02:00
}