generic event log component for user/ciphers

This commit is contained in:
Kyle Spearrin 2018-07-11 15:22:55 -04:00
parent 6d225beb46
commit 98d3b42728
8 changed files with 89 additions and 16 deletions

View File

@ -36,6 +36,7 @@ import {
CollectionAddEditComponent as OrgCollectionAddEditComponent, CollectionAddEditComponent as OrgCollectionAddEditComponent,
} from './organizations/manage/collection-add-edit.component'; } from './organizations/manage/collection-add-edit.component';
import { CollectionsComponent as OrgManageCollectionsComponent } from './organizations/manage/collections.component'; import { CollectionsComponent as OrgManageCollectionsComponent } from './organizations/manage/collections.component';
import { EntityEventsComponent as OrgEntityEventsComponent } from './organizations/manage/entity-events.component';
import { EntityUsersComponent as OrgEntityUsersComponent } from './organizations/manage/entity-users.component'; import { EntityUsersComponent as OrgEntityUsersComponent } from './organizations/manage/entity-users.component';
import { EventsComponent as OrgEventsComponent } from './organizations/manage/events.component'; import { EventsComponent as OrgEventsComponent } from './organizations/manage/events.component';
import { GroupAddEditComponent as OrgGroupAddEditComponent } from './organizations/manage/group-add-edit.component'; import { GroupAddEditComponent as OrgGroupAddEditComponent } from './organizations/manage/group-add-edit.component';
@ -43,7 +44,6 @@ import { GroupsComponent as OrgGroupsComponent } from './organizations/manage/gr
import { ManageComponent as OrgManageComponent } from './organizations/manage/manage.component'; import { ManageComponent as OrgManageComponent } from './organizations/manage/manage.component';
import { PeopleComponent as OrgPeopleComponent } from './organizations/manage/people.component'; import { PeopleComponent as OrgPeopleComponent } from './organizations/manage/people.component';
import { UserAddEditComponent as OrgUserAddEditComponent } from './organizations/manage/user-add-edit.component'; import { UserAddEditComponent as OrgUserAddEditComponent } from './organizations/manage/user-add-edit.component';
import { UserEventsComponent as OrgUserEventsComponent } from './organizations/manage/user-events.component';
import { UserGroupsComponent as OrgUserGroupsComponent } from './organizations/manage/user-groups.component'; import { UserGroupsComponent as OrgUserGroupsComponent } from './organizations/manage/user-groups.component';
import { ExportComponent as OrgExportComponent } from './organizations/tools/export.component'; import { ExportComponent as OrgExportComponent } from './organizations/tools/export.component';
@ -179,6 +179,7 @@ import { SearchPipe } from 'jslib/angular/pipes/search.pipe';
OrgCiphersComponent, OrgCiphersComponent,
OrgCollectionAddEditComponent, OrgCollectionAddEditComponent,
OrgCollectionsComponent, OrgCollectionsComponent,
OrgEntityEventsComponent,
OrgEntityUsersComponent, OrgEntityUsersComponent,
OrgEventsComponent, OrgEventsComponent,
OrgExportComponent, OrgExportComponent,
@ -191,7 +192,6 @@ import { SearchPipe } from 'jslib/angular/pipes/search.pipe';
OrgPeopleComponent, OrgPeopleComponent,
OrgToolsComponent, OrgToolsComponent,
OrgUserAddEditComponent, OrgUserAddEditComponent,
OrgUserEventsComponent,
OrgUserGroupsComponent, OrgUserGroupsComponent,
OrganizationsComponent, OrganizationsComponent,
OrganizationLayoutComponent, OrganizationLayoutComponent,
@ -241,10 +241,10 @@ import { SearchPipe } from 'jslib/angular/pipes/search.pipe';
OrgAttachmentsComponent, OrgAttachmentsComponent,
OrgCollectionAddEditComponent, OrgCollectionAddEditComponent,
OrgCollectionsComponent, OrgCollectionsComponent,
OrgEntityEventsComponent,
OrgEntityUsersComponent, OrgEntityUsersComponent,
OrgGroupAddEditComponent, OrgGroupAddEditComponent,
OrgUserAddEditComponent, OrgUserAddEditComponent,
OrgUserEventsComponent,
OrgUserGroupsComponent, OrgUserGroupsComponent,
PasswordGeneratorHistoryComponent, PasswordGeneratorHistoryComponent,
PurgeVaultComponent, PurgeVaultComponent,

View File

@ -41,6 +41,7 @@
<th class="border-top-0" width="40"> <th class="border-top-0" width="40">
<span class="sr-only">{{'device' | i18n}}</span> <span class="sr-only">{{'device' | i18n}}</span>
</th> </th>
<th class="border-top-0" width="150" *ngIf="showUser">{{'user' | i18n}}</th>
<th class="border-top-0">{{'event' | i18n}}</th> <th class="border-top-0">{{'event' | i18n}}</th>
</tr> </tr>
</thead> </thead>
@ -50,6 +51,9 @@
<td> <td>
<i class="text-muted fa fa-lg {{e.appIcon}}" title="{{e.appName}}, {{e.ip}}"></i> <i class="text-muted fa fa-lg {{e.appIcon}}" title="{{e.appName}}, {{e.ip}}"></i>
</td> </td>
<td *ngIf="showUser">
<span title="{{e.userEmail}}">{{e.userName}}</span>
</td>
<td [innerHTML]="e.message"></td> <td [innerHTML]="e.message"></td>
</tr> </tr>
</tbody> </tbody>

View File

@ -15,13 +15,15 @@ import { EventResponse } from 'jslib/models/response/eventResponse';
import { ListResponse } from 'jslib/models/response/listResponse'; import { ListResponse } from 'jslib/models/response/listResponse';
@Component({ @Component({
selector: 'app-user-events', selector: 'app-entity-events',
templateUrl: 'user-events.component.html', templateUrl: 'entity-events.component.html',
}) })
export class UserEventsComponent implements OnInit { export class EntityEventsComponent implements OnInit {
@Input() name: string; @Input() name: string;
@Input() organizationUserId: string; @Input() entity: 'user' | 'cipher';
@Input() entityId: string;
@Input() organizationId: string; @Input() organizationId: string;
@Input() showUser = false;
loading = true; loading = true;
loaded = false; loaded = false;
@ -32,6 +34,9 @@ export class UserEventsComponent implements OnInit {
refreshPromise: Promise<any>; refreshPromise: Promise<any>;
morePromise: Promise<any>; morePromise: Promise<any>;
private orgUsersUserIdMap = new Map<string, any>();
private orgUsersIdMap = new Map<string, any>();
constructor(private apiService: ApiService, private i18nService: I18nService, constructor(private apiService: ApiService, private i18nService: I18nService,
private eventService: EventService, private toasterService: ToasterService) { } private eventService: EventService, private toasterService: ToasterService) { }
@ -39,6 +44,18 @@ export class UserEventsComponent implements OnInit {
const defaultDates = this.eventService.getDefaultDateFilters(); const defaultDates = this.eventService.getDefaultDateFilters();
this.start = defaultDates[0]; this.start = defaultDates[0];
this.end = defaultDates[1]; this.end = defaultDates[1];
await this.load();
}
async load() {
if (this.showUser) {
const response = await this.apiService.getOrganizationUsers(this.organizationId);
response.data.forEach((u) => {
const name = u.name == null || u.name.trim() === '' ? u.email : u.name;
this.orgUsersIdMap.set(u.id, { name: name, email: u.email });
this.orgUsersUserIdMap.set(u.userId, { name: name, email: u.email });
});
}
await this.loadEvents(true); await this.loadEvents(true);
this.loaded = true; this.loaded = true;
} }
@ -60,8 +77,14 @@ export class UserEventsComponent implements OnInit {
this.loading = true; this.loading = true;
let response: ListResponse<EventResponse>; let response: ListResponse<EventResponse>;
try { try {
const promise = this.apiService.getEventsOrganizationUser(this.organizationId, this.organizationUserId, let promise: Promise<any>;
dates[0], dates[1], clearExisting ? null : this.continuationToken); if (this.entity === 'user') {
promise = this.apiService.getEventsOrganizationUser(this.organizationId, this.entityId,
dates[0], dates[1], clearExisting ? null : this.continuationToken);
} else {
promise = this.apiService.getEventsCipher(this.entityId,
dates[0], dates[1], clearExisting ? null : this.continuationToken);
}
if (clearExisting) { if (clearExisting) {
this.refreshPromise = promise; this.refreshPromise = promise;
} else { } else {
@ -74,11 +97,15 @@ export class UserEventsComponent implements OnInit {
const events = response.data.map((r) => { const events = response.data.map((r) => {
const userId = r.actingUserId == null ? r.userId : r.actingUserId; const userId = r.actingUserId == null ? r.userId : r.actingUserId;
const eventInfo = this.eventService.getEventInfo(r); const eventInfo = this.eventService.getEventInfo(r);
const user = this.showUser && userId != null && this.orgUsersUserIdMap.has(userId) ?
this.orgUsersUserIdMap.get(userId) : null;
return { return {
message: eventInfo.message, message: eventInfo.message,
appIcon: eventInfo.appIcon, appIcon: eventInfo.appIcon,
appName: eventInfo.appName, appName: eventInfo.appName,
userId: userId, userId: userId,
userName: user != null ? user.name : this.showUser ? this.i18nService.t('unknown') : null,
userEmail: user != null ? user.email : this.showUser ? '' : null,
date: r.date, date: r.date,
ip: r.ipAddress, ip: r.ipAddress,
type: r.type, type: r.type,

View File

@ -26,8 +26,8 @@ import { OrganizationUserType } from 'jslib/enums/organizationUserType';
import { Utils } from 'jslib/misc/utils'; import { Utils } from 'jslib/misc/utils';
import { ModalComponent } from '../../modal.component'; import { ModalComponent } from '../../modal.component';
import { EntityEventsComponent } from './entity-events.component';
import { UserAddEditComponent } from './user-add-edit.component'; import { UserAddEditComponent } from './user-add-edit.component';
import { UserEventsComponent } from './user-events.component';
import { UserGroupsComponent } from './user-groups.component'; import { UserGroupsComponent } from './user-groups.component';
@Component({ @Component({
@ -174,12 +174,14 @@ export class PeopleComponent implements OnInit {
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent); const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
this.modal = this.eventsModalRef.createComponent(factory).instance; this.modal = this.eventsModalRef.createComponent(factory).instance;
const childComponent = this.modal.show<UserEventsComponent>( const childComponent = this.modal.show<EntityEventsComponent>(
UserEventsComponent, this.eventsModalRef); EntityEventsComponent, this.eventsModalRef);
childComponent.name = user != null ? user.name || user.email : null; childComponent.name = user.name || user.email;
childComponent.organizationId = this.organizationId; childComponent.organizationId = this.organizationId;
childComponent.organizationUserId = user != null ? user.id : null; childComponent.entityId = user.id;
childComponent.showUser = false;
childComponent.entity = 'user';
this.modal.onClosed.subscribe(() => { this.modal.onClosed.subscribe(() => {
this.modal = null; this.modal = null;

View File

@ -1,4 +1,8 @@
import { Component } from '@angular/core'; import {
Component,
EventEmitter,
Output,
} from '@angular/core';
import { ToasterService } from 'angular2-toaster'; import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2'; import { Angulartics2 } from 'angulartics2';
@ -20,7 +24,10 @@ import { CiphersComponent as BaseCiphersComponent } from '../../vault/ciphers.co
templateUrl: '../../vault/ciphers.component.html', templateUrl: '../../vault/ciphers.component.html',
}) })
export class CiphersComponent extends BaseCiphersComponent { export class CiphersComponent extends BaseCiphersComponent {
@Output() onEventsClicked = new EventEmitter<CipherView>();
organization: Organization; organization: Organization;
accessEvents = false;
constructor(cipherService: CipherService, analytics: Angulartics2, constructor(cipherService: CipherService, analytics: Angulartics2,
toasterService: ToasterService, i18nService: I18nService, toasterService: ToasterService, i18nService: I18nService,
@ -33,6 +40,7 @@ export class CiphersComponent extends BaseCiphersComponent {
await super.load(); await super.load();
return; return;
} }
this.accessEvents = this.organization.useEvents;
const ciphers = await this.apiService.getCiphersOrganization(this.organization.id); const ciphers = await this.apiService.getCiphersOrganization(this.organization.id);
if (ciphers != null && ciphers.data != null && ciphers.data.length) { if (ciphers != null && ciphers.data != null && ciphers.data.length) {
const decCiphers: CipherView[] = []; const decCiphers: CipherView[] = [];
@ -64,4 +72,8 @@ export class CiphersComponent extends BaseCiphersComponent {
checkCipher(c: CipherView) { checkCipher(c: CipherView) {
// do nothing // do nothing
} }
events(c: CipherView) {
this.onEventsClicked.emit(c);
}
} }

View File

@ -13,7 +13,7 @@
</button> </button>
</div> </div>
<app-org-vault-ciphers (onCipherClicked)="editCipher($event)" (onAttachmentsClicked)="editCipherAttachments($event)" (onAddCipher)="addCipher()" <app-org-vault-ciphers (onCipherClicked)="editCipher($event)" (onAttachmentsClicked)="editCipherAttachments($event)" (onAddCipher)="addCipher()"
(onCollectionsClicked)="editCipherCollections($event)"> (onCollectionsClicked)="editCipherCollections($event)" (onEventsClicked)="viewEvents($event)">
</app-org-vault-ciphers> </app-org-vault-ciphers>
</div> </div>
</div> </div>
@ -21,3 +21,4 @@
<ng-template #attachments></ng-template> <ng-template #attachments></ng-template>
<ng-template #cipherAddEdit></ng-template> <ng-template #cipherAddEdit></ng-template>
<ng-template #collections></ng-template> <ng-template #collections></ng-template>
<ng-template #eventsTemplate></ng-template>

View File

@ -22,6 +22,7 @@ import { CipherType } from 'jslib/enums/cipherType';
import { ModalComponent } from '../../modal.component'; import { ModalComponent } from '../../modal.component';
import { EntityEventsComponent } from '../manage/entity-events.component';
import { AddEditComponent } from './add-edit.component'; import { AddEditComponent } from './add-edit.component';
import { AttachmentsComponent } from './attachments.component'; import { AttachmentsComponent } from './attachments.component';
import { CiphersComponent } from './ciphers.component'; import { CiphersComponent } from './ciphers.component';
@ -38,6 +39,7 @@ export class VaultComponent implements OnInit {
@ViewChild('attachments', { read: ViewContainerRef }) attachmentsModalRef: ViewContainerRef; @ViewChild('attachments', { read: ViewContainerRef }) attachmentsModalRef: ViewContainerRef;
@ViewChild('cipherAddEdit', { read: ViewContainerRef }) cipherAddEditModalRef: ViewContainerRef; @ViewChild('cipherAddEdit', { read: ViewContainerRef }) cipherAddEditModalRef: ViewContainerRef;
@ViewChild('collections', { read: ViewContainerRef }) collectionsModalRef: ViewContainerRef; @ViewChild('collections', { read: ViewContainerRef }) collectionsModalRef: ViewContainerRef;
@ViewChild('eventsTemplate', { read: ViewContainerRef }) eventsModalRef: ViewContainerRef;
organization: Organization; organization: Organization;
collectionId: string; collectionId: string;
@ -210,6 +212,27 @@ export class VaultComponent implements OnInit {
return childComponent; return childComponent;
} }
async viewEvents(cipher: CipherView) {
if (this.modal != null) {
this.modal.close();
}
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
this.modal = this.eventsModalRef.createComponent(factory).instance;
const childComponent = this.modal.show<EntityEventsComponent>(
EntityEventsComponent, this.eventsModalRef);
childComponent.name = cipher.name;
childComponent.organizationId = this.organization.id;
childComponent.entityId = cipher.id;
childComponent.showUser = true;
childComponent.entity = 'cipher';
this.modal.onClosed.subscribe(() => {
this.modal = null;
});
}
private clearFilters() { private clearFilters() {
this.collectionId = null; this.collectionId = null;
this.type = null; this.type = null;

View File

@ -38,6 +38,10 @@
<i class="fa fa-fw fa-cubes"></i> <i class="fa fa-fw fa-cubes"></i>
{{'collections' | i18n}} {{'collections' | i18n}}
</a> </a>
<a class="dropdown-item" href="#" appStopClick *ngIf="c.organizationId && accessEvents" (click)="events(c)">
<i class="fa fa-fw fa-file-text-o"></i>
{{'eventLogs' | i18n}}
</a>
<a class="dropdown-item text-danger" href="#" appStopClick (click)="delete(c)"> <a class="dropdown-item text-danger" href="#" appStopClick (click)="delete(c)">
<i class="fa fa-fw fa-trash-o"></i> <i class="fa fa-fw fa-trash-o"></i>
{{'delete' | i18n}} {{'delete' | i18n}}