1
0
mirror of https://github.com/bitwarden/web synced 2026-02-28 18:33:37 +00:00

Apply Prettier (#1347)

This commit is contained in:
Oscar Hinton
2021-12-17 15:57:11 +01:00
committed by GitHub
parent 2b0a9d995e
commit 56477eb39c
414 changed files with 33390 additions and 26857 deletions

View File

@@ -1,438 +1,554 @@
import { Injectable } from '@angular/core';
import { Injectable } from "@angular/core";
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { PolicyService } from 'jslib-common/abstractions/policy.service';
import { I18nService } from "jslib-common/abstractions/i18n.service";
import { PolicyService } from "jslib-common/abstractions/policy.service";
import { DeviceType } from 'jslib-common/enums/deviceType';
import { EventType } from 'jslib-common/enums/eventType';
import { PolicyType } from 'jslib-common/enums/policyType';
import { EventResponse } from 'jslib-common/models/response/eventResponse';
import { DeviceType } from "jslib-common/enums/deviceType";
import { EventType } from "jslib-common/enums/eventType";
import { PolicyType } from "jslib-common/enums/policyType";
import { EventResponse } from "jslib-common/models/response/eventResponse";
@Injectable()
export class EventService {
constructor(private i18nService: I18nService, private policyService: PolicyService) { }
constructor(private i18nService: I18nService, private policyService: PolicyService) {}
getDefaultDateFilters() {
const d = new Date();
const end = new Date(d.getFullYear(), d.getMonth(), d.getDate(), 23, 59);
d.setDate(d.getDate() - 30);
const start = new Date(d.getFullYear(), d.getMonth(), d.getDate(), 0, 0);
return [this.toDateTimeLocalString(start), this.toDateTimeLocalString(end)];
getDefaultDateFilters() {
const d = new Date();
const end = new Date(d.getFullYear(), d.getMonth(), d.getDate(), 23, 59);
d.setDate(d.getDate() - 30);
const start = new Date(d.getFullYear(), d.getMonth(), d.getDate(), 0, 0);
return [this.toDateTimeLocalString(start), this.toDateTimeLocalString(end)];
}
formatDateFilters(filterStart: string, filterEnd: string) {
const start: Date = new Date(filterStart);
const end: Date = new Date(filterEnd + ":59.999");
if (isNaN(start.getTime()) || isNaN(end.getTime()) || end < start) {
throw new Error("Invalid date range.");
}
return [start.toISOString(), end.toISOString()];
}
formatDateFilters(filterStart: string, filterEnd: string) {
const start: Date = new Date(filterStart);
const end: Date = new Date(filterEnd + ':59.999');
if (isNaN(start.getTime()) || isNaN(end.getTime()) || end < start) {
throw new Error('Invalid date range.');
}
return [start.toISOString(), end.toISOString()];
}
async getEventInfo(ev: EventResponse, options = new EventOptions()): Promise<EventInfo> {
const appInfo = this.getAppInfo(ev.deviceType);
const { message, humanReadableMessage } = await this.getEventMessage(ev, options);
return {
message: message,
humanReadableMessage: humanReadableMessage,
appIcon: appInfo[0],
appName: appInfo[1],
};
}
async getEventInfo(ev: EventResponse, options = new EventOptions()): Promise<EventInfo> {
const appInfo = this.getAppInfo(ev.deviceType);
const { message, humanReadableMessage } = await this.getEventMessage(ev, options);
return {
message: message,
humanReadableMessage: humanReadableMessage,
appIcon: appInfo[0],
appName: appInfo[1],
};
}
private async getEventMessage(ev: EventResponse, options: EventOptions) {
let msg = '';
let humanReadableMsg = '';
switch (ev.type) {
// User
case EventType.User_LoggedIn:
msg = humanReadableMsg = this.i18nService.t('loggedIn');
break;
case EventType.User_ChangedPassword:
msg = humanReadableMsg = this.i18nService.t('changedPassword');
break;
case EventType.User_Updated2fa:
msg = humanReadableMsg = this.i18nService.t('enabledUpdated2fa');
break;
case EventType.User_Disabled2fa:
msg = humanReadableMsg = this.i18nService.t('disabled2fa');
break;
case EventType.User_Recovered2fa:
msg = humanReadableMsg = this.i18nService.t('recovered2fa');
break;
case EventType.User_FailedLogIn:
msg = humanReadableMsg = this.i18nService.t('failedLogin');
break;
case EventType.User_FailedLogIn2fa:
msg = humanReadableMsg = this.i18nService.t('failedLogin2fa');
break;
case EventType.User_ClientExportedVault:
msg = humanReadableMsg = this.i18nService.t('exportedVault');
break;
case EventType.User_UpdatedTempPassword:
msg = humanReadableMsg = this.i18nService.t('updatedMasterPassword');
break;
case EventType.User_MigratedKeyToKeyConnector:
msg = humanReadableMsg = this.i18nService.t('migratedKeyConnector');
break;
// Cipher
case EventType.Cipher_Created:
msg = this.i18nService.t('createdItemId', this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t('createdItemId', this.getShortId(ev.cipherId));
break;
case EventType.Cipher_Updated:
msg = this.i18nService.t('editedItemId', this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t('editedItemId', this.getShortId(ev.cipherId));
break;
case EventType.Cipher_Deleted:
msg = this.i18nService.t('permanentlyDeletedItemId', this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t('permanentlyDeletedItemId', this.getShortId(ev.cipherId));
break;
case EventType.Cipher_SoftDeleted:
msg = this.i18nService.t('deletedItemId', this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t('deletedItemId', this.getShortId(ev.cipherId));
break;
case EventType.Cipher_Restored:
msg = this.i18nService.t('restoredItemId', this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t('restoredItemId', this.formatCipherId(ev, options));
break;
case EventType.Cipher_AttachmentCreated:
msg = this.i18nService.t('createdAttachmentForItem', this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t('createdAttachmentForItem', this.getShortId(ev.cipherId));
break;
case EventType.Cipher_AttachmentDeleted:
msg = this.i18nService.t('deletedAttachmentForItem', this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t('deletedAttachmentForItem', this.getShortId(ev.cipherId));
break;
case EventType.Cipher_Shared:
msg = this.i18nService.t('movedItemIdToOrg', this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t('movedItemIdToOrg', this.getShortId(ev.cipherId));
break;
case EventType.Cipher_ClientViewed:
msg = this.i18nService.t('viewedItemId', this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t('viewedItemId', this.getShortId(ev.cipherId));
break;
case EventType.Cipher_ClientToggledPasswordVisible:
msg = this.i18nService.t('viewedPasswordItemId', this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t('viewedPasswordItemId', this.getShortId(ev.cipherId));
break;
case EventType.Cipher_ClientToggledHiddenFieldVisible:
msg = this.i18nService.t('viewedHiddenFieldItemId', this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t('viewedHiddenFieldItemId', this.getShortId(ev.cipherId));
break;
case EventType.Cipher_ClientToggledCardCodeVisible:
msg = this.i18nService.t('viewedSecurityCodeItemId', this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t('viewedSecurityCodeItemId', this.getShortId(ev.cipherId));
break;
case EventType.Cipher_ClientCopiedHiddenField:
msg = this.i18nService.t('copiedHiddenFieldItemId', this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t('copiedHiddenFieldItemId', this.getShortId(ev.cipherId));
break;
case EventType.Cipher_ClientCopiedPassword:
msg = this.i18nService.t('copiedPasswordItemId', this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t('copiedPasswordItemId', this.getShortId(ev.cipherId));
break;
case EventType.Cipher_ClientCopiedCardCode:
msg = this.i18nService.t('copiedSecurityCodeItemId', this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t('copiedSecurityCodeItemId', this.getShortId(ev.cipherId));
break;
case EventType.Cipher_ClientAutofilled:
msg = this.i18nService.t('autofilledItemId', this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t('autofilledItemId', this.getShortId(ev.cipherId));
break;
case EventType.Cipher_UpdatedCollections:
msg = this.i18nService.t('editedCollectionsForItem', this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t('editedCollectionsForItem', this.getShortId(ev.cipherId));
break;
// Collection
case EventType.Collection_Created:
msg = this.i18nService.t('createdCollectionId', this.formatCollectionId(ev));
humanReadableMsg = this.i18nService.t('createdCollectionId', this.getShortId(ev.collectionId));
break;
case EventType.Collection_Updated:
msg = this.i18nService.t('editedCollectionId', this.formatCollectionId(ev));
humanReadableMsg = this.i18nService.t('editedCollectionId', this.getShortId(ev.collectionId));
break;
case EventType.Collection_Deleted:
msg = this.i18nService.t('deletedCollectionId', this.formatCollectionId(ev));
humanReadableMsg = this.i18nService.t('deletedCollectionId', this.getShortId(ev.collectionId));
break;
// Group
case EventType.Group_Created:
msg = this.i18nService.t('createdGroupId', this.formatGroupId(ev));
humanReadableMsg = this.i18nService.t('createdGroupId', this.getShortId(ev.groupId));
break;
case EventType.Group_Updated:
msg = this.i18nService.t('editedGroupId', this.formatGroupId(ev));
humanReadableMsg = this.i18nService.t('editedGroupId', this.getShortId(ev.groupId));
break;
case EventType.Group_Deleted:
msg = this.i18nService.t('deletedGroupId', this.formatGroupId(ev));
humanReadableMsg = this.i18nService.t('deletedGroupId', this.getShortId(ev.groupId));
break;
// Org user
case EventType.OrganizationUser_Invited:
msg = this.i18nService.t('invitedUserId', this.formatOrgUserId(ev));
humanReadableMsg = this.i18nService.t('invitedUserId', this.getShortId(ev.organizationUserId));
break;
case EventType.OrganizationUser_Confirmed:
msg = this.i18nService.t('confirmedUserId', this.formatOrgUserId(ev));
humanReadableMsg = this.i18nService.t('confirmedUserId', this.getShortId(ev.organizationUserId));
break;
case EventType.OrganizationUser_Updated:
msg = this.i18nService.t('editedUserId', this.formatOrgUserId(ev));
humanReadableMsg = this.i18nService.t('editedUserId', this.getShortId(ev.organizationUserId));
break;
case EventType.OrganizationUser_Removed:
msg = this.i18nService.t('removedUserId', this.formatOrgUserId(ev));
humanReadableMsg = this.i18nService.t('removedUserId', this.getShortId(ev.organizationUserId));
break;
case EventType.OrganizationUser_UpdatedGroups:
msg = this.i18nService.t('editedGroupsForUser', this.formatOrgUserId(ev));
humanReadableMsg = this.i18nService.t('editedGroupsForUser', this.getShortId(ev.organizationUserId));
break;
case EventType.OrganizationUser_UnlinkedSso:
msg = this.i18nService.t('unlinkedSsoUser', this.formatOrgUserId(ev));
humanReadableMsg = this.i18nService.t('unlinkedSsoUser', this.getShortId(ev.organizationUserId));
break;
case EventType.OrganizationUser_ResetPassword_Enroll:
msg = this.i18nService.t('eventEnrollPasswordReset', this.formatOrgUserId(ev));
humanReadableMsg = this.i18nService.t('eventEnrollPasswordReset', this.getShortId(ev.organizationUserId));
break;
case EventType.OrganizationUser_ResetPassword_Withdraw:
msg = this.i18nService.t('eventWithdrawPasswordReset', this.formatOrgUserId(ev));
humanReadableMsg = this.i18nService.t('eventWithdrawPasswordReset', this.getShortId(ev.organizationUserId));
break;
case EventType.OrganizationUser_AdminResetPassword:
msg = this.i18nService.t('eventAdminPasswordReset', this.formatOrgUserId(ev));
humanReadableMsg = this.i18nService.t('eventAdminPasswordReset', this.getShortId(ev.organizationUserId));
break;
case EventType.OrganizationUser_ResetSsoLink:
msg = this.i18nService.t('eventResetSsoLink', this.formatOrgUserId(ev));
humanReadableMsg = this.i18nService.t('eventResetSsoLink', this.getShortId(ev.organizationUserId));
break;
case EventType.OrganizationUser_FirstSsoLogin:
msg = this.i18nService.t('firstSsoLogin', this.formatOrgUserId(ev));
humanReadableMsg = this.i18nService.t('firstSsoLogin', this.getShortId(ev.organizationUserId));
break;
// Org
case EventType.Organization_Updated:
msg = humanReadableMsg = this.i18nService.t('editedOrgSettings');
break;
case EventType.Organization_PurgedVault:
msg = humanReadableMsg = this.i18nService.t('purgedOrganizationVault');
break;
/*
private async getEventMessage(ev: EventResponse, options: EventOptions) {
let msg = "";
let humanReadableMsg = "";
switch (ev.type) {
// User
case EventType.User_LoggedIn:
msg = humanReadableMsg = this.i18nService.t("loggedIn");
break;
case EventType.User_ChangedPassword:
msg = humanReadableMsg = this.i18nService.t("changedPassword");
break;
case EventType.User_Updated2fa:
msg = humanReadableMsg = this.i18nService.t("enabledUpdated2fa");
break;
case EventType.User_Disabled2fa:
msg = humanReadableMsg = this.i18nService.t("disabled2fa");
break;
case EventType.User_Recovered2fa:
msg = humanReadableMsg = this.i18nService.t("recovered2fa");
break;
case EventType.User_FailedLogIn:
msg = humanReadableMsg = this.i18nService.t("failedLogin");
break;
case EventType.User_FailedLogIn2fa:
msg = humanReadableMsg = this.i18nService.t("failedLogin2fa");
break;
case EventType.User_ClientExportedVault:
msg = humanReadableMsg = this.i18nService.t("exportedVault");
break;
case EventType.User_UpdatedTempPassword:
msg = humanReadableMsg = this.i18nService.t("updatedMasterPassword");
break;
case EventType.User_MigratedKeyToKeyConnector:
msg = humanReadableMsg = this.i18nService.t("migratedKeyConnector");
break;
// Cipher
case EventType.Cipher_Created:
msg = this.i18nService.t("createdItemId", this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t("createdItemId", this.getShortId(ev.cipherId));
break;
case EventType.Cipher_Updated:
msg = this.i18nService.t("editedItemId", this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t("editedItemId", this.getShortId(ev.cipherId));
break;
case EventType.Cipher_Deleted:
msg = this.i18nService.t("permanentlyDeletedItemId", this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t(
"permanentlyDeletedItemId",
this.getShortId(ev.cipherId)
);
break;
case EventType.Cipher_SoftDeleted:
msg = this.i18nService.t("deletedItemId", this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t("deletedItemId", this.getShortId(ev.cipherId));
break;
case EventType.Cipher_Restored:
msg = this.i18nService.t("restoredItemId", this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t("restoredItemId", this.formatCipherId(ev, options));
break;
case EventType.Cipher_AttachmentCreated:
msg = this.i18nService.t("createdAttachmentForItem", this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t(
"createdAttachmentForItem",
this.getShortId(ev.cipherId)
);
break;
case EventType.Cipher_AttachmentDeleted:
msg = this.i18nService.t("deletedAttachmentForItem", this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t(
"deletedAttachmentForItem",
this.getShortId(ev.cipherId)
);
break;
case EventType.Cipher_Shared:
msg = this.i18nService.t("movedItemIdToOrg", this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t("movedItemIdToOrg", this.getShortId(ev.cipherId));
break;
case EventType.Cipher_ClientViewed:
msg = this.i18nService.t("viewedItemId", this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t("viewedItemId", this.getShortId(ev.cipherId));
break;
case EventType.Cipher_ClientToggledPasswordVisible:
msg = this.i18nService.t("viewedPasswordItemId", this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t("viewedPasswordItemId", this.getShortId(ev.cipherId));
break;
case EventType.Cipher_ClientToggledHiddenFieldVisible:
msg = this.i18nService.t("viewedHiddenFieldItemId", this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t(
"viewedHiddenFieldItemId",
this.getShortId(ev.cipherId)
);
break;
case EventType.Cipher_ClientToggledCardCodeVisible:
msg = this.i18nService.t("viewedSecurityCodeItemId", this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t(
"viewedSecurityCodeItemId",
this.getShortId(ev.cipherId)
);
break;
case EventType.Cipher_ClientCopiedHiddenField:
msg = this.i18nService.t("copiedHiddenFieldItemId", this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t(
"copiedHiddenFieldItemId",
this.getShortId(ev.cipherId)
);
break;
case EventType.Cipher_ClientCopiedPassword:
msg = this.i18nService.t("copiedPasswordItemId", this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t("copiedPasswordItemId", this.getShortId(ev.cipherId));
break;
case EventType.Cipher_ClientCopiedCardCode:
msg = this.i18nService.t("copiedSecurityCodeItemId", this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t(
"copiedSecurityCodeItemId",
this.getShortId(ev.cipherId)
);
break;
case EventType.Cipher_ClientAutofilled:
msg = this.i18nService.t("autofilledItemId", this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t("autofilledItemId", this.getShortId(ev.cipherId));
break;
case EventType.Cipher_UpdatedCollections:
msg = this.i18nService.t("editedCollectionsForItem", this.formatCipherId(ev, options));
humanReadableMsg = this.i18nService.t(
"editedCollectionsForItem",
this.getShortId(ev.cipherId)
);
break;
// Collection
case EventType.Collection_Created:
msg = this.i18nService.t("createdCollectionId", this.formatCollectionId(ev));
humanReadableMsg = this.i18nService.t(
"createdCollectionId",
this.getShortId(ev.collectionId)
);
break;
case EventType.Collection_Updated:
msg = this.i18nService.t("editedCollectionId", this.formatCollectionId(ev));
humanReadableMsg = this.i18nService.t(
"editedCollectionId",
this.getShortId(ev.collectionId)
);
break;
case EventType.Collection_Deleted:
msg = this.i18nService.t("deletedCollectionId", this.formatCollectionId(ev));
humanReadableMsg = this.i18nService.t(
"deletedCollectionId",
this.getShortId(ev.collectionId)
);
break;
// Group
case EventType.Group_Created:
msg = this.i18nService.t("createdGroupId", this.formatGroupId(ev));
humanReadableMsg = this.i18nService.t("createdGroupId", this.getShortId(ev.groupId));
break;
case EventType.Group_Updated:
msg = this.i18nService.t("editedGroupId", this.formatGroupId(ev));
humanReadableMsg = this.i18nService.t("editedGroupId", this.getShortId(ev.groupId));
break;
case EventType.Group_Deleted:
msg = this.i18nService.t("deletedGroupId", this.formatGroupId(ev));
humanReadableMsg = this.i18nService.t("deletedGroupId", this.getShortId(ev.groupId));
break;
// Org user
case EventType.OrganizationUser_Invited:
msg = this.i18nService.t("invitedUserId", this.formatOrgUserId(ev));
humanReadableMsg = this.i18nService.t(
"invitedUserId",
this.getShortId(ev.organizationUserId)
);
break;
case EventType.OrganizationUser_Confirmed:
msg = this.i18nService.t("confirmedUserId", this.formatOrgUserId(ev));
humanReadableMsg = this.i18nService.t(
"confirmedUserId",
this.getShortId(ev.organizationUserId)
);
break;
case EventType.OrganizationUser_Updated:
msg = this.i18nService.t("editedUserId", this.formatOrgUserId(ev));
humanReadableMsg = this.i18nService.t(
"editedUserId",
this.getShortId(ev.organizationUserId)
);
break;
case EventType.OrganizationUser_Removed:
msg = this.i18nService.t("removedUserId", this.formatOrgUserId(ev));
humanReadableMsg = this.i18nService.t(
"removedUserId",
this.getShortId(ev.organizationUserId)
);
break;
case EventType.OrganizationUser_UpdatedGroups:
msg = this.i18nService.t("editedGroupsForUser", this.formatOrgUserId(ev));
humanReadableMsg = this.i18nService.t(
"editedGroupsForUser",
this.getShortId(ev.organizationUserId)
);
break;
case EventType.OrganizationUser_UnlinkedSso:
msg = this.i18nService.t("unlinkedSsoUser", this.formatOrgUserId(ev));
humanReadableMsg = this.i18nService.t(
"unlinkedSsoUser",
this.getShortId(ev.organizationUserId)
);
break;
case EventType.OrganizationUser_ResetPassword_Enroll:
msg = this.i18nService.t("eventEnrollPasswordReset", this.formatOrgUserId(ev));
humanReadableMsg = this.i18nService.t(
"eventEnrollPasswordReset",
this.getShortId(ev.organizationUserId)
);
break;
case EventType.OrganizationUser_ResetPassword_Withdraw:
msg = this.i18nService.t("eventWithdrawPasswordReset", this.formatOrgUserId(ev));
humanReadableMsg = this.i18nService.t(
"eventWithdrawPasswordReset",
this.getShortId(ev.organizationUserId)
);
break;
case EventType.OrganizationUser_AdminResetPassword:
msg = this.i18nService.t("eventAdminPasswordReset", this.formatOrgUserId(ev));
humanReadableMsg = this.i18nService.t(
"eventAdminPasswordReset",
this.getShortId(ev.organizationUserId)
);
break;
case EventType.OrganizationUser_ResetSsoLink:
msg = this.i18nService.t("eventResetSsoLink", this.formatOrgUserId(ev));
humanReadableMsg = this.i18nService.t(
"eventResetSsoLink",
this.getShortId(ev.organizationUserId)
);
break;
case EventType.OrganizationUser_FirstSsoLogin:
msg = this.i18nService.t("firstSsoLogin", this.formatOrgUserId(ev));
humanReadableMsg = this.i18nService.t(
"firstSsoLogin",
this.getShortId(ev.organizationUserId)
);
break;
// Org
case EventType.Organization_Updated:
msg = humanReadableMsg = this.i18nService.t("editedOrgSettings");
break;
case EventType.Organization_PurgedVault:
msg = humanReadableMsg = this.i18nService.t("purgedOrganizationVault");
break;
/*
case EventType.Organization_ClientExportedVault:
msg = this.i18nService.t('exportedOrganizationVault');
break;
*/
case EventType.Organization_VaultAccessed:
msg = humanReadableMsg = this.i18nService.t('vaultAccessedByProvider');
break;
case EventType.Organization_EnabledSso:
msg = humanReadableMsg = this.i18nService.t('enabledSso');
break;
case EventType.Organization_DisabledSso:
msg = humanReadableMsg = this.i18nService.t('disabledSso');
break;
case EventType.Organization_EnabledKeyConnector:
msg = humanReadableMsg = this.i18nService.t('enabledKeyConnector');
break;
case EventType.Organization_DisabledKeyConnector:
msg = humanReadableMsg = this.i18nService.t('disabledKeyConnector');
break;
// Policies
case EventType.Policy_Updated:
msg = this.i18nService.t('modifiedPolicyId', this.formatPolicyId(ev));
case EventType.Organization_VaultAccessed:
msg = humanReadableMsg = this.i18nService.t("vaultAccessedByProvider");
break;
case EventType.Organization_EnabledSso:
msg = humanReadableMsg = this.i18nService.t("enabledSso");
break;
case EventType.Organization_DisabledSso:
msg = humanReadableMsg = this.i18nService.t("disabledSso");
break;
case EventType.Organization_EnabledKeyConnector:
msg = humanReadableMsg = this.i18nService.t("enabledKeyConnector");
break;
case EventType.Organization_DisabledKeyConnector:
msg = humanReadableMsg = this.i18nService.t("disabledKeyConnector");
break;
// Policies
case EventType.Policy_Updated:
msg = this.i18nService.t("modifiedPolicyId", this.formatPolicyId(ev));
const policies = await this.policyService.getAll();
const policy = policies.filter(p => p.id === ev.policyId)[0];
let p1 = this.getShortId(ev.policyId);
if (policy != null) {
p1 = PolicyType[policy.type];
}
humanReadableMsg = this.i18nService.t('modifiedPolicyId', p1);
break;
// Provider users:
case EventType.ProviderUser_Invited:
msg = this.i18nService.t('invitedUserId', this.formatProviderUserId(ev));
humanReadableMsg = this.i18nService.t('invitedUserId', this.getShortId(ev.providerUserId));
break;
case EventType.ProviderUser_Confirmed:
msg = this.i18nService.t('confirmedUserId', this.formatProviderUserId(ev));
humanReadableMsg = this.i18nService.t('confirmedUserId', this.getShortId(ev.providerUserId));
break;
case EventType.ProviderUser_Updated:
msg = this.i18nService.t('editedUserId', this.formatProviderUserId(ev));
humanReadableMsg = this.i18nService.t('editedUserId', this.getShortId(ev.providerUserId));
break;
case EventType.ProviderUser_Removed:
msg = this.i18nService.t('removedUserId', this.formatProviderUserId(ev));
humanReadableMsg = this.i18nService.t('removedUserId', this.getShortId(ev.providerUserId));
break;
case EventType.ProviderOrganization_Created:
msg = this.i18nService.t('createdOrganizationId', this.formatProviderOrganizationId(ev));
humanReadableMsg = this.i18nService.t('createdOrganizationId', this.getShortId(ev.providerOrganizationId));
break;
case EventType.ProviderOrganization_Added:
msg = this.i18nService.t('addedOrganizationId', this.formatProviderOrganizationId(ev));
humanReadableMsg = this.i18nService.t('addedOrganizationId', this.getShortId(ev.providerOrganizationId));
break;
case EventType.ProviderOrganization_Removed:
msg = this.i18nService.t('removedOrganizationId', this.formatProviderOrganizationId(ev));
humanReadableMsg = this.i18nService.t('removedOrganizationId', this.getShortId(ev.providerOrganizationId));
break;
case EventType.ProviderOrganization_VaultAccessed:
msg = this.i18nService.t('accessedClientVault', this.formatProviderOrganizationId(ev));
humanReadableMsg = this.i18nService.t('accessedClientVault', this.getShortId(ev.providerOrganizationId));
break;
default:
break;
const policies = await this.policyService.getAll();
const policy = policies.filter((p) => p.id === ev.policyId)[0];
let p1 = this.getShortId(ev.policyId);
if (policy != null) {
p1 = PolicyType[policy.type];
}
return {
message: msg === '' ? null : msg,
humanReadableMessage: humanReadableMsg === '' ? null : humanReadableMsg,
};
}
private getAppInfo(deviceType: DeviceType): [string, string] {
switch (deviceType) {
case DeviceType.Android:
return ['fa-android', this.i18nService.t('mobile') + ' - Android'];
case DeviceType.iOS:
return ['fa-apple', this.i18nService.t('mobile') + ' - iOS'];
case DeviceType.UWP:
return ['fa-windows', this.i18nService.t('mobile') + ' - Windows'];
case DeviceType.ChromeExtension:
return ['fa-chrome', this.i18nService.t('extension') + ' - Chrome'];
case DeviceType.FirefoxExtension:
return ['fa-firefox', this.i18nService.t('extension') + ' - Firefox'];
case DeviceType.OperaExtension:
return ['fa-opera', this.i18nService.t('extension') + ' - Opera'];
case DeviceType.EdgeExtension:
return ['fa-edge', this.i18nService.t('extension') + ' - Edge'];
case DeviceType.VivaldiExtension:
return ['fa-puzzle-piece', this.i18nService.t('extension') + ' - Vivaldi'];
case DeviceType.SafariExtension:
return ['fa-safari', this.i18nService.t('extension') + ' - Safari'];
case DeviceType.WindowsDesktop:
return ['fa-windows', this.i18nService.t('desktop') + ' - Windows'];
case DeviceType.MacOsDesktop:
return ['fa-apple', this.i18nService.t('desktop') + ' - macOS'];
case DeviceType.LinuxDesktop:
return ['fa-linux', this.i18nService.t('desktop') + ' - Linux'];
case DeviceType.ChromeBrowser:
return ['fa-globe', this.i18nService.t('webVault') + ' - Chrome'];
case DeviceType.FirefoxBrowser:
return ['fa-globe', this.i18nService.t('webVault') + ' - Firefox'];
case DeviceType.OperaBrowser:
return ['fa-globe', this.i18nService.t('webVault') + ' - Opera'];
case DeviceType.SafariBrowser:
return ['fa-globe', this.i18nService.t('webVault') + ' - Safari'];
case DeviceType.VivaldiBrowser:
return ['fa-globe', this.i18nService.t('webVault') + ' - Vivaldi'];
case DeviceType.EdgeBrowser:
return ['fa-globe', this.i18nService.t('webVault') + ' - Edge'];
case DeviceType.IEBrowser:
return ['fa-globe', this.i18nService.t('webVault') + ' - IE'];
case DeviceType.UnknownBrowser:
return ['fa-globe', this.i18nService.t('webVault') + ' - ' + this.i18nService.t('unknown')];
default:
return ['fa-globe', this.i18nService.t('unknown')];
}
humanReadableMsg = this.i18nService.t("modifiedPolicyId", p1);
break;
// Provider users:
case EventType.ProviderUser_Invited:
msg = this.i18nService.t("invitedUserId", this.formatProviderUserId(ev));
humanReadableMsg = this.i18nService.t("invitedUserId", this.getShortId(ev.providerUserId));
break;
case EventType.ProviderUser_Confirmed:
msg = this.i18nService.t("confirmedUserId", this.formatProviderUserId(ev));
humanReadableMsg = this.i18nService.t(
"confirmedUserId",
this.getShortId(ev.providerUserId)
);
break;
case EventType.ProviderUser_Updated:
msg = this.i18nService.t("editedUserId", this.formatProviderUserId(ev));
humanReadableMsg = this.i18nService.t("editedUserId", this.getShortId(ev.providerUserId));
break;
case EventType.ProviderUser_Removed:
msg = this.i18nService.t("removedUserId", this.formatProviderUserId(ev));
humanReadableMsg = this.i18nService.t("removedUserId", this.getShortId(ev.providerUserId));
break;
case EventType.ProviderOrganization_Created:
msg = this.i18nService.t("createdOrganizationId", this.formatProviderOrganizationId(ev));
humanReadableMsg = this.i18nService.t(
"createdOrganizationId",
this.getShortId(ev.providerOrganizationId)
);
break;
case EventType.ProviderOrganization_Added:
msg = this.i18nService.t("addedOrganizationId", this.formatProviderOrganizationId(ev));
humanReadableMsg = this.i18nService.t(
"addedOrganizationId",
this.getShortId(ev.providerOrganizationId)
);
break;
case EventType.ProviderOrganization_Removed:
msg = this.i18nService.t("removedOrganizationId", this.formatProviderOrganizationId(ev));
humanReadableMsg = this.i18nService.t(
"removedOrganizationId",
this.getShortId(ev.providerOrganizationId)
);
break;
case EventType.ProviderOrganization_VaultAccessed:
msg = this.i18nService.t("accessedClientVault", this.formatProviderOrganizationId(ev));
humanReadableMsg = this.i18nService.t(
"accessedClientVault",
this.getShortId(ev.providerOrganizationId)
);
break;
default:
break;
}
return {
message: msg === "" ? null : msg,
humanReadableMessage: humanReadableMsg === "" ? null : humanReadableMsg,
};
}
private formatCipherId(ev: EventResponse, options: EventOptions) {
const shortId = this.getShortId(ev.cipherId);
if (ev.organizationId == null || !options.cipherInfo) {
return '<code>' + shortId + '</code>';
}
const a = this.makeAnchor(shortId);
a.setAttribute('href', '#/organizations/' + ev.organizationId + '/vault?search=' + shortId +
'&viewEvents=' + ev.cipherId);
return a.outerHTML;
private getAppInfo(deviceType: DeviceType): [string, string] {
switch (deviceType) {
case DeviceType.Android:
return ["fa-android", this.i18nService.t("mobile") + " - Android"];
case DeviceType.iOS:
return ["fa-apple", this.i18nService.t("mobile") + " - iOS"];
case DeviceType.UWP:
return ["fa-windows", this.i18nService.t("mobile") + " - Windows"];
case DeviceType.ChromeExtension:
return ["fa-chrome", this.i18nService.t("extension") + " - Chrome"];
case DeviceType.FirefoxExtension:
return ["fa-firefox", this.i18nService.t("extension") + " - Firefox"];
case DeviceType.OperaExtension:
return ["fa-opera", this.i18nService.t("extension") + " - Opera"];
case DeviceType.EdgeExtension:
return ["fa-edge", this.i18nService.t("extension") + " - Edge"];
case DeviceType.VivaldiExtension:
return ["fa-puzzle-piece", this.i18nService.t("extension") + " - Vivaldi"];
case DeviceType.SafariExtension:
return ["fa-safari", this.i18nService.t("extension") + " - Safari"];
case DeviceType.WindowsDesktop:
return ["fa-windows", this.i18nService.t("desktop") + " - Windows"];
case DeviceType.MacOsDesktop:
return ["fa-apple", this.i18nService.t("desktop") + " - macOS"];
case DeviceType.LinuxDesktop:
return ["fa-linux", this.i18nService.t("desktop") + " - Linux"];
case DeviceType.ChromeBrowser:
return ["fa-globe", this.i18nService.t("webVault") + " - Chrome"];
case DeviceType.FirefoxBrowser:
return ["fa-globe", this.i18nService.t("webVault") + " - Firefox"];
case DeviceType.OperaBrowser:
return ["fa-globe", this.i18nService.t("webVault") + " - Opera"];
case DeviceType.SafariBrowser:
return ["fa-globe", this.i18nService.t("webVault") + " - Safari"];
case DeviceType.VivaldiBrowser:
return ["fa-globe", this.i18nService.t("webVault") + " - Vivaldi"];
case DeviceType.EdgeBrowser:
return ["fa-globe", this.i18nService.t("webVault") + " - Edge"];
case DeviceType.IEBrowser:
return ["fa-globe", this.i18nService.t("webVault") + " - IE"];
case DeviceType.UnknownBrowser:
return ["fa-globe", this.i18nService.t("webVault") + " - " + this.i18nService.t("unknown")];
default:
return ["fa-globe", this.i18nService.t("unknown")];
}
}
private formatGroupId(ev: EventResponse) {
const shortId = this.getShortId(ev.groupId);
const a = this.makeAnchor(shortId);
a.setAttribute('href', '#/organizations/' + ev.organizationId + '/manage/groups?search=' + shortId);
return a.outerHTML;
private formatCipherId(ev: EventResponse, options: EventOptions) {
const shortId = this.getShortId(ev.cipherId);
if (ev.organizationId == null || !options.cipherInfo) {
return "<code>" + shortId + "</code>";
}
const a = this.makeAnchor(shortId);
a.setAttribute(
"href",
"#/organizations/" +
ev.organizationId +
"/vault?search=" +
shortId +
"&viewEvents=" +
ev.cipherId
);
return a.outerHTML;
}
private formatCollectionId(ev: EventResponse) {
const shortId = this.getShortId(ev.collectionId);
const a = this.makeAnchor(shortId);
a.setAttribute('href', '#/organizations/' + ev.organizationId + '/manage/collections?search=' + shortId);
return a.outerHTML;
}
private formatGroupId(ev: EventResponse) {
const shortId = this.getShortId(ev.groupId);
const a = this.makeAnchor(shortId);
a.setAttribute(
"href",
"#/organizations/" + ev.organizationId + "/manage/groups?search=" + shortId
);
return a.outerHTML;
}
private formatOrgUserId(ev: EventResponse) {
const shortId = this.getShortId(ev.organizationUserId);
const a = this.makeAnchor(shortId);
a.setAttribute('href', '#/organizations/' + ev.organizationId + '/manage/people?search=' + shortId +
'&viewEvents=' + ev.organizationUserId);
return a.outerHTML;
}
private formatCollectionId(ev: EventResponse) {
const shortId = this.getShortId(ev.collectionId);
const a = this.makeAnchor(shortId);
a.setAttribute(
"href",
"#/organizations/" + ev.organizationId + "/manage/collections?search=" + shortId
);
return a.outerHTML;
}
private formatProviderUserId(ev: EventResponse) {
const shortId = this.getShortId(ev.providerUserId);
const a = this.makeAnchor(shortId);
a.setAttribute('href', '#/providers/' + ev.providerId + '/manage/people?search=' + shortId +
'&viewEvents=' + ev.providerUserId);
return a.outerHTML;
}
private formatOrgUserId(ev: EventResponse) {
const shortId = this.getShortId(ev.organizationUserId);
const a = this.makeAnchor(shortId);
a.setAttribute(
"href",
"#/organizations/" +
ev.organizationId +
"/manage/people?search=" +
shortId +
"&viewEvents=" +
ev.organizationUserId
);
return a.outerHTML;
}
private formatProviderOrganizationId(ev: EventResponse) {
const shortId = this.getShortId(ev.providerOrganizationId);
const a = this.makeAnchor(shortId);
a.setAttribute('href', '#/providers/' + ev.providerId + '/clients?search=' + shortId);
return a.outerHTML;
}
private formatProviderUserId(ev: EventResponse) {
const shortId = this.getShortId(ev.providerUserId);
const a = this.makeAnchor(shortId);
a.setAttribute(
"href",
"#/providers/" +
ev.providerId +
"/manage/people?search=" +
shortId +
"&viewEvents=" +
ev.providerUserId
);
return a.outerHTML;
}
private formatPolicyId(ev: EventResponse) {
const shortId = this.getShortId(ev.policyId);
const a = this.makeAnchor(shortId);
a.setAttribute('href', '#/organizations/' + ev.organizationId + '/manage/policies?policyId=' + ev.policyId);
return a.outerHTML;
}
private formatProviderOrganizationId(ev: EventResponse) {
const shortId = this.getShortId(ev.providerOrganizationId);
const a = this.makeAnchor(shortId);
a.setAttribute("href", "#/providers/" + ev.providerId + "/clients?search=" + shortId);
return a.outerHTML;
}
private makeAnchor(shortId: string) {
const a = document.createElement('a');
a.title = this.i18nService.t('view');
a.innerHTML = '<code>' + shortId + '</code>';
return a;
}
private formatPolicyId(ev: EventResponse) {
const shortId = this.getShortId(ev.policyId);
const a = this.makeAnchor(shortId);
a.setAttribute(
"href",
"#/organizations/" + ev.organizationId + "/manage/policies?policyId=" + ev.policyId
);
return a.outerHTML;
}
private getShortId(id: string) {
return id?.substring(0, 8);
}
private makeAnchor(shortId: string) {
const a = document.createElement("a");
a.title = this.i18nService.t("view");
a.innerHTML = "<code>" + shortId + "</code>";
return a;
}
private toDateTimeLocalString(date: Date) {
return date.getFullYear() +
'-' + this.pad(date.getMonth() + 1) +
'-' + this.pad(date.getDate()) +
'T' + this.pad(date.getHours()) +
':' + this.pad(date.getMinutes());
}
private getShortId(id: string) {
return id?.substring(0, 8);
}
private pad(num: number) {
const norm = Math.floor(Math.abs(num));
return (norm < 10 ? '0' : '') + norm;
}
private toDateTimeLocalString(date: Date) {
return (
date.getFullYear() +
"-" +
this.pad(date.getMonth() + 1) +
"-" +
this.pad(date.getDate()) +
"T" +
this.pad(date.getHours()) +
":" +
this.pad(date.getMinutes())
);
}
private pad(num: number) {
const norm = Math.floor(Math.abs(num));
return (norm < 10 ? "0" : "") + norm;
}
}
export class EventInfo {
message: string;
humanReadableMessage: string;
appIcon: string;
appName: string;
message: string;
humanReadableMessage: string;
appIcon: string;
appName: string;
}
export class EventOptions {
cipherInfo = true;
cipherInfo = true;
}

View File

@@ -1,61 +1,60 @@
import {
ApplicationRef,
ComponentFactoryResolver,
Injectable,
Injector,
} from '@angular/core';
import * as jq from 'jquery';
import { first } from 'rxjs/operators';
import { ApplicationRef, ComponentFactoryResolver, Injectable, Injector } from "@angular/core";
import * as jq from "jquery";
import { first } from "rxjs/operators";
import { MessagingService } from 'jslib-common/abstractions/messaging.service';
import { MessagingService } from "jslib-common/abstractions/messaging.service";
import { ModalRef } from 'jslib-angular/components/modal/modal.ref';
import { ModalService as BaseModalService } from 'jslib-angular/services/modal.service';
import { ModalRef } from "jslib-angular/components/modal/modal.ref";
import { ModalService as BaseModalService } from "jslib-angular/services/modal.service";
import { Utils } from 'jslib-common/misc/utils';
import { Utils } from "jslib-common/misc/utils";
@Injectable()
export class ModalService extends BaseModalService {
el: any = null;
modalOpen: boolean = false;
el: any = null;
modalOpen: boolean = false;
constructor(componentFactoryResolver: ComponentFactoryResolver, applicationRef: ApplicationRef,
injector: Injector, private messagingService: MessagingService) {
super(componentFactoryResolver, applicationRef, injector);
}
constructor(
componentFactoryResolver: ComponentFactoryResolver,
applicationRef: ApplicationRef,
injector: Injector,
private messagingService: MessagingService
) {
super(componentFactoryResolver, applicationRef, injector);
}
protected setupHandlers(modalRef: ModalRef) {
modalRef.onCreated.pipe(first()).subscribe(() => {
const modals = Array.from(document.querySelectorAll('.modal'));
if (modals.length > 0) {
this.el = jq(modals[0]);
this.el.modal('show');
protected setupHandlers(modalRef: ModalRef) {
modalRef.onCreated.pipe(first()).subscribe(() => {
const modals = Array.from(document.querySelectorAll(".modal"));
if (modals.length > 0) {
this.el = jq(modals[0]);
this.el.modal("show");
this.el.on('show.bs.modal', () => {
modalRef.show();
this.messagingService.send('modalShow');
});
this.el.on('shown.bs.modal', () => {
modalRef.shown();
this.messagingService.send('modalShown');
if (!Utils.isMobileBrowser) {
this.el.find('*[appAutoFocus]').focus();
}
});
this.el.on('hide.bs.modal', () => {
this.messagingService.send('modalClose');
});
this.el.on('hidden.bs.modal', () => {
modalRef.closed();
this.messagingService.send('modalClosed');
});
}
this.el.on("show.bs.modal", () => {
modalRef.show();
this.messagingService.send("modalShow");
});
modalRef.onClose.pipe(first()).subscribe(() => {
if (this.el != null) {
this.el.modal('hide');
}
this.el.on("shown.bs.modal", () => {
modalRef.shown();
this.messagingService.send("modalShown");
if (!Utils.isMobileBrowser) {
this.el.find("*[appAutoFocus]").focus();
}
});
}
this.el.on("hide.bs.modal", () => {
this.messagingService.send("modalClose");
});
this.el.on("hidden.bs.modal", () => {
modalRef.closed();
this.messagingService.send("modalClosed");
});
}
});
modalRef.onClose.pipe(first()).subscribe(() => {
if (this.el != null) {
this.el.modal("hide");
}
});
}
}

View File

@@ -1,35 +1,35 @@
import { Injectable } from '@angular/core';
import {
ActivatedRouteSnapshot,
CanActivate,
Router,
} from '@angular/router';
import { Injectable } from "@angular/core";
import { ActivatedRouteSnapshot, CanActivate, Router } from "@angular/router";
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { OrganizationService } from 'jslib-common/abstractions/organization.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { I18nService } from "jslib-common/abstractions/i18n.service";
import { OrganizationService } from "jslib-common/abstractions/organization.service";
import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service";
@Injectable()
export class OrganizationGuardService implements CanActivate {
constructor(
private router: Router,
private platformUtilsService: PlatformUtilsService,
private i18nService: I18nService,
private organizationService: OrganizationService,
) { }
constructor(
private router: Router,
private platformUtilsService: PlatformUtilsService,
private i18nService: I18nService,
private organizationService: OrganizationService
) {}
async canActivate(route: ActivatedRouteSnapshot) {
const org = await this.organizationService.get(route.params.organizationId);
if (org == null) {
this.router.navigate(['/']);
return false;
}
if (!org.isOwner && !org.enabled) {
this.platformUtilsService.showToast('error', null, this.i18nService.t('organizationIsDisabled'));
this.router.navigate(['/']);
return false;
}
return true;
async canActivate(route: ActivatedRouteSnapshot) {
const org = await this.organizationService.get(route.params.organizationId);
if (org == null) {
this.router.navigate(["/"]);
return false;
}
if (!org.isOwner && !org.enabled) {
this.platformUtilsService.showToast(
"error",
null,
this.i18nService.t("organizationIsDisabled")
);
this.router.navigate(["/"]);
return false;
}
return true;
}
}

View File

@@ -1,42 +1,41 @@
import { Injectable } from '@angular/core';
import {
ActivatedRouteSnapshot,
CanActivate,
Router,
} from '@angular/router';
import { Injectable } from "@angular/core";
import { ActivatedRouteSnapshot, CanActivate, Router } from "@angular/router";
import { OrganizationService } from 'jslib-common/abstractions/organization.service';
import { OrganizationService } from "jslib-common/abstractions/organization.service";
import { Permissions } from 'jslib-common/enums/permissions';
import { Permissions } from "jslib-common/enums/permissions";
@Injectable()
export class OrganizationTypeGuardService implements CanActivate {
constructor(private organizationService: OrganizationService, private router: Router) { }
constructor(private organizationService: OrganizationService, private router: Router) {}
async canActivate(route: ActivatedRouteSnapshot) {
const org = await this.organizationService.get(route.params.organizationId);
const permissions = route.data == null ? null : route.data.permissions as Permissions[];
async canActivate(route: ActivatedRouteSnapshot) {
const org = await this.organizationService.get(route.params.organizationId);
const permissions = route.data == null ? null : (route.data.permissions as Permissions[]);
if (
(permissions.indexOf(Permissions.AccessEventLogs) !== -1 && org.canAccessEventLogs) ||
(permissions.indexOf(Permissions.AccessImportExport) !== -1 && org.canAccessImportExport) ||
(permissions.indexOf(Permissions.AccessReports) !== -1 && org.canAccessReports) ||
(permissions.indexOf(Permissions.CreateNewCollections) !== -1 && org.canCreateNewCollections) ||
(permissions.indexOf(Permissions.EditAnyCollection) !== -1 && org.canEditAnyCollection) ||
(permissions.indexOf(Permissions.DeleteAnyCollection) !== -1 && org.canDeleteAnyCollection) ||
(permissions.indexOf(Permissions.EditAssignedCollections) !== -1 && org.canEditAssignedCollections) ||
(permissions.indexOf(Permissions.DeleteAssignedCollections) !== -1 && org.canDeleteAssignedCollections) ||
(permissions.indexOf(Permissions.ManageGroups) !== -1 && org.canManageGroups) ||
(permissions.indexOf(Permissions.ManageOrganization) !== -1 && org.isOwner) ||
(permissions.indexOf(Permissions.ManagePolicies) !== -1 && org.canManagePolicies) ||
(permissions.indexOf(Permissions.ManageUsers) !== -1 && org.canManageUsers) ||
(permissions.indexOf(Permissions.ManageUsersPassword) !== -1 && org.canManageUsersPassword) ||
(permissions.indexOf(Permissions.ManageSso) !== -1 && org.canManageSso)
) {
return true;
}
this.router.navigate(['/organizations', org.id]);
return false;
if (
(permissions.indexOf(Permissions.AccessEventLogs) !== -1 && org.canAccessEventLogs) ||
(permissions.indexOf(Permissions.AccessImportExport) !== -1 && org.canAccessImportExport) ||
(permissions.indexOf(Permissions.AccessReports) !== -1 && org.canAccessReports) ||
(permissions.indexOf(Permissions.CreateNewCollections) !== -1 &&
org.canCreateNewCollections) ||
(permissions.indexOf(Permissions.EditAnyCollection) !== -1 && org.canEditAnyCollection) ||
(permissions.indexOf(Permissions.DeleteAnyCollection) !== -1 && org.canDeleteAnyCollection) ||
(permissions.indexOf(Permissions.EditAssignedCollections) !== -1 &&
org.canEditAssignedCollections) ||
(permissions.indexOf(Permissions.DeleteAssignedCollections) !== -1 &&
org.canDeleteAssignedCollections) ||
(permissions.indexOf(Permissions.ManageGroups) !== -1 && org.canManageGroups) ||
(permissions.indexOf(Permissions.ManageOrganization) !== -1 && org.isOwner) ||
(permissions.indexOf(Permissions.ManagePolicies) !== -1 && org.canManagePolicies) ||
(permissions.indexOf(Permissions.ManageUsers) !== -1 && org.canManageUsers) ||
(permissions.indexOf(Permissions.ManageUsersPassword) !== -1 && org.canManageUsersPassword) ||
(permissions.indexOf(Permissions.ManageSso) !== -1 && org.canManageSso)
) {
return true;
}
this.router.navigate(["/organizations", org.id]);
return false;
}
}

View File

@@ -1,13 +1,13 @@
import { BasePolicy } from '../organizations/policies/base-policy.component';
import { BasePolicy } from "../organizations/policies/base-policy.component";
export class PolicyListService {
private policies: BasePolicy[] = [];
private policies: BasePolicy[] = [];
addPolicies(policies: BasePolicy[]) {
this.policies.push(...policies);
}
addPolicies(policies: BasePolicy[]) {
this.policies.push(...policies);
}
getPolicies(): BasePolicy[] {
return this.policies;
}
getPolicies(): BasePolicy[] {
return this.policies;
}
}

View File

@@ -1,62 +1,62 @@
import { Injectable } from '@angular/core';
import { Title } from '@angular/platform-browser';
import {
ActivatedRoute,
NavigationEnd,
Router,
} from '@angular/router';
import { Injectable } from "@angular/core";
import { Title } from "@angular/platform-browser";
import { ActivatedRoute, NavigationEnd, Router } from "@angular/router";
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { I18nService } from "jslib-common/abstractions/i18n.service";
@Injectable()
export class RouterService {
private previousUrl: string = undefined;
private currentUrl: string = undefined;
private previousUrl: string = undefined;
private currentUrl: string = undefined;
constructor(private router: Router, private activatedRoute: ActivatedRoute,
private titleService: Title, i18nService: I18nService) {
this.currentUrl = this.router.url;
router.events.subscribe(event => {
if (event instanceof NavigationEnd) {
this.previousUrl = this.currentUrl;
this.currentUrl = event.url;
constructor(
private router: Router,
private activatedRoute: ActivatedRoute,
private titleService: Title,
i18nService: I18nService
) {
this.currentUrl = this.router.url;
router.events.subscribe((event) => {
if (event instanceof NavigationEnd) {
this.previousUrl = this.currentUrl;
this.currentUrl = event.url;
let title = i18nService.t('pageTitle', 'Bitwarden');
let titleId: string = null;
let rawTitle: string = null;
let child = this.activatedRoute.firstChild;
while (child != null) {
if (child.firstChild != null) {
child = child.firstChild;
} else if (child.snapshot.data != null && child.snapshot.data.title != null) {
rawTitle = child.snapshot.data.title;
break;
} else if (child.snapshot.data != null && child.snapshot.data.titleId != null) {
titleId = child.snapshot.data.titleId;
break;
} else {
titleId = null;
rawTitle = null;
break;
}
}
let title = i18nService.t("pageTitle", "Bitwarden");
let titleId: string = null;
let rawTitle: string = null;
let child = this.activatedRoute.firstChild;
while (child != null) {
if (child.firstChild != null) {
child = child.firstChild;
} else if (child.snapshot.data != null && child.snapshot.data.title != null) {
rawTitle = child.snapshot.data.title;
break;
} else if (child.snapshot.data != null && child.snapshot.data.titleId != null) {
titleId = child.snapshot.data.titleId;
break;
} else {
titleId = null;
rawTitle = null;
break;
}
}
if (titleId != null || rawTitle != null) {
const newTitle = rawTitle != null ? rawTitle : i18nService.t(titleId);
if (newTitle != null && newTitle !== '') {
title = (newTitle + ' | ' + title);
}
}
this.titleService.setTitle(title);
}
});
}
if (titleId != null || rawTitle != null) {
const newTitle = rawTitle != null ? rawTitle : i18nService.t(titleId);
if (newTitle != null && newTitle !== "") {
title = newTitle + " | " + title;
}
}
this.titleService.setTitle(title);
}
});
}
getPreviousUrl() {
return this.previousUrl;
}
getPreviousUrl() {
return this.previousUrl;
}
setPreviousUrl(url: string) {
this.previousUrl = url;
}
setPreviousUrl(url: string) {
this.previousUrl = url;
}
}

View File

@@ -1,166 +1,172 @@
import { APP_INITIALIZER, Injector, NgModule } from "@angular/core";
import { ToastrModule } from "ngx-toastr";
import { BroadcasterMessagingService } from "../../services/broadcasterMessaging.service";
import { HtmlStorageService } from "../../services/htmlStorage.service";
import { I18nService } from "../../services/i18n.service";
import { MemoryStorageService } from "../../services/memoryStorage.service";
import { WebPlatformUtilsService } from "../../services/webPlatformUtils.service";
import { EventService } from "./event.service";
import { ModalService } from "./modal.service";
import { OrganizationGuardService } from "./organization-guard.service";
import { OrganizationTypeGuardService } from "./organization-type-guard.service";
import { PolicyListService } from "./policy-list.service";
import { RouterService } from "./router.service";
import { JslibServicesModule } from "jslib-angular/services/jslib-services.module";
import { ModalService as ModalServiceAbstraction } from "jslib-angular/services/modal.service";
import { AuthService } from "jslib-common/services/auth.service";
import { ContainerService } from "jslib-common/services/container.service";
import { CryptoService } from "jslib-common/services/crypto.service";
import { EventService as EventLoggingService } from "jslib-common/services/event.service";
import { ImportService } from "jslib-common/services/import.service";
import { VaultTimeoutService } from "jslib-common/services/vaultTimeout.service";
import { ApiService as ApiServiceAbstraction } from "jslib-common/abstractions/api.service";
import { AuthService as AuthServiceAbstraction } from "jslib-common/abstractions/auth.service";
import { CipherService as CipherServiceAbstraction } from "jslib-common/abstractions/cipher.service";
import { CollectionService as CollectionServiceAbstraction } from "jslib-common/abstractions/collection.service";
import { CryptoService as CryptoServiceAbstraction } from "jslib-common/abstractions/crypto.service";
import { CryptoFunctionService as CryptoFunctionServiceAbstraction } from "jslib-common/abstractions/cryptoFunction.service";
import {
APP_INITIALIZER,
Injector,
NgModule,
} from '@angular/core';
import { ToastrModule } from 'ngx-toastr';
EnvironmentService as EnvironmentServiceAbstraction,
Urls,
} from "jslib-common/abstractions/environment.service";
import { EventService as EventLoggingServiceAbstraction } from "jslib-common/abstractions/event.service";
import { FolderService as FolderServiceAbstraction } from "jslib-common/abstractions/folder.service";
import { I18nService as I18nServiceAbstraction } from "jslib-common/abstractions/i18n.service";
import { ImportService as ImportServiceAbstraction } from "jslib-common/abstractions/import.service";
import { LogService } from "jslib-common/abstractions/log.service";
import { MessagingService as MessagingServiceAbstraction } from "jslib-common/abstractions/messaging.service";
import { NotificationsService as NotificationsServiceAbstraction } from "jslib-common/abstractions/notifications.service";
import { PlatformUtilsService as PlatformUtilsServiceAbstraction } from "jslib-common/abstractions/platformUtils.service";
import { StateService as StateServiceAbstraction } from "jslib-common/abstractions/state.service";
import { StorageService as StorageServiceAbstraction } from "jslib-common/abstractions/storage.service";
import { VaultTimeoutService as VaultTimeoutServiceAbstraction } from "jslib-common/abstractions/vaultTimeout.service";
import { BroadcasterMessagingService } from '../../services/broadcasterMessaging.service';
import { HtmlStorageService } from '../../services/htmlStorage.service';
import { I18nService } from '../../services/i18n.service';
import { MemoryStorageService } from '../../services/memoryStorage.service';
import { WebPlatformUtilsService } from '../../services/webPlatformUtils.service';
import { ThemeType } from "jslib-common/enums/themeType";
import { EventService } from './event.service';
import { ModalService } from './modal.service';
import { OrganizationGuardService } from './organization-guard.service';
import { OrganizationTypeGuardService } from './organization-type-guard.service';
import { PolicyListService } from './policy-list.service';
import { RouterService } from './router.service';
export function initFactory(
window: Window,
storageService: StorageServiceAbstraction,
environmentService: EnvironmentServiceAbstraction,
notificationsService: NotificationsServiceAbstraction,
vaultTimeoutService: VaultTimeoutService,
i18nService: I18nService,
eventLoggingService: EventLoggingService,
authService: AuthService,
stateService: StateServiceAbstraction,
platformUtilsService: PlatformUtilsServiceAbstraction,
cryptoService: CryptoServiceAbstraction
): Function {
return async () => {
await (storageService as HtmlStorageService).init();
await stateService.init();
import { JslibServicesModule } from 'jslib-angular/services/jslib-services.module';
import { ModalService as ModalServiceAbstraction } from 'jslib-angular/services/modal.service';
const urls = process.env.URLS as Urls;
urls.base ??= window.location.origin;
environmentService.setUrls(urls, false);
import { AuthService } from 'jslib-common/services/auth.service';
import { ContainerService } from 'jslib-common/services/container.service';
import { CryptoService } from 'jslib-common/services/crypto.service';
import { EventService as EventLoggingService } from 'jslib-common/services/event.service';
import { ImportService } from 'jslib-common/services/import.service';
import { VaultTimeoutService } from 'jslib-common/services/vaultTimeout.service';
setTimeout(() => notificationsService.init(), 3000);
import { ApiService as ApiServiceAbstraction } from 'jslib-common/abstractions/api.service';
import { AuthService as AuthServiceAbstraction } from 'jslib-common/abstractions/auth.service';
import { CipherService as CipherServiceAbstraction } from 'jslib-common/abstractions/cipher.service';
import { CollectionService as CollectionServiceAbstraction } from 'jslib-common/abstractions/collection.service';
import { CryptoService as CryptoServiceAbstraction } from 'jslib-common/abstractions/crypto.service';
import { CryptoFunctionService as CryptoFunctionServiceAbstraction } from 'jslib-common/abstractions/cryptoFunction.service';
import { EnvironmentService as EnvironmentServiceAbstraction, Urls } from 'jslib-common/abstractions/environment.service';
import { EventService as EventLoggingServiceAbstraction } from 'jslib-common/abstractions/event.service';
import { FolderService as FolderServiceAbstraction } from 'jslib-common/abstractions/folder.service';
import { I18nService as I18nServiceAbstraction } from 'jslib-common/abstractions/i18n.service';
import { ImportService as ImportServiceAbstraction } from 'jslib-common/abstractions/import.service';
import { LogService } from 'jslib-common/abstractions/log.service';
import { MessagingService as MessagingServiceAbstraction } from 'jslib-common/abstractions/messaging.service';
import { NotificationsService as NotificationsServiceAbstraction } from 'jslib-common/abstractions/notifications.service';
import { PlatformUtilsService as PlatformUtilsServiceAbstraction } from 'jslib-common/abstractions/platformUtils.service';
import { StateService as StateServiceAbstraction } from 'jslib-common/abstractions/state.service';
import { StorageService as StorageServiceAbstraction } from 'jslib-common/abstractions/storage.service';
import { VaultTimeoutService as VaultTimeoutServiceAbstraction } from 'jslib-common/abstractions/vaultTimeout.service';
vaultTimeoutService.init(true);
const locale = await stateService.getLocale();
await i18nService.init(locale);
eventLoggingService.init(true);
authService.init();
const htmlEl = window.document.documentElement;
htmlEl.classList.add("locale_" + i18nService.translationLocale);
import { ThemeType } from 'jslib-common/enums/themeType';
// Initial theme is set in index.html which must be updated if there are any changes to theming logic
platformUtilsService.onDefaultSystemThemeChange(async (sysTheme) => {
const bwTheme = await stateService.getTheme();
if (bwTheme === ThemeType.System) {
htmlEl.classList.remove("theme_" + ThemeType.Light, "theme_" + ThemeType.Dark);
htmlEl.classList.add("theme_" + sysTheme);
}
});
export function initFactory(window: Window, storageService: StorageServiceAbstraction,
environmentService: EnvironmentServiceAbstraction, notificationsService: NotificationsServiceAbstraction,
vaultTimeoutService: VaultTimeoutService, i18nService: I18nService, eventLoggingService: EventLoggingService,
authService: AuthService, stateService: StateServiceAbstraction,
platformUtilsService: PlatformUtilsServiceAbstraction, cryptoService: CryptoServiceAbstraction): Function {
return async () => {
await (storageService as HtmlStorageService).init();
await stateService.init();
const urls = process.env.URLS as Urls;
urls.base ??= window.location.origin;
environmentService.setUrls(urls, false);
setTimeout(() => notificationsService.init(), 3000);
vaultTimeoutService.init(true);
const locale = await stateService.getLocale();
await i18nService.init(locale);
eventLoggingService.init(true);
authService.init();
const htmlEl = window.document.documentElement;
htmlEl.classList.add('locale_' + i18nService.translationLocale);
// Initial theme is set in index.html which must be updated if there are any changes to theming logic
platformUtilsService.onDefaultSystemThemeChange(async sysTheme => {
const bwTheme = await stateService.getTheme();
if (bwTheme === ThemeType.System) {
htmlEl.classList.remove('theme_' + ThemeType.Light, 'theme_' + ThemeType.Dark);
htmlEl.classList.add('theme_' + sysTheme);
}
});
const containerService = new ContainerService(cryptoService);
containerService.attachToWindow(window);
};
const containerService = new ContainerService(cryptoService);
containerService.attachToWindow(window);
};
}
@NgModule({
imports: [
ToastrModule,
JslibServicesModule,
],
declarations: [],
providers: [
{
provide: APP_INITIALIZER,
useFactory: initFactory,
deps: [
'WINDOW',
StorageServiceAbstraction,
EnvironmentServiceAbstraction,
NotificationsServiceAbstraction,
VaultTimeoutServiceAbstraction,
I18nServiceAbstraction,
EventLoggingServiceAbstraction,
AuthServiceAbstraction,
StateServiceAbstraction,
PlatformUtilsServiceAbstraction,
CryptoServiceAbstraction,
],
multi: true,
},
OrganizationGuardService,
OrganizationTypeGuardService,
RouterService,
EventService,
PolicyListService,
{
provide: I18nServiceAbstraction,
useFactory: (window: Window) => new I18nService(window.navigator.language, 'locales'),
deps: [ 'WINDOW' ],
},
{ provide: StorageServiceAbstraction, useClass: HtmlStorageService },
{ provide: 'SECURE_STORAGE', useClass: MemoryStorageService },
{
provide: PlatformUtilsServiceAbstraction,
useFactory: (i18nService: I18nServiceAbstraction, messagingService: MessagingServiceAbstraction,
logService: LogService, stateService: StateServiceAbstraction) => new WebPlatformUtilsService(i18nService,
messagingService, logService, stateService),
deps: [
I18nServiceAbstraction,
MessagingServiceAbstraction,
LogService,
StateServiceAbstraction,
],
},
{ provide: MessagingServiceAbstraction, useClass: BroadcasterMessagingService },
{ provide: ModalServiceAbstraction, useClass: ModalService },
{
provide: ImportServiceAbstraction,
useClass: ImportService,
deps: [
CipherServiceAbstraction,
FolderServiceAbstraction,
ApiServiceAbstraction,
I18nServiceAbstraction,
CollectionServiceAbstraction,
PlatformUtilsServiceAbstraction,
CryptoServiceAbstraction,
],
},
{
provide: CryptoServiceAbstraction,
useClass: CryptoService,
deps: [
CryptoFunctionServiceAbstraction,
PlatformUtilsServiceAbstraction,
LogService,
StateServiceAbstraction,
],
},
],
imports: [ToastrModule, JslibServicesModule],
declarations: [],
providers: [
{
provide: APP_INITIALIZER,
useFactory: initFactory,
deps: [
"WINDOW",
StorageServiceAbstraction,
EnvironmentServiceAbstraction,
NotificationsServiceAbstraction,
VaultTimeoutServiceAbstraction,
I18nServiceAbstraction,
EventLoggingServiceAbstraction,
AuthServiceAbstraction,
StateServiceAbstraction,
PlatformUtilsServiceAbstraction,
CryptoServiceAbstraction,
],
multi: true,
},
OrganizationGuardService,
OrganizationTypeGuardService,
RouterService,
EventService,
PolicyListService,
{
provide: I18nServiceAbstraction,
useFactory: (window: Window) => new I18nService(window.navigator.language, "locales"),
deps: ["WINDOW"],
},
{ provide: StorageServiceAbstraction, useClass: HtmlStorageService },
{ provide: "SECURE_STORAGE", useClass: MemoryStorageService },
{
provide: PlatformUtilsServiceAbstraction,
useFactory: (
i18nService: I18nServiceAbstraction,
messagingService: MessagingServiceAbstraction,
logService: LogService,
stateService: StateServiceAbstraction
) => new WebPlatformUtilsService(i18nService, messagingService, logService, stateService),
deps: [
I18nServiceAbstraction,
MessagingServiceAbstraction,
LogService,
StateServiceAbstraction,
],
},
{ provide: MessagingServiceAbstraction, useClass: BroadcasterMessagingService },
{ provide: ModalServiceAbstraction, useClass: ModalService },
{
provide: ImportServiceAbstraction,
useClass: ImportService,
deps: [
CipherServiceAbstraction,
FolderServiceAbstraction,
ApiServiceAbstraction,
I18nServiceAbstraction,
CollectionServiceAbstraction,
PlatformUtilsServiceAbstraction,
CryptoServiceAbstraction,
],
},
{
provide: CryptoServiceAbstraction,
useClass: CryptoService,
deps: [
CryptoFunctionServiceAbstraction,
PlatformUtilsServiceAbstraction,
LogService,
StateServiceAbstraction,
],
},
],
})
export class ServicesModule {
}
export class ServicesModule {}