From d35c7df789f4dfb785ef010046550598b3aa3bf5 Mon Sep 17 00:00:00 2001 From: Ken Sternberg <133134217+kensternberg-authentik@users.noreply.github.com> Date: Wed, 13 Sep 2023 12:28:42 -0700 Subject: [PATCH] web: detangle element to admin references (#6864) * 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) 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. * web: remove admin from elements This commit removes the two references from `elements` to `admin`: the list of UserEvents and a reference to the FlowSearch type, used by the Forms manager to decide how to extract a value. For FlowSearch, a different convention for detecting the type was implemented (instances of the object have a unique fieldname for the value holder). UserEvents and ObjectChangelog have been moved to `components` as they're clearly dependent upon the API. This defers work on removing Admin from Components, as that is (again) references going the wrong way, but that can happen later. * 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 was supposed to be merged. --- web/src/admin/applications/ApplicationViewPage.ts | 2 +- web/src/admin/flows/FlowViewPage.ts | 2 +- web/src/admin/groups/GroupViewPage.ts | 2 +- web/src/admin/providers/ldap/LDAPProviderViewPage.ts | 2 +- web/src/admin/providers/oauth2/OAuth2ProviderViewPage.ts | 2 +- web/src/admin/providers/proxy/ProxyProviderViewPage.ts | 2 +- web/src/admin/providers/radius/RadiusProviderViewPage.ts | 2 +- web/src/admin/providers/saml/SAMLProviderViewPage.ts | 2 +- web/src/admin/providers/scim/SCIMProviderViewPage.ts | 2 +- web/src/admin/sources/ldap/LDAPSourceViewPage.ts | 2 +- web/src/admin/sources/oauth/OAuthSourceViewPage.ts | 2 +- web/src/admin/sources/plex/PlexSourceViewPage.ts | 2 +- web/src/admin/sources/saml/SAMLSourceViewPage.ts | 2 +- web/src/admin/users/UserViewPage.ts | 4 ++-- web/src/{elements => components}/events/ObjectChangelog.ts | 0 web/src/{elements => components}/events/UserEvents.ts | 0 web/src/elements/forms/Form.ts | 3 +-- 17 files changed, 16 insertions(+), 17 deletions(-) rename web/src/{elements => components}/events/ObjectChangelog.ts (100%) rename web/src/{elements => components}/events/UserEvents.ts (100%) diff --git a/web/src/admin/applications/ApplicationViewPage.ts b/web/src/admin/applications/ApplicationViewPage.ts index 1881c0f04..f65182ca7 100644 --- a/web/src/admin/applications/ApplicationViewPage.ts +++ b/web/src/admin/applications/ApplicationViewPage.ts @@ -5,12 +5,12 @@ 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 "@goauthentik/components/events/ObjectChangelog"; 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 { msg } from "@lit/localize"; import { CSSResult, TemplateResult, html } from "lit"; diff --git a/web/src/admin/flows/FlowViewPage.ts b/web/src/admin/flows/FlowViewPage.ts index a6448678b..ee88ff2e3 100644 --- a/web/src/admin/flows/FlowViewPage.ts +++ b/web/src/admin/flows/FlowViewPage.ts @@ -3,11 +3,11 @@ import "@goauthentik/admin/flows/FlowDiagram"; import "@goauthentik/admin/flows/FlowForm"; import "@goauthentik/admin/policies/BoundPoliciesList"; import { AndNext, DEFAULT_CONFIG } from "@goauthentik/common/api/config"; +import "@goauthentik/components/events/ObjectChangelog"; import { AKElement } from "@goauthentik/elements/Base"; import "@goauthentik/elements/PageHeader"; import "@goauthentik/elements/Tabs"; import "@goauthentik/elements/buttons/SpinnerButton"; -import "@goauthentik/elements/events/ObjectChangelog"; import { msg } from "@lit/localize"; import { CSSResult, TemplateResult, css, html } from "lit"; diff --git a/web/src/admin/groups/GroupViewPage.ts b/web/src/admin/groups/GroupViewPage.ts index 33d89b88f..0cbdcee5e 100644 --- a/web/src/admin/groups/GroupViewPage.ts +++ b/web/src/admin/groups/GroupViewPage.ts @@ -2,6 +2,7 @@ import "@goauthentik/admin/groups/GroupForm"; import "@goauthentik/admin/users/RelatedUserList"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { EVENT_REFRESH } from "@goauthentik/common/constants"; +import "@goauthentik/components/events/ObjectChangelog"; import { AKElement } from "@goauthentik/elements/Base"; import "@goauthentik/elements/CodeMirror"; import { PFColor } from "@goauthentik/elements/Label"; @@ -9,7 +10,6 @@ import "@goauthentik/elements/PageHeader"; import "@goauthentik/elements/Tabs"; import "@goauthentik/elements/buttons/ActionButton"; import "@goauthentik/elements/buttons/SpinnerButton"; -import "@goauthentik/elements/events/ObjectChangelog"; import "@goauthentik/elements/forms/ModalForm"; import { msg, str } from "@lit/localize"; diff --git a/web/src/admin/providers/ldap/LDAPProviderViewPage.ts b/web/src/admin/providers/ldap/LDAPProviderViewPage.ts index 6693ee8d6..f644bb7c5 100644 --- a/web/src/admin/providers/ldap/LDAPProviderViewPage.ts +++ b/web/src/admin/providers/ldap/LDAPProviderViewPage.ts @@ -3,12 +3,12 @@ import "@goauthentik/admin/providers/ldap/LDAPProviderForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { EVENT_REFRESH } from "@goauthentik/common/constants"; import { me } from "@goauthentik/common/users"; +import "@goauthentik/components/events/ObjectChangelog"; import { AKElement } from "@goauthentik/elements/Base"; import "@goauthentik/elements/CodeMirror"; import "@goauthentik/elements/Tabs"; import "@goauthentik/elements/buttons/ModalButton"; import "@goauthentik/elements/buttons/SpinnerButton"; -import "@goauthentik/elements/events/ObjectChangelog"; import { msg } from "@lit/localize"; import { CSSResult, TemplateResult, html } from "lit"; diff --git a/web/src/admin/providers/oauth2/OAuth2ProviderViewPage.ts b/web/src/admin/providers/oauth2/OAuth2ProviderViewPage.ts index cefc5b959..920e71ceb 100644 --- a/web/src/admin/providers/oauth2/OAuth2ProviderViewPage.ts +++ b/web/src/admin/providers/oauth2/OAuth2ProviderViewPage.ts @@ -3,6 +3,7 @@ import "@goauthentik/admin/providers/oauth2/OAuth2ProviderForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { EVENT_REFRESH } from "@goauthentik/common/constants"; import { convertToTitle } from "@goauthentik/common/utils"; +import "@goauthentik/components/events/ObjectChangelog"; import MDProviderOAuth2 from "@goauthentik/docs/providers/oauth2/index.md"; import { AKElement } from "@goauthentik/elements/Base"; import "@goauthentik/elements/CodeMirror"; @@ -11,7 +12,6 @@ import "@goauthentik/elements/Markdown"; import "@goauthentik/elements/Tabs"; import "@goauthentik/elements/buttons/ModalButton"; import "@goauthentik/elements/buttons/SpinnerButton"; -import "@goauthentik/elements/events/ObjectChangelog"; import { msg } from "@lit/localize"; import { CSSResult, TemplateResult, html } from "lit"; diff --git a/web/src/admin/providers/proxy/ProxyProviderViewPage.ts b/web/src/admin/providers/proxy/ProxyProviderViewPage.ts index 91c50f546..2451cfa1e 100644 --- a/web/src/admin/providers/proxy/ProxyProviderViewPage.ts +++ b/web/src/admin/providers/proxy/ProxyProviderViewPage.ts @@ -3,6 +3,7 @@ import "@goauthentik/admin/providers/proxy/ProxyProviderForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { EVENT_REFRESH } from "@goauthentik/common/constants"; import { convertToSlug } from "@goauthentik/common/utils"; +import "@goauthentik/components/events/ObjectChangelog"; import MDCaddyStandalone from "@goauthentik/docs/providers/proxy/_caddy_standalone.md"; import MDNginxIngress from "@goauthentik/docs/providers/proxy/_nginx_ingress.md"; import MDNginxPM from "@goauthentik/docs/providers/proxy/_nginx_proxy_manager.md"; @@ -20,7 +21,6 @@ import { Replacer } from "@goauthentik/elements/Markdown"; import "@goauthentik/elements/Tabs"; import "@goauthentik/elements/buttons/ModalButton"; import "@goauthentik/elements/buttons/SpinnerButton"; -import "@goauthentik/elements/events/ObjectChangelog"; import { getURLParam } from "@goauthentik/elements/router/RouteMatch"; import { msg } from "@lit/localize"; diff --git a/web/src/admin/providers/radius/RadiusProviderViewPage.ts b/web/src/admin/providers/radius/RadiusProviderViewPage.ts index e181766fc..b62600a97 100644 --- a/web/src/admin/providers/radius/RadiusProviderViewPage.ts +++ b/web/src/admin/providers/radius/RadiusProviderViewPage.ts @@ -2,12 +2,12 @@ import "@goauthentik/admin/providers/RelatedApplicationButton"; import "@goauthentik/admin/providers/radius/RadiusProviderForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { EVENT_REFRESH } from "@goauthentik/common/constants"; +import "@goauthentik/components/events/ObjectChangelog"; import { AKElement } from "@goauthentik/elements/Base"; import "@goauthentik/elements/CodeMirror"; import "@goauthentik/elements/Tabs"; import "@goauthentik/elements/buttons/ModalButton"; import "@goauthentik/elements/buttons/SpinnerButton"; -import "@goauthentik/elements/events/ObjectChangelog"; import { msg } from "@lit/localize"; import { CSSResult, TemplateResult, html } from "lit"; diff --git a/web/src/admin/providers/saml/SAMLProviderViewPage.ts b/web/src/admin/providers/saml/SAMLProviderViewPage.ts index 82fccf1a9..3e8d773ef 100644 --- a/web/src/admin/providers/saml/SAMLProviderViewPage.ts +++ b/web/src/admin/providers/saml/SAMLProviderViewPage.ts @@ -3,6 +3,7 @@ import "@goauthentik/admin/providers/saml/SAMLProviderForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { EVENT_REFRESH } from "@goauthentik/common/constants"; import { MessageLevel } from "@goauthentik/common/messages"; +import "@goauthentik/components/events/ObjectChangelog"; import { AKElement } from "@goauthentik/elements/Base"; import "@goauthentik/elements/CodeMirror"; import "@goauthentik/elements/EmptyState"; @@ -10,7 +11,6 @@ import "@goauthentik/elements/Tabs"; import "@goauthentik/elements/buttons/ActionButton"; import "@goauthentik/elements/buttons/ModalButton"; import "@goauthentik/elements/buttons/SpinnerButton"; -import "@goauthentik/elements/events/ObjectChangelog"; import { showMessage } from "@goauthentik/elements/messages/MessageContainer"; import { msg } from "@lit/localize"; diff --git a/web/src/admin/providers/scim/SCIMProviderViewPage.ts b/web/src/admin/providers/scim/SCIMProviderViewPage.ts index 72174836f..8a4d7fe0b 100644 --- a/web/src/admin/providers/scim/SCIMProviderViewPage.ts +++ b/web/src/admin/providers/scim/SCIMProviderViewPage.ts @@ -1,13 +1,13 @@ import "@goauthentik/admin/providers/scim/SCIMProviderForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { EVENT_REFRESH } from "@goauthentik/common/constants"; +import "@goauthentik/components/events/ObjectChangelog"; import MDSCIMProvider from "@goauthentik/docs/providers/scim/index.md"; import { AKElement } from "@goauthentik/elements/Base"; import "@goauthentik/elements/Markdown"; import "@goauthentik/elements/Tabs"; import "@goauthentik/elements/buttons/ActionButton"; import "@goauthentik/elements/buttons/ModalButton"; -import "@goauthentik/elements/events/ObjectChangelog"; import { msg } from "@lit/localize"; import { CSSResult, TemplateResult, html } from "lit"; diff --git a/web/src/admin/sources/ldap/LDAPSourceViewPage.ts b/web/src/admin/sources/ldap/LDAPSourceViewPage.ts index 84bd662b4..2c74bc5f2 100644 --- a/web/src/admin/sources/ldap/LDAPSourceViewPage.ts +++ b/web/src/admin/sources/ldap/LDAPSourceViewPage.ts @@ -1,12 +1,12 @@ import "@goauthentik/admin/sources/ldap/LDAPSourceForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { EVENT_REFRESH } from "@goauthentik/common/constants"; +import "@goauthentik/components/events/ObjectChangelog"; import { AKElement } from "@goauthentik/elements/Base"; import "@goauthentik/elements/CodeMirror"; import "@goauthentik/elements/Tabs"; import "@goauthentik/elements/buttons/ActionButton"; import "@goauthentik/elements/buttons/SpinnerButton"; -import "@goauthentik/elements/events/ObjectChangelog"; import "@goauthentik/elements/forms/ModalForm"; import { msg, str } from "@lit/localize"; diff --git a/web/src/admin/sources/oauth/OAuthSourceViewPage.ts b/web/src/admin/sources/oauth/OAuthSourceViewPage.ts index fba2c7eee..3bfa5cdaf 100644 --- a/web/src/admin/sources/oauth/OAuthSourceViewPage.ts +++ b/web/src/admin/sources/oauth/OAuthSourceViewPage.ts @@ -3,11 +3,11 @@ import "@goauthentik/admin/sources/oauth/OAuthSourceDiagram"; import "@goauthentik/admin/sources/oauth/OAuthSourceForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { EVENT_REFRESH } from "@goauthentik/common/constants"; +import "@goauthentik/components/events/ObjectChangelog"; import { AKElement } from "@goauthentik/elements/Base"; import "@goauthentik/elements/CodeMirror"; import "@goauthentik/elements/Tabs"; import "@goauthentik/elements/buttons/SpinnerButton"; -import "@goauthentik/elements/events/ObjectChangelog"; import "@goauthentik/elements/forms/ModalForm"; import { msg } from "@lit/localize"; diff --git a/web/src/admin/sources/plex/PlexSourceViewPage.ts b/web/src/admin/sources/plex/PlexSourceViewPage.ts index f18f5a81f..51db79d27 100644 --- a/web/src/admin/sources/plex/PlexSourceViewPage.ts +++ b/web/src/admin/sources/plex/PlexSourceViewPage.ts @@ -2,11 +2,11 @@ import "@goauthentik/admin/policies/BoundPoliciesList"; import "@goauthentik/admin/sources/plex/PlexSourceForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { EVENT_REFRESH } from "@goauthentik/common/constants"; +import "@goauthentik/components/events/ObjectChangelog"; import { AKElement } from "@goauthentik/elements/Base"; import "@goauthentik/elements/CodeMirror"; import "@goauthentik/elements/Tabs"; import "@goauthentik/elements/buttons/SpinnerButton"; -import "@goauthentik/elements/events/ObjectChangelog"; import "@goauthentik/elements/forms/ModalForm"; import { msg } from "@lit/localize"; diff --git a/web/src/admin/sources/saml/SAMLSourceViewPage.ts b/web/src/admin/sources/saml/SAMLSourceViewPage.ts index ccf197f21..b85768242 100644 --- a/web/src/admin/sources/saml/SAMLSourceViewPage.ts +++ b/web/src/admin/sources/saml/SAMLSourceViewPage.ts @@ -2,11 +2,11 @@ import "@goauthentik/admin/policies/BoundPoliciesList"; import "@goauthentik/admin/sources/saml/SAMLSourceForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { EVENT_REFRESH } from "@goauthentik/common/constants"; +import "@goauthentik/components/events/ObjectChangelog"; import { AKElement } from "@goauthentik/elements/Base"; import "@goauthentik/elements/CodeMirror"; import "@goauthentik/elements/Tabs"; import "@goauthentik/elements/buttons/SpinnerButton"; -import "@goauthentik/elements/events/ObjectChangelog"; import "@goauthentik/elements/forms/ModalForm"; import { msg } from "@lit/localize"; diff --git a/web/src/admin/users/UserViewPage.ts b/web/src/admin/users/UserViewPage.ts index 60e62c0c8..dccc34101 100644 --- a/web/src/admin/users/UserViewPage.ts +++ b/web/src/admin/users/UserViewPage.ts @@ -6,6 +6,8 @@ import "@goauthentik/admin/users/UserPasswordForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { EVENT_REFRESH } from "@goauthentik/common/constants"; import { MessageLevel } from "@goauthentik/common/messages"; +import "@goauthentik/components/events/ObjectChangelog"; +import "@goauthentik/components/events/UserEvents"; import { AKElement, rootInterface } from "@goauthentik/elements/Base"; import "@goauthentik/elements/CodeMirror"; import { PFColor } from "@goauthentik/elements/Label"; @@ -14,8 +16,6 @@ import { PFSize } from "@goauthentik/elements/Spinner"; import "@goauthentik/elements/Tabs"; import "@goauthentik/elements/buttons/ActionButton"; import "@goauthentik/elements/buttons/SpinnerButton"; -import "@goauthentik/elements/events/ObjectChangelog"; -import "@goauthentik/elements/events/UserEvents"; import "@goauthentik/elements/forms/ModalForm"; import { showMessage } from "@goauthentik/elements/messages/MessageContainer"; import "@goauthentik/elements/oauth/UserRefreshList"; diff --git a/web/src/elements/events/ObjectChangelog.ts b/web/src/components/events/ObjectChangelog.ts similarity index 100% rename from web/src/elements/events/ObjectChangelog.ts rename to web/src/components/events/ObjectChangelog.ts diff --git a/web/src/elements/events/UserEvents.ts b/web/src/components/events/UserEvents.ts similarity index 100% rename from web/src/elements/events/UserEvents.ts rename to web/src/components/events/UserEvents.ts diff --git a/web/src/elements/forms/Form.ts b/web/src/elements/forms/Form.ts index 3685084ae..6c69365a7 100644 --- a/web/src/elements/forms/Form.ts +++ b/web/src/elements/forms/Form.ts @@ -1,4 +1,3 @@ -import { FlowSearch } from "@goauthentik/admin/common/ak-flow-search/FlowSearch"; import { PreventFormSubmit } from "@goauthentik/app/elements/forms/helpers"; import { EVENT_REFRESH } from "@goauthentik/common/constants"; import { MessageLevel } from "@goauthentik/common/messages"; @@ -172,7 +171,7 @@ export abstract class Form extends AKElement { inputElement.type === "checkbox" ) { json[element.name] = inputElement.checked; - } else if (inputElement instanceof FlowSearch) { + } else if ("selectedFlow" in inputElement) { json[element.name] = inputElement.value; } else if (inputElement.tagName.toLowerCase() === "ak-search-select") { const select = inputElement as unknown as SearchSelect;