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:
@ -1,7 +1,8 @@
|
||||
import "@goauthentik/admin/events/EventInfo";
|
||||
import { ActionToLabel, EventGeo } from "@goauthentik/admin/events/utils";
|
||||
import { EventGeo } from "@goauthentik/admin/events/utils";
|
||||
import { DEFAULT_CONFIG } from "@goauthentik/common/api/config";
|
||||
import { EventWithContext } from "@goauthentik/common/events";
|
||||
import { actionToLabel } from "@goauthentik/common/labels";
|
||||
import { truncate } from "@goauthentik/common/utils";
|
||||
import "@goauthentik/elements/Tabs";
|
||||
import "@goauthentik/elements/buttons/Dropdown";
|
||||
@ -68,7 +69,7 @@ export class RecentEventsCard extends Table<Event> {
|
||||
|
||||
row(item: EventWithContext): TemplateResult[] {
|
||||
return [
|
||||
html`<div><a href="${`#/events/log/${item.pk}`}">${ActionToLabel(item.action)}</a></div>
|
||||
html`<div><a href="${`#/events/log/${item.pk}`}">${actionToLabel(item.action)}</a></div>
|
||||
<small>${item.app}</small>`,
|
||||
item.user?.username
|
||||
? html`<div>
|
||||
|
||||
@ -3,6 +3,7 @@ import "@goauthentik/admin/applications/wizard/ApplicationWizard";
|
||||
import { PFSize } from "@goauthentik/app/elements/Spinner";
|
||||
import { DEFAULT_CONFIG } from "@goauthentik/common/api/config";
|
||||
import { uiConfig } from "@goauthentik/common/ui/config";
|
||||
import "@goauthentik/components/ak-app-icon";
|
||||
import MDApplication from "@goauthentik/docs/core/applications.md";
|
||||
import "@goauthentik/elements/Markdown";
|
||||
import "@goauthentik/elements/buttons/SpinnerButton";
|
||||
@ -12,7 +13,6 @@ import { getURLParam } from "@goauthentik/elements/router/RouteMatch";
|
||||
import { PaginatedResponse } from "@goauthentik/elements/table/Table";
|
||||
import { TableColumn } from "@goauthentik/elements/table/Table";
|
||||
import { TablePage } from "@goauthentik/elements/table/TablePage";
|
||||
import "@goauthentik/user/LibraryApplication/AppIcon";
|
||||
import "@patternfly/elements/pf-tooltip/pf-tooltip.js";
|
||||
|
||||
import { msg } from "@lit/localize";
|
||||
|
||||
@ -4,13 +4,13 @@ import "@goauthentik/admin/applications/ApplicationForm";
|
||||
import "@goauthentik/admin/policies/BoundPoliciesList";
|
||||
import { PFSize } from "@goauthentik/app/elements/Spinner";
|
||||
import { DEFAULT_CONFIG } from "@goauthentik/common/api/config";
|
||||
import "@goauthentik/components/ak-app-icon";
|
||||
import { AKElement } from "@goauthentik/elements/Base";
|
||||
import "@goauthentik/elements/EmptyState";
|
||||
import "@goauthentik/elements/PageHeader";
|
||||
import "@goauthentik/elements/Tabs";
|
||||
import "@goauthentik/elements/buttons/SpinnerButton";
|
||||
import "@goauthentik/elements/events/ObjectChangelog";
|
||||
import "@goauthentik/user/LibraryApplication/AppIcon";
|
||||
|
||||
import { msg } from "@lit/localize";
|
||||
import { CSSResult, TemplateResult, html } from "lit";
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import "@goauthentik/admin/events/EventInfo";
|
||||
import { ActionToLabel, EventGeo } from "@goauthentik/admin/events/utils";
|
||||
import { EventGeo } from "@goauthentik/admin/events/utils";
|
||||
import { DEFAULT_CONFIG } from "@goauthentik/common/api/config";
|
||||
import { EventWithContext } from "@goauthentik/common/events";
|
||||
import { actionToLabel } from "@goauthentik/common/labels";
|
||||
import { uiConfig } from "@goauthentik/common/ui/config";
|
||||
import { PaginatedResponse } from "@goauthentik/elements/table/Table";
|
||||
import { TableColumn } from "@goauthentik/elements/table/Table";
|
||||
@ -56,7 +57,7 @@ export class EventListPage extends TablePage<Event> {
|
||||
|
||||
row(item: EventWithContext): TemplateResult[] {
|
||||
return [
|
||||
html`<div>${ActionToLabel(item.action)}</div>
|
||||
html`<div>${actionToLabel(item.action)}</div>
|
||||
<small>${item.app}</small>`,
|
||||
item.user?.username
|
||||
? html`<div>
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import "@goauthentik/admin/events/EventInfo";
|
||||
import { ActionToLabel, EventGeo } from "@goauthentik/admin/events/utils";
|
||||
import { EventGeo } from "@goauthentik/admin/events/utils";
|
||||
import { DEFAULT_CONFIG } from "@goauthentik/common/api/config";
|
||||
import { EventWithContext } from "@goauthentik/common/events";
|
||||
import { actionToLabel } from "@goauthentik/common/labels";
|
||||
import { AKElement } from "@goauthentik/elements/Base";
|
||||
import "@goauthentik/elements/PageHeader";
|
||||
|
||||
@ -62,7 +63,7 @@ export class EventViewPage extends AKElement {
|
||||
</dt>
|
||||
<dd class="pf-c-description-list__description">
|
||||
<div class="pf-c-description-list__text">
|
||||
${ActionToLabel(this.event.action)}
|
||||
${actionToLabel(this.event.action)}
|
||||
</div>
|
||||
</dd>
|
||||
</div>
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { SeverityToLabel } from "@goauthentik/admin/events/utils";
|
||||
import { DEFAULT_CONFIG } from "@goauthentik/common/api/config";
|
||||
import { severityToLabel } from "@goauthentik/common/labels";
|
||||
import "@goauthentik/elements/forms/HorizontalFormElement";
|
||||
import { ModelForm } from "@goauthentik/elements/forms/ModelForm";
|
||||
import "@goauthentik/elements/forms/Radio";
|
||||
@ -125,16 +125,16 @@ export class RuleForm extends ModelForm<NotificationRule, string> {
|
||||
<ak-radio
|
||||
.options=${[
|
||||
{
|
||||
label: SeverityToLabel(SeverityEnum.Alert),
|
||||
label: severityToLabel(SeverityEnum.Alert),
|
||||
value: SeverityEnum.Alert,
|
||||
default: true,
|
||||
},
|
||||
{
|
||||
label: SeverityToLabel(SeverityEnum.Warning),
|
||||
label: severityToLabel(SeverityEnum.Warning),
|
||||
value: SeverityEnum.Warning,
|
||||
},
|
||||
{
|
||||
label: SeverityToLabel(SeverityEnum.Notice),
|
||||
label: severityToLabel(SeverityEnum.Notice),
|
||||
value: SeverityEnum.Notice,
|
||||
},
|
||||
]}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import "@goauthentik/admin/events/RuleForm";
|
||||
import { SeverityToLabel } from "@goauthentik/admin/events/utils";
|
||||
import "@goauthentik/admin/policies/BoundPoliciesList";
|
||||
import { DEFAULT_CONFIG } from "@goauthentik/common/api/config";
|
||||
import { severityToLabel } from "@goauthentik/common/labels";
|
||||
import { uiConfig } from "@goauthentik/common/ui/config";
|
||||
import "@goauthentik/elements/buttons/SpinnerButton";
|
||||
import "@goauthentik/elements/forms/DeleteBulkForm";
|
||||
@ -83,7 +83,7 @@ export class RuleListPage extends TablePage<NotificationRule> {
|
||||
row(item: NotificationRule): TemplateResult[] {
|
||||
return [
|
||||
html`${item.name}`,
|
||||
html`${SeverityToLabel(item.severity)}`,
|
||||
html`${severityToLabel(item.severity)}`,
|
||||
html`${item.groupObj
|
||||
? html`<a href="#/identity/groups/${item.groupObj.pk}">${item.groupObj.name}</a>`
|
||||
: msg("None (rule disabled)")}`,
|
||||
|
||||
@ -1,11 +1,8 @@
|
||||
import { EventWithContext } from "@goauthentik/common/events";
|
||||
import { KeyUnknown } from "@goauthentik/elements/forms/Form";
|
||||
|
||||
import { msg } from "@lit/localize";
|
||||
import { TemplateResult, html } from "lit";
|
||||
|
||||
import { EventActions, SeverityEnum } from "@goauthentik/api";
|
||||
|
||||
export function EventGeo(event: EventWithContext): TemplateResult {
|
||||
let geo: KeyUnknown | undefined = undefined;
|
||||
if (Object.hasOwn(event.context, "geo")) {
|
||||
@ -17,76 +14,3 @@ export function EventGeo(event: EventWithContext): TemplateResult {
|
||||
}
|
||||
return html``;
|
||||
}
|
||||
|
||||
export function ActionToLabel(action?: EventActions): string {
|
||||
if (!action) return "";
|
||||
switch (action) {
|
||||
case EventActions.Login:
|
||||
return msg("Login");
|
||||
case EventActions.LoginFailed:
|
||||
return msg("Failed login");
|
||||
case EventActions.Logout:
|
||||
return msg("Logout");
|
||||
case EventActions.UserWrite:
|
||||
return msg("User was written to");
|
||||
case EventActions.SuspiciousRequest:
|
||||
return msg("Suspicious request");
|
||||
case EventActions.PasswordSet:
|
||||
return msg("Password set");
|
||||
case EventActions.SecretView:
|
||||
return msg("Secret was viewed");
|
||||
case EventActions.SecretRotate:
|
||||
return msg("Secret was rotated");
|
||||
case EventActions.InvitationUsed:
|
||||
return msg("Invitation used");
|
||||
case EventActions.AuthorizeApplication:
|
||||
return msg("Application authorized");
|
||||
case EventActions.SourceLinked:
|
||||
return msg("Source linked");
|
||||
case EventActions.ImpersonationStarted:
|
||||
return msg("Impersonation started");
|
||||
case EventActions.ImpersonationEnded:
|
||||
return msg("Impersonation ended");
|
||||
case EventActions.FlowExecution:
|
||||
return msg("Flow execution");
|
||||
case EventActions.PolicyExecution:
|
||||
return msg("Policy execution");
|
||||
case EventActions.PolicyException:
|
||||
return msg("Policy exception");
|
||||
case EventActions.PropertyMappingException:
|
||||
return msg("Property Mapping exception");
|
||||
case EventActions.SystemTaskExecution:
|
||||
return msg("System task execution");
|
||||
case EventActions.SystemTaskException:
|
||||
return msg("System task exception");
|
||||
case EventActions.SystemException:
|
||||
return msg("General system exception");
|
||||
case EventActions.ConfigurationError:
|
||||
return msg("Configuration error");
|
||||
case EventActions.ModelCreated:
|
||||
return msg("Model created");
|
||||
case EventActions.ModelUpdated:
|
||||
return msg("Model updated");
|
||||
case EventActions.ModelDeleted:
|
||||
return msg("Model deleted");
|
||||
case EventActions.EmailSent:
|
||||
return msg("Email sent");
|
||||
case EventActions.UpdateAvailable:
|
||||
return msg("Update available");
|
||||
default:
|
||||
return action;
|
||||
}
|
||||
}
|
||||
|
||||
export function SeverityToLabel(severity: SeverityEnum | null | undefined): string {
|
||||
if (!severity) return msg("Unknown severity");
|
||||
switch (severity) {
|
||||
case SeverityEnum.Alert:
|
||||
return msg("Alert");
|
||||
case SeverityEnum.Notice:
|
||||
return msg("Notice");
|
||||
case SeverityEnum.Warning:
|
||||
return msg("Warning");
|
||||
}
|
||||
return msg("Unknown severity");
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import "@goauthentik/admin/tokens/TokenForm";
|
||||
import { DEFAULT_CONFIG } from "@goauthentik/common/api/config";
|
||||
import { intentToLabel } from "@goauthentik/common/labels";
|
||||
import { uiConfig } from "@goauthentik/common/ui/config";
|
||||
import { PFColor } from "@goauthentik/elements/Label";
|
||||
import "@goauthentik/elements/buttons/Dropdown";
|
||||
@ -17,21 +18,6 @@ import { customElement, property } from "lit/decorators.js";
|
||||
|
||||
import { CoreApi, IntentEnum, Token } from "@goauthentik/api";
|
||||
|
||||
export function IntentToLabel(intent: IntentEnum): string {
|
||||
switch (intent) {
|
||||
case IntentEnum.Api:
|
||||
return msg("API Access");
|
||||
case IntentEnum.AppPassword:
|
||||
return msg("App password");
|
||||
case IntentEnum.Recovery:
|
||||
return msg("Recovery");
|
||||
case IntentEnum.Verification:
|
||||
return msg("Verification");
|
||||
case IntentEnum.UnknownDefaultOpenApi:
|
||||
return msg("Unknown intent");
|
||||
}
|
||||
}
|
||||
|
||||
@customElement("ak-token-list")
|
||||
export class TokenListPage extends TablePage<Token> {
|
||||
searchEnabled(): boolean {
|
||||
@ -121,7 +107,7 @@ export class TokenListPage extends TablePage<Token> {
|
||||
${item.expiring ? msg("Yes") : msg("No")}
|
||||
</ak-label>`,
|
||||
html`${item.expiring ? item.expires?.toLocaleString() : msg("-")}`,
|
||||
html`${IntentToLabel(item.intent || IntentEnum.Api)}`,
|
||||
html`${intentToLabel(item.intent ?? IntentEnum.Api)}`,
|
||||
html`
|
||||
${!item.managed
|
||||
? html`<ak-forms-modal>
|
||||
|
||||
Reference in New Issue
Block a user