web/admin: remove site-shell
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
ed17920bd4
commit
583b6cc20b
|
@ -11,16 +11,6 @@ from authentik.lib.utils.reflection import all_subclasses
|
||||||
from authentik.lib.views import CreateAssignPermView
|
from authentik.lib.views import CreateAssignPermView
|
||||||
|
|
||||||
|
|
||||||
class DeleteMessageView(SuccessMessageMixin, DeleteView):
|
|
||||||
"""DeleteView which shows `self.success_message` on successful deletion"""
|
|
||||||
|
|
||||||
success_url = reverse_lazy("authentik_core:if-admin")
|
|
||||||
|
|
||||||
def delete(self, request, *args, **kwargs):
|
|
||||||
messages.success(self.request, self.success_message)
|
|
||||||
return super().delete(request, *args, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
class InheritanceCreateView(CreateAssignPermView):
|
class InheritanceCreateView(CreateAssignPermView):
|
||||||
"""CreateView for objects using InheritanceManager"""
|
"""CreateView for objects using InheritanceManager"""
|
||||||
|
|
||||||
|
|
|
@ -1,173 +0,0 @@
|
||||||
import { css, CSSResult, customElement, html, LitElement, property, TemplateResult } from "lit-element";
|
|
||||||
import { SpinnerSize } from "../../elements/Spinner";
|
|
||||||
import { showMessage } from "../../elements/messages/MessageContainer";
|
|
||||||
import { gettext } from "django";
|
|
||||||
import { SentryIgnoredError } from "../../common/errors";
|
|
||||||
import { unsafeHTML } from "lit-html/directives/unsafe-html";
|
|
||||||
import PFBase from "@patternfly/patternfly/patternfly-base.css";
|
|
||||||
import PFButton from "@patternfly/patternfly/components/Button/button.css";
|
|
||||||
import PFModalBox from "@patternfly/patternfly/components/ModalBox/modal-box.css";
|
|
||||||
import PFForm from "@patternfly/patternfly/components/Form/form.css";
|
|
||||||
import PFFormControl from "@patternfly/patternfly/components/FormControl/form-control.css";
|
|
||||||
import PFBullseye from "@patternfly/patternfly/layouts/Bullseye/bullseye.css";
|
|
||||||
import PFBackdrop from "@patternfly/patternfly/components/Backdrop/backdrop.css";
|
|
||||||
import PFPage from "@patternfly/patternfly/components/Page/page.css";
|
|
||||||
import PFStack from "@patternfly/patternfly/layouts/Stack/stack.css";
|
|
||||||
import PFCard from "@patternfly/patternfly/components/Card/card.css";
|
|
||||||
import PFContent from "@patternfly/patternfly/components/Content/content.css";
|
|
||||||
import AKGlobal from "../../authentik.css";
|
|
||||||
import { EVENT_REFRESH } from "../../constants";
|
|
||||||
import { MessageLevel } from "../../elements/messages/Message";
|
|
||||||
|
|
||||||
@customElement("ak-site-shell")
|
|
||||||
export class SiteShell extends LitElement {
|
|
||||||
@property()
|
|
||||||
set url(value: string) {
|
|
||||||
this._url = value;
|
|
||||||
this.loadContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
_url?: string;
|
|
||||||
|
|
||||||
@property({type: Boolean})
|
|
||||||
loading = false;
|
|
||||||
|
|
||||||
@property({type: String})
|
|
||||||
body = "";
|
|
||||||
|
|
||||||
static get styles(): CSSResult[] {
|
|
||||||
return [PFBase, PFButton, PFModalBox, PFForm, PFFormControl, PFBullseye, PFBackdrop, PFPage, PFStack, PFCard, PFContent, AKGlobal].concat(
|
|
||||||
css`
|
|
||||||
:host,
|
|
||||||
::slotted(*) {
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
.pf-l-bullseye {
|
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
this.addEventListener(EVENT_REFRESH, () => {
|
|
||||||
this.loadContent();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
loadContent(): void {
|
|
||||||
const bodySlot = this.querySelector("[slot=body]");
|
|
||||||
if (!bodySlot) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!this._url) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (this.loading) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.loading = true;
|
|
||||||
fetch(this._url)
|
|
||||||
.then((response) => {
|
|
||||||
if (response.ok) {
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
console.debug(`authentik/site-shell: Request failed ${this._url}`);
|
|
||||||
showMessage({
|
|
||||||
level: MessageLevel.error,
|
|
||||||
message: gettext(`Request failed: ${response.statusText}`),
|
|
||||||
});
|
|
||||||
this.loading = false;
|
|
||||||
throw new SentryIgnoredError("Request failed");
|
|
||||||
})
|
|
||||||
.then((response) => response.text())
|
|
||||||
.then((text) => {
|
|
||||||
this.body = text;
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
setTimeout(() => {
|
|
||||||
this.loading = false;
|
|
||||||
}, 100);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
updateHandlers(): void {
|
|
||||||
// Ensure anchors only change the hash
|
|
||||||
this.shadowRoot?.querySelectorAll<HTMLAnchorElement>("a:not(.ak-root-link)").forEach((a) => {
|
|
||||||
if (a.href === "") {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (a.href.startsWith("#")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const url = new URL(a.href);
|
|
||||||
const qs = url.search || "";
|
|
||||||
const hash = (url.hash || "#").substring(2, Infinity);
|
|
||||||
a.href = `#${url.pathname}${qs}${hash}`;
|
|
||||||
} catch (e) {
|
|
||||||
console.debug(`authentik/site-shell: error ${e}`);
|
|
||||||
a.href = `#${a.href}`;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// Create refresh buttons
|
|
||||||
this.shadowRoot?.querySelectorAll("[role=ak-refresh]").forEach((rt) => {
|
|
||||||
rt.addEventListener("click", () => {
|
|
||||||
this.loadContent();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
// Make get forms (search bar) notify us on submit so we can change the hash
|
|
||||||
this.shadowRoot?.querySelectorAll<HTMLFormElement>("form[method=get]").forEach((form) => {
|
|
||||||
form.addEventListener("submit", (e) => {
|
|
||||||
e.preventDefault();
|
|
||||||
const formData = new FormData(form);
|
|
||||||
const qs = new URLSearchParams((<any>formData)).toString(); // eslint-disable-line
|
|
||||||
window.location.hash = `#${this._url}?${qs}`;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
// Make forms with POST Method have a correct action set
|
|
||||||
this.shadowRoot?.querySelectorAll<HTMLFormElement>("form[method=post]").forEach((form) => {
|
|
||||||
form.addEventListener("submit", (e) => {
|
|
||||||
e.preventDefault();
|
|
||||||
const formData = new FormData(form);
|
|
||||||
fetch(this._url ? this._url : form.action, {
|
|
||||||
method: form.method,
|
|
||||||
body: formData,
|
|
||||||
})
|
|
||||||
.then((response) => {
|
|
||||||
return response.text();
|
|
||||||
})
|
|
||||||
.then((data) => {
|
|
||||||
this.body = data;
|
|
||||||
this.updateHandlers();
|
|
||||||
})
|
|
||||||
.catch((e) => {
|
|
||||||
showMessage({
|
|
||||||
level: MessageLevel.error,
|
|
||||||
message: "Unexpected error"
|
|
||||||
});
|
|
||||||
console.error(e);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
render(): TemplateResult {
|
|
||||||
return html` ${this.loading ?
|
|
||||||
html`<div class="pf-l-bullseye">
|
|
||||||
<div class="pf-l-bullseye__item">
|
|
||||||
<ak-spinner size=${SpinnerSize.XLarge}></ak-spinner>
|
|
||||||
</div>
|
|
||||||
</div>`
|
|
||||||
: ""}
|
|
||||||
${unsafeHTML(this.body)}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
updated(): void {
|
|
||||||
this.updateHandlers();
|
|
||||||
}
|
|
||||||
}
|
|
Reference in a new issue