From c2bf6a67008af73002e0fe06df082491240dcee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rui=20Tom=C3=A9?= <108268980+r-tome@users.noreply.github.com> Date: Wed, 9 Nov 2022 12:13:37 +0000 Subject: [PATCH] =?UTF-8?q?[EC-449]=C2=A0Event=20log=20user=20for=20SCIM?= =?UTF-8?q?=20events=20(#3643)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [EC-449] Added EventSystemUser Enum and added systemUser property to eventResponse * [EC-449] Add systemUser property to BaseEventsComponent, EventExport and EventView * [EC-449] Set EventSystemUser as string on EventExport * [EC-449] Remove systemUser from EventExport * [EC-449] Rename EventSystemUser file to lowercase * [EC-449] Force git to rename EventSystemUser file * [EC-449] Rename EventSystemUser file to event-system-user.ts * [EC-449] Fix EventSystemUser reference on EventsComponent * [EC-449] Move installationId username logic to BaseEventsComponent * Update libs/common/src/enums/event-system-user.ts Add a note to warn about using the Enum key in the UI. Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com> * [EC-449] Remove EventSystemUser from provider events. Remove nested condition on events component Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com> --- .../src/app/common/base.events.component.ts | 3 ++- .../organizations/manage/events.component.ts | 21 +++++++++++++------ .../app/providers/manage/events.component.ts | 12 ++++++++--- libs/common/src/enums/event-system-user.ts | 4 ++++ .../src/models/response/event.response.ts | 3 +++ libs/common/src/models/view/event.view.ts | 3 +++ 6 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 libs/common/src/enums/event-system-user.ts diff --git a/apps/web/src/app/common/base.events.component.ts b/apps/web/src/app/common/base.events.component.ts index 51a2d3afad9..0a67a1caf07 100644 --- a/apps/web/src/app/common/base.events.component.ts +++ b/apps/web/src/app/common/base.events.component.ts @@ -132,12 +132,13 @@ export abstract class BaseEventsComponent { appIcon: eventInfo.appIcon, appName: eventInfo.appName, userId: userId, - userName: r.installationId != null ? `Installation: ${r.installationId}` : userName, + userName: userName, userEmail: user != null ? user.email : "", date: r.date, ip: r.ipAddress, type: r.type, installationId: r.installationId, + systemUser: r.systemUser, }); }) ); diff --git a/apps/web/src/app/organizations/manage/events.component.ts b/apps/web/src/app/organizations/manage/events.component.ts index abc8b52543d..dd31169914d 100644 --- a/apps/web/src/app/organizations/manage/events.component.ts +++ b/apps/web/src/app/organizations/manage/events.component.ts @@ -11,6 +11,7 @@ import { LogService } from "@bitwarden/common/abstractions/log.service"; import { OrganizationService } from "@bitwarden/common/abstractions/organization/organization.service.abstraction"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { ProviderService } from "@bitwarden/common/abstractions/provider.service"; +import { EventSystemUser } from "@bitwarden/common/enums/event-system-user"; import { Organization } from "@bitwarden/common/models/domain/organization"; import { EventResponse } from "@bitwarden/common/models/response/event.response"; @@ -114,17 +115,25 @@ export class EventsComponent extends BaseEventsComponent implements OnInit, OnDe } protected getUserName(r: EventResponse, userId: string) { - if (userId == null) { - return null; + if (r.installationId != null) { + return `Installation: ${r.installationId}`; } - if (this.orgUsersUserIdMap.has(userId)) { - return this.orgUsersUserIdMap.get(userId); + if (userId != null) { + if (this.orgUsersUserIdMap.has(userId)) { + return this.orgUsersUserIdMap.get(userId); + } + + if (r.providerId != null && r.providerId === this.organization.providerId) { + return { + name: this.organization.providerName, + }; + } } - if (r.providerId != null && r.providerId === this.organization.providerId) { + if (r.systemUser != null) { return { - name: this.organization.providerName, + name: EventSystemUser[r.systemUser], }; } diff --git a/bitwarden_license/bit-web/src/app/providers/manage/events.component.ts b/bitwarden_license/bit-web/src/app/providers/manage/events.component.ts index 0dd1b6de458..5c1105f6a79 100644 --- a/bitwarden_license/bit-web/src/app/providers/manage/events.component.ts +++ b/bitwarden_license/bit-web/src/app/providers/manage/events.component.ts @@ -82,8 +82,14 @@ export class EventsComponent extends BaseEventsComponent implements OnInit { } protected getUserName(r: EventResponse, userId: string) { - return userId != null && this.providerUsersUserIdMap.has(userId) - ? this.providerUsersUserIdMap.get(userId) - : null; + if (r.installationId != null) { + return `Installation: ${r.installationId}`; + } + + if (userId != null && this.providerUsersUserIdMap.has(userId)) { + return this.providerUsersUserIdMap.get(userId); + } + + return null; } } diff --git a/libs/common/src/enums/event-system-user.ts b/libs/common/src/enums/event-system-user.ts new file mode 100644 index 00000000000..cd9a73dd8f9 --- /dev/null +++ b/libs/common/src/enums/event-system-user.ts @@ -0,0 +1,4 @@ +// Note: the enum key is used to describe the EventSystemUser in the UI. Be careful about changing it. +export enum EventSystemUser { + SCIM = 1, +} diff --git a/libs/common/src/models/response/event.response.ts b/libs/common/src/models/response/event.response.ts index fe102019ccd..10897494ab7 100644 --- a/libs/common/src/models/response/event.response.ts +++ b/libs/common/src/models/response/event.response.ts @@ -1,4 +1,5 @@ import { DeviceType } from "../../enums/deviceType"; +import { EventSystemUser } from "../../enums/event-system-user"; import { EventType } from "../../enums/eventType"; import { BaseResponse } from "./base.response"; @@ -20,6 +21,7 @@ export class EventResponse extends BaseResponse { deviceType: DeviceType; ipAddress: string; installationId: string; + systemUser: EventSystemUser; constructor(response: any) { super(response); @@ -39,5 +41,6 @@ export class EventResponse extends BaseResponse { this.deviceType = this.getResponseProperty("DeviceType"); this.ipAddress = this.getResponseProperty("IpAddress"); this.installationId = this.getResponseProperty("InstallationId"); + this.systemUser = this.getResponseProperty("SystemUser"); } } diff --git a/libs/common/src/models/view/event.view.ts b/libs/common/src/models/view/event.view.ts index 56bf5c309e8..6b77c0b6286 100644 --- a/libs/common/src/models/view/event.view.ts +++ b/libs/common/src/models/view/event.view.ts @@ -1,3 +1,4 @@ +import { EventSystemUser } from "../../enums/event-system-user"; import { EventType } from "../../enums/eventType"; export class EventView { @@ -12,6 +13,7 @@ export class EventView { ip: string; type: EventType; installationId: string; + systemUser: EventSystemUser; constructor(data: Required) { this.message = data.message; @@ -25,5 +27,6 @@ export class EventView { this.ip = data.ip; this.type = data.type; this.installationId = data.installationId; + this.systemUser = data.systemUser; } }