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