Files
authentik/web/src/common/labels.ts
Ken Sternberg a9886b047e web: further refinements to the sidebar
This commit restores the onHashChange functionality, using an
on-demand reverse map (there really aren't that many objects in the
nav tree) to make sure all of the parent entities are also listed
in the "expanded" listing to make sure the target object is still
visible.  Along the way, several type lever errors were corrected.
Two major pieces of functionality were extracted from the Sidebar
function as they're mostly consumers/filters of the information
provided, and don't need to be in the Sidebar itself.
2023-11-17 14:47:47 -08:00

82 lines
3.6 KiB
TypeScript

import { msg } from "@lit/localize";
import { Device, EventActions, IntentEnum, SeverityEnum, UserTypeEnum } from "@goauthentik/api";
type Pair<T> = [T, string];
/* Various tables in the API for which we need to supply labels */
export const intentEnumToLabel = new Map<IntentEnum, string>([
[IntentEnum.Api, msg("API Access")],
[IntentEnum.AppPassword, msg("App password")],
[IntentEnum.Recovery, msg("Recovery")],
[IntentEnum.Verification, msg("Verification")],
[IntentEnum.UnknownDefaultOpenApi, msg("Unknown intent")],
]);
export const intentToLabel = (intent: IntentEnum) => intentEnumToLabel.get(intent);
export const eventActionLabels: Pair<EventActions>[] = [
[EventActions.Login, msg("Login")],
[EventActions.LoginFailed, msg("Failed login")],
[EventActions.Logout, msg("Logout")],
[EventActions.UserWrite, msg("User was written to")],
[EventActions.SuspiciousRequest, msg("Suspicious request")],
[EventActions.PasswordSet, msg("Password set")],
[EventActions.SecretView, msg("Secret was viewed")],
[EventActions.SecretRotate, msg("Secret was rotated")],
[EventActions.InvitationUsed, msg("Invitation used")],
[EventActions.AuthorizeApplication, msg("Application authorized")],
[EventActions.SourceLinked, msg("Source linked")],
[EventActions.ImpersonationStarted, msg("Impersonation started")],
[EventActions.ImpersonationEnded, msg("Impersonation ended")],
[EventActions.FlowExecution, msg("Flow execution")],
// These are different: look closely.
[EventActions.PolicyExecution, msg("Policy execution")],
[EventActions.PolicyException, msg("Policy exception")],
[EventActions.PropertyMappingException, msg("Property Mapping exception")],
// These are different: look closely.
[EventActions.SystemTaskExecution, msg("System task execution")],
[EventActions.SystemTaskException, msg("System task exception")],
[EventActions.SystemException, msg("General system exception")],
[EventActions.ConfigurationError, msg("Configuration error")],
[EventActions.ModelCreated, msg("Model created")],
[EventActions.ModelUpdated, msg("Model updated")],
[EventActions.ModelDeleted, msg("Model deleted")],
[EventActions.EmailSent, msg("Email sent")],
[EventActions.UpdateAvailable, msg("Update available")],
];
export const eventActionToLabel = new Map<EventActions | undefined, string>(eventActionLabels);
export const actionToLabel = (action?: EventActions): string =>
eventActionToLabel.get(action) ?? action ?? "";
export const severityEnumToLabel = new Map<SeverityEnum | null | undefined, string>([
[SeverityEnum.Alert, msg("Alert")],
[SeverityEnum.Notice, msg("Notice")],
[SeverityEnum.Warning, msg("Warning")],
]);
export const severityToLabel = (severity: SeverityEnum | null | undefined) =>
severityEnumToLabel.get(severity) ?? msg("Unknown severity");
// TODO: Add verbose_name field to now vendored OTP devices
export const deviceTypeToLabel = new Map<string, string>([
["authentik_stages_authenticator_static.StaticDevice", msg("Static tokens")],
["authentik_stages_authenticator_totp.TOTPDevice", msg("TOTP Device")],
]);
export const deviceTypeName = (device: Device) =>
deviceTypeToLabel.get(device.type) ?? device?.verboseName ?? "";
const _userTypeToLabel = new Map<UserTypeEnum | undefined, string>([
[UserTypeEnum.Internal, msg("Internal")],
[UserTypeEnum.External, msg("External")],
[UserTypeEnum.ServiceAccount, msg("Service account")],
[UserTypeEnum.InternalServiceAccount, msg("Service account (internal)")],
]);
export const userTypeToLabel = (type?: UserTypeEnum): string =>
_userTypeToLabel.get(type) ?? type ?? "";