diff --git a/authentik/admin/urls.py b/authentik/admin/urls.py index 6402e6efa..56b3769a8 100644 --- a/authentik/admin/urls.py +++ b/authentik/admin/urls.py @@ -2,7 +2,6 @@ from django.urls import path from authentik.admin.views import ( - outposts, outposts_service_connections, policies, policies_bindings, @@ -114,17 +113,6 @@ urlpatterns = [ property_mappings.PropertyMappingTestView.as_view(), name="property-mapping-test", ), - # Outposts - path( - "outposts/create/", - outposts.OutpostCreateView.as_view(), - name="outpost-create", - ), - path( - "outposts//update/", - outposts.OutpostUpdateView.as_view(), - name="outpost-update", - ), # Outpost Service Connections path( "outpost_service_connections/create/", diff --git a/authentik/admin/views/outposts.py b/authentik/admin/views/outposts.py deleted file mode 100644 index fa1b93afc..000000000 --- a/authentik/admin/views/outposts.py +++ /dev/null @@ -1,55 +0,0 @@ -"""authentik Outpost administration""" -from dataclasses import asdict -from typing import Any - -from django.contrib.auth.mixins import LoginRequiredMixin -from django.contrib.auth.mixins import ( - PermissionRequiredMixin as DjangoPermissionRequiredMixin, -) -from django.contrib.messages.views import SuccessMessageMixin -from django.utils.translation import gettext as _ -from django.views.generic import UpdateView -from guardian.mixins import PermissionRequiredMixin - -from authentik.lib.views import CreateAssignPermView -from authentik.outposts.forms import OutpostForm -from authentik.outposts.models import Outpost, OutpostConfig - - -class OutpostCreateView( - SuccessMessageMixin, - LoginRequiredMixin, - DjangoPermissionRequiredMixin, - CreateAssignPermView, -): - """Create new Outpost""" - - model = Outpost - form_class = OutpostForm - permission_required = "authentik_outposts.add_outpost" - success_url = "/" - template_name = "generic/create.html" - success_message = _("Successfully created Outpost") - - def get_initial(self) -> dict[str, Any]: - return { - "_config": asdict( - OutpostConfig(authentik_host=self.request.build_absolute_uri("/")) - ) - } - - -class OutpostUpdateView( - SuccessMessageMixin, - LoginRequiredMixin, - PermissionRequiredMixin, - UpdateView, -): - """Update outpost""" - - model = Outpost - form_class = OutpostForm - permission_required = "authentik_outposts.change_outpost" - success_url = "/" - template_name = "generic/update.html" - success_message = _("Successfully updated Outpost") diff --git a/authentik/outposts/api/outposts.py b/authentik/outposts/api/outposts.py index 5734e4057..566b1c5d7 100644 --- a/authentik/outposts/api/outposts.py +++ b/authentik/outposts/api/outposts.py @@ -95,4 +95,5 @@ class OutpostViewSet(ModelViewSet): @action(detail=False, methods=["GET"]) def default_settings(self, request: Request) -> Response: """Global default outpost config""" - return Response({"config": default_outpost_config(request._request.get_host())}) + host = self.request.build_absolute_uri("/") + return Response({"config": default_outpost_config(host)}) diff --git a/web/src/api/legacy.ts b/web/src/api/legacy.ts index d38d9610e..2c1855575 100644 --- a/web/src/api/legacy.ts +++ b/web/src/api/legacy.ts @@ -16,10 +16,6 @@ export class AdminURLManager { return `/administration/property-mappings/${rest}`; } - static outposts(rest: string): string { - return `/administration/outposts/${rest}`; - } - static outpostServiceConnections(rest: string): string { return `/administration/outpost_service_connections/${rest}`; } diff --git a/web/src/pages/flows/FlowViewPage.ts b/web/src/pages/flows/FlowViewPage.ts index f72a5cf15..2e381ae58 100644 --- a/web/src/pages/flows/FlowViewPage.ts +++ b/web/src/pages/flows/FlowViewPage.ts @@ -84,7 +84,7 @@ export class FlowViewPage extends LitElement { class="pf-c-button pf-m-secondary" @click=${() => { new FlowsApi(DEFAULT_CONFIG).flowsInstancesExecute({ - slug: flow.slug + slug: this.flow.slug }).then(link => { window.location.assign(`${link.link}?next=/%23${window.location.href}`); }); diff --git a/web/src/pages/outposts/OutpostForm.ts b/web/src/pages/outposts/OutpostForm.ts new file mode 100644 index 000000000..d62488b5b --- /dev/null +++ b/web/src/pages/outposts/OutpostForm.ts @@ -0,0 +1,102 @@ +import { CoreApi, Outpost, OutpostsApi, ProvidersApi } from "authentik-api"; +import { gettext } from "django"; +import { customElement, property } from "lit-element"; +import { html, TemplateResult } from "lit-html"; +import { DEFAULT_CONFIG } from "../../api/Config"; +import { Form } from "../../elements/forms/Form"; +import { until } from "lit-html/directives/until"; +import { ifDefined } from "lit-html/directives/if-defined"; +import "../../elements/forms/HorizontalFormElement"; +import "../../elements/CodeMirror"; +import YAML from "yaml"; + +@customElement("ak-outpost-form") +export class OutpostForm extends Form { + + @property({attribute: false}) + outpost?: Outpost; + + getSuccessMessage(): string { + if (this.outpost) { + return gettext("Successfully updated outpost."); + } else { + return gettext("Successfully created outpost."); + } + } + + send = (data: Outpost): Promise => { + if (this.outpost) { + return new OutpostsApi(DEFAULT_CONFIG).outpostsOutpostsUpdate({ + uuid: this.outpost.pk || "", + data: data + }); + } else { + return new OutpostsApi(DEFAULT_CONFIG).outpostsOutpostsCreate({ + data: data + }); + } + }; + + renderForm(): TemplateResult { + return html`
+ + + + + + + + + + + +

${gettext("Hold control/command to select multiple items.")}

+
+ ${until(new OutpostsApi(DEFAULT_CONFIG).outpostsOutpostsDefaultSettings({}).then(config => { + let fc = config.config; + if (this.outpost) { + fc = this.outpost.config; + } + return html` + + `; + }))} +
`; + } + +} diff --git a/web/src/pages/outposts/OutpostListPage.ts b/web/src/pages/outposts/OutpostListPage.ts index 8b87d7e4e..c39018c1c 100644 --- a/web/src/pages/outposts/OutpostListPage.ts +++ b/web/src/pages/outposts/OutpostListPage.ts @@ -6,14 +6,13 @@ import { TableColumn } from "../../elements/table/Table"; import { TablePage } from "../../elements/table/TablePage"; import "./OutpostHealth"; +import "./OutpostForm"; import "../../elements/buttons/SpinnerButton"; -import "../../elements/buttons/ModalButton"; import "../../elements/buttons/TokenCopyButton"; import "../../elements/forms/DeleteForm"; import { PAGE_SIZE } from "../../constants"; import { Outpost, OutpostsApi } from "authentik-api"; import { DEFAULT_CONFIG } from "../../api/Config"; -import { AdminURLManager } from "../../api/legacy"; import { ifDefined } from "lit-html/directives/if-defined"; @customElement("ak-outpost-list") @@ -58,12 +57,19 @@ export class OutpostListPage extends TablePage { })}`, html``, html` - - + + + ${gettext("Update")} + + + ${gettext("Update Outpost")} + + + + + { renderToolbar(): TemplateResult { return html` - - + + ${gettext("Create")} - -
-
+ + + ${gettext("Create Outpost")} + + + + + ${super.renderToolbar()} `; }