web/admin: show outpost warning on application page too

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-12-06 10:10:44 +01:00
parent b694816e7b
commit e3e9178ccc
6 changed files with 91 additions and 9 deletions

View File

@ -1,6 +1,8 @@
"""Outpost API Views"""
from dacite.core import from_dict
from dacite.exceptions import DaciteError
from django_filters.filters import ModelMultipleChoiceFilter
from django_filters.filterset import FilterSet
from drf_spectacular.utils import extend_schema
from rest_framework.decorators import action
from rest_framework.fields import BooleanField, CharField, DateTimeField
@ -99,16 +101,30 @@ class OutpostHealthSerializer(PassiveSerializer):
version_outdated = BooleanField(read_only=True)
class OutpostFilter(FilterSet):
"""Filter for Outposts"""
providers_by_pk = ModelMultipleChoiceFilter(
field_name="providers",
queryset=Provider.objects.all(),
)
class Meta:
model = Outpost
fields = {
"providers": ["isnull"],
"name": ["iexact", "icontains"],
"service_connection__name": ["iexact", "icontains"],
}
class OutpostViewSet(UsedByMixin, ModelViewSet):
"""Outpost Viewset"""
queryset = Outpost.objects.all()
serializer_class = OutpostSerializer
filterset_fields = {
"providers": ["isnull"],
"name": ["iexact", "icontains"],
"service_connection__name": ["iexact", "icontains"],
}
filterset_class = OutpostFilter
search_fields = [
"name",
"providers__name",

View File

@ -5764,6 +5764,14 @@ paths:
name: providers__isnull
schema:
type: boolean
- in: query
name: providers_by_pk
schema:
type: array
items:
type: integer
explode: true
style: form
- name: search
required: false
in: query
@ -5952,6 +5960,14 @@ paths:
name: providers__isnull
schema:
type: boolean
- in: query
name: providers_by_pk
schema:
type: array
items:
type: integer
explode: true
style: form
- name: search
required: false
in: query

View File

@ -5619,6 +5619,10 @@ msgstr "Wait (min)"
msgid "Warning"
msgstr "Warning"
#: src/pages/applications/ApplicationViewPage.ts
msgid "Warning: Application is not used by any Outpost."
msgstr "Warning: Application is not used by any Outpost."
#: src/pages/stages/invitation/InvitationListPage.ts
msgid "Warning: No invitation stage is bound to any flow. Invitations will not work as expected."
msgstr "Warning: No invitation stage is bound to any flow. Invitations will not work as expected."

View File

@ -5557,6 +5557,10 @@ msgstr "Attente (min)"
msgid "Warning"
msgstr "Avertissement"
#: src/pages/applications/ApplicationViewPage.ts
msgid "Warning: Application is not used by any Outpost."
msgstr ""
#: src/pages/stages/invitation/InvitationListPage.ts
msgid "Warning: No invitation stage is bound to any flow. Invitations will not work as expected."
msgstr ""

View File

@ -5599,6 +5599,10 @@ msgstr ""
msgid "Warning"
msgstr ""
#: src/pages/applications/ApplicationViewPage.ts
msgid "Warning: Application is not used by any Outpost."
msgstr ""
#: src/pages/stages/invitation/InvitationListPage.ts
msgid "Warning: No invitation stage is bound to any flow. Invitations will not work as expected."
msgstr ""

View File

@ -1,10 +1,11 @@
import { t } from "@lingui/macro";
import { CSSResult, LitElement, TemplateResult, html } from "lit";
import { customElement, property } from "lit/decorators.js";
import { customElement, property, state } from "lit/decorators.js";
import { ifDefined } from "lit/directives/if-defined.js";
import AKGlobal from "../../authentik.css";
import PFBanner from "@patternfly/patternfly/components/Banner/banner.css";
import PFButton from "@patternfly/patternfly/components/Button/button.css";
import PFCard from "@patternfly/patternfly/components/Card/card.css";
import PFContent from "@patternfly/patternfly/components/Content/content.css";
@ -13,7 +14,7 @@ import PFPage from "@patternfly/patternfly/components/Page/page.css";
import PFGrid from "@patternfly/patternfly/layouts/Grid/grid.css";
import PFBase from "@patternfly/patternfly/patternfly-base.css";
import { Application, CoreApi } from "@goauthentik/api";
import { Application, CoreApi, OutpostsApi } from "@goauthentik/api";
import { DEFAULT_CONFIG } from "../../api/Config";
import "../../elements/EmptyState";
@ -36,14 +37,45 @@ export class ApplicationViewPage extends LitElement {
})
.then((app) => {
this.application = app;
if (
app.providerObj &&
[
"authentik_providers_proxy.proxyprovider",
"authentik_providers_ldap.ldapprovider",
].includes(app.providerObj.metaModelName)
) {
new OutpostsApi(DEFAULT_CONFIG)
.outpostsInstancesList({
providersByPk: [app.provider || 0],
pageSize: 1,
})
.then((outposts) => {
if (outposts.pagination.count < 1) {
this.missingOutpost = true;
}
});
}
});
}
@property({ attribute: false })
application!: Application;
@state()
missingOutpost = false;
static get styles(): CSSResult[] {
return [PFBase, PFPage, PFContent, PFButton, PFDescriptionList, PFGrid, PFCard, AKGlobal];
return [
PFBase,
PFBanner,
PFPage,
PFContent,
PFButton,
PFDescriptionList,
PFGrid,
PFCard,
AKGlobal,
];
}
render(): TemplateResult {
@ -61,7 +93,12 @@ export class ApplicationViewPage extends LitElement {
if (!this.application) {
return html`<ak-empty-state ?loading="${true}" header=${t`Loading`}> </ak-empty-state>`;
}
return html` <ak-tabs>
return html`<ak-tabs>
${this.missingOutpost
? html`<div slot="header" class="pf-c-banner pf-m-warning">
${t`Warning: Application is not used by any Outpost.`}
</div>`
: html``}
<section
slot="page-overview"
data-tab-title="${t`Overview`}"
@ -88,6 +125,7 @@ export class ApplicationViewPage extends LitElement {
.providerObj?.pk}"
>
${this.application.providerObj?.name}
(${this.application.providerObj?.verboseName})
</a>
</div>
</dd>