web: use version family subdomain for in-app doc links

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2022-12-22 17:03:08 +01:00
parent 4c133b957c
commit e4e7a112e3
No known key found for this signature in database
11 changed files with 42 additions and 15 deletions

View file

@ -2,10 +2,14 @@
{% get_current_language as LANGUAGE_CODE %}
<script>
window.authentik = {};
window.authentik.locale = "{{ LANGUAGE_CODE }}";
window.authentik.config = JSON.parse('{{ config_json|escapejs }}');
window.authentik.tenant = JSON.parse('{{ tenant_json|escapejs }}');
window.authentik = {
locale: "{{ LANGUAGE_CODE }}",
config: JSON.parse('{{ config_json|escapejs }}'),
tenant: JSON.parse('{{ tenant_json|escapejs }}'),
versionFamily: "{{ version_family }}",
versionSubdomain: "{{ version_subdomain }}",
build: "{{ build }}",
};
window.addEventListener("DOMContentLoaded", () => {
{% for message in messages %}
window.dispatchEvent(

View file

@ -5,6 +5,8 @@ from typing import Any
from django.shortcuts import get_object_or_404
from django.views.generic.base import TemplateView
from rest_framework.request import Request
from authentik import get_build_hash
from authentik.admin.tasks import LOCAL_VERSION
from authentik.api.v3.config import ConfigView
from authentik.flows.models import Flow
@ -17,6 +19,9 @@ class InterfaceView(TemplateView):
def get_context_data(self, **kwargs: Any) -> dict[str, Any]:
kwargs["config_json"] = dumps(ConfigView(request=Request(self.request)).get_config().data)
kwargs["tenant_json"] = dumps(CurrentTenantSerializer(self.request.tenant).data)
kwargs["version_family"] = f"{LOCAL_VERSION.major}.{LOCAL_VERSION.minor}"
kwargs["version_subdomain"] = f"version-{LOCAL_VERSION.major}-{LOCAL_VERSION.minor}"
kwargs["build"] = get_build_hash()
return super().get_context_data(**kwargs)

View file

@ -1,3 +1,4 @@
import { docLink } from "@goauthentik/common/global";
import { ModalButton } from "@goauthentik/elements/buttons/ModalButton";
import "@goauthentik/elements/buttons/TokenCopyButton";
@ -22,7 +23,7 @@ export class OutpostDeploymentModal extends ModalButton {
<p>
<a
target="_blank"
href="https://goauthentik.io/docs/outposts?utm_source=authentik#deploy"
href="${docLink("/docs/outposts?utm_source=authentik#deploy")}"
>${t`View deployment documentation`}</a
>
</p>

View file

@ -1,4 +1,5 @@
import { DEFAULT_CONFIG } from "@goauthentik/common/api/config";
import { docLink } from "@goauthentik/common/global";
import "@goauthentik/elements/CodeMirror";
import "@goauthentik/elements/forms/HorizontalFormElement";
import { ModelForm } from "@goauthentik/elements/forms/ModelForm";
@ -164,9 +165,7 @@ export class OutpostForm extends ModelForm<Outpost, string> {
</p>
<p class="pf-c-form__helper-text">
See
<a
target="_blank"
href="https://goauthentik.io/docs/outposts?utm_source=authentik"
<a target="_blank" href="${docLink("/docs/outposts?utm_source=authentik")}"
>documentation</a
>.
</p>
@ -209,7 +208,7 @@ export class OutpostForm extends ModelForm<Outpost, string> {
See
<a
target="_blank"
href="https://goauthentik.io/docs/outposts?utm_source=authentik#configuration"
href="${docLink("/docs/outposts?utm_source=authentik#configuration")}"
>documentation</a
>.
</p>

View file

@ -1,4 +1,5 @@
import { DEFAULT_CONFIG } from "@goauthentik/common/api/config";
import { docLink } from "@goauthentik/common/global";
import { first } from "@goauthentik/common/utils";
import "@goauthentik/elements/CodeMirror";
import "@goauthentik/elements/forms/FormGroup";
@ -85,7 +86,7 @@ export class ExpressionPolicyForm extends ModelForm<ExpressionPolicy, string> {
${t`Expression using Python.`}
<a
target="_blank"
href="https://goauthentik.io/docs/policies/expression?utm_source=authentik"
href="${docLink("/docs/policies/expression?utm_source=authentik")}"
>
${t`See documentation for a list of all variables.`}
</a>

View file

@ -1,4 +1,5 @@
import { DEFAULT_CONFIG } from "@goauthentik/common/api/config";
import { docLink } from "@goauthentik/common/global";
import "@goauthentik/elements/CodeMirror";
import "@goauthentik/elements/forms/HorizontalFormElement";
import { ModelForm } from "@goauthentik/elements/forms/ModelForm";
@ -72,7 +73,7 @@ export class PropertyMappingLDAPForm extends ModelForm<LDAPPropertyMapping, stri
${t`Expression using Python.`}
<a
target="_blank"
href="https://goauthentik.io/docs/property-mappings/expression?utm_source=authentik"
href="${docLink("/docs/property-mappings/expression?utm_source=authentik")}"
>
${t`See documentation for a list of all variables.`}
</a>

View file

@ -1,4 +1,5 @@
import { DEFAULT_CONFIG } from "@goauthentik/common/api/config";
import { docLink } from "@goauthentik/common/global";
import "@goauthentik/elements/CodeMirror";
import "@goauthentik/elements/forms/HorizontalFormElement";
import { ModelForm } from "@goauthentik/elements/forms/ModelForm";
@ -57,7 +58,7 @@ export class PropertyMappingNotification extends ModelForm<NotificationWebhookMa
${t`Expression using Python.`}
<a
target="_blank"
href="https://goauthentik.io/docs/property-mappings/expression?utm_source=authentik"
href="${docLink("/docs/property-mappings/expression?utm_source=authentik")}"
>
${t`See documentation for a list of all variables.`}
</a>

View file

@ -1,4 +1,5 @@
import { DEFAULT_CONFIG } from "@goauthentik/common/api/config";
import { docLink } from "@goauthentik/common/global";
import "@goauthentik/elements/CodeMirror";
import "@goauthentik/elements/forms/HorizontalFormElement";
import { ModelForm } from "@goauthentik/elements/forms/ModelForm";
@ -82,7 +83,7 @@ export class PropertyMappingLDAPForm extends ModelForm<SAMLPropertyMapping, stri
${t`Expression using Python.`}
<a
target="_blank"
href="https://goauthentik.io/docs/property-mappings/expression?utm_source=authentik"
href="${docLink("/docs/property-mappings/expression?utm_source=authentik")}"
>
${t`See documentation for a list of all variables.`}
</a>

View file

@ -1,4 +1,5 @@
import { DEFAULT_CONFIG } from "@goauthentik/common/api/config";
import { docLink } from "@goauthentik/common/global";
import "@goauthentik/elements/CodeMirror";
import "@goauthentik/elements/forms/HorizontalFormElement";
import { ModelForm } from "@goauthentik/elements/forms/ModelForm";
@ -78,7 +79,7 @@ export class PropertyMappingScopeForm extends ModelForm<ScopeMapping, string> {
${t`Expression using Python.`}
<a
target="_blank"
href="https://goauthentik.io/docs/property-mappings/expression?utm_source=authentik"
href="${docLink("/docs/property-mappings/expression?utm_source=authentik")}"
>
${t`See documentation for a list of all variables.`}
</a>

View file

@ -7,6 +7,9 @@ export interface GlobalAuthentik {
};
config: Config;
tenant: CurrentTenant;
versionFamily: string;
versionSubdomain: string;
build: string;
}
export interface AuthentikWindow {
@ -16,3 +19,12 @@ export interface AuthentikWindow {
export function globalAK(): GlobalAuthentik | undefined {
return (window as unknown as AuthentikWindow).authentik;
}
export function docLink(path: string): string {
const ak = globalAK();
// Default case or beta build which should always point to latest
if (!ak || ak.build !== "") {
return `https://goauthentik.io${path}`;
}
return `https://${ak.versionSubdomain}.goauthentik.io${path}`;
}

View file

@ -1,3 +1,4 @@
import { docLink } from "@goauthentik/common/global";
import "@goauthentik/elements/Alert";
import { AKElement } from "@goauthentik/elements/Base";
@ -56,7 +57,7 @@ export class Markdown extends AKElement {
if (md.filename === "index.md") {
relPath = relPath.replace("index.md", "");
}
const baseURL = "https://goauthentik.io";
const baseURL = docLink("");
const fullURL = `${baseURL}${relPath}.$1`;
return input.replace(relativeLink, `href="${fullURL}" target="_blank"`);
}