web: Detangling some circular dependencies in Admin and User (#6852)

* Web: Detangling some circular dependencies in Admin and User

Admin, User, and Flow should not dependend upon each other, at least
not in a circular way.  If Admin and User depend on Flow, that's
fine, but Flow should not correspondingly depend upon elements of
either; if they have something in common, let's put them in
`@goauthentik/common` or find some other smart place to store them.

This commit refactors the intentToLabel and actionToLabel functions
into `@goauthentik/common/labels` and converts them to static tables
for maintenance purposes.

* web: "Consistency is the hobgoblin of small minds" - Ralph Waldo Emerson

* web: I found these confusing to look at, so I added comments.

* web: remove admin-to-user component reference(s) (#6856)

There was only one: AppIcon.  This has been moved to `components`.

Touching the LibraryApplications page triggered a cyclomatic
complexity check.  Extracting the expansion block and streamlining
the class and style declarations with lit directives helped.
This commit is contained in:
Ken Sternberg
2023-09-13 10:16:24 -07:00
committed by GitHub
parent 58aa7ec623
commit 28702b3a25
16 changed files with 124 additions and 145 deletions

58
web/src/common/labels.ts Normal file
View File

@ -0,0 +1,58 @@
import { msg } from "@lit/localize";
import { EventActions, IntentEnum, SeverityEnum } from "@goauthentik/api";
/* 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 eventActionToLabel = new Map<EventActions | undefined, string>([
[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 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");