import { t } from "@lingui/macro"; import { css, CSSResult, customElement, html, LitElement, property, TemplateResult } from "lit-element"; import { until } from "lit-html/directives/until"; import { FlowsApi } from "authentik-api"; import "../../elements/Spinner"; import "../../elements/Expand"; import { SpinnerSize } from "../../elements/Spinner"; import { EventContext, EventWithContext } from "../../api/Events"; import { DEFAULT_CONFIG } from "../../api/Config"; import PFDescriptionList from "@patternfly/patternfly/components/DescriptionList/description-list.css"; import PFFlex from "@patternfly/patternfly/layouts/Flex/flex.css"; import PFBase from "@patternfly/patternfly/patternfly-base.css"; import PFList from "@patternfly/patternfly/components/List/list.css"; @customElement("ak-event-info") export class EventInfo extends LitElement { @property({attribute: false}) event!: EventWithContext; static get styles(): CSSResult[] { return [PFBase, PFFlex, PFList, PFDescriptionList, css` code { display: block; white-space: pre-wrap; } .pf-l-flex { justify-content: space-between; } .pf-l-flex__item { min-width: 25%; } ` ]; } getModelInfo(context: EventContext): TemplateResult { if (context === null) { return html`-`; } return html`
${t`UID`}
${context.pk as string}
${t`Name`}
${context.name as string}
${t`App`}
${context.app as string}
${t`Model Name`}
${context.model_name as string}
`; } defaultResponse(): TemplateResult { return html`

${t`Context`}

${JSON.stringify(this.event?.context, null, 4)}

${t`User`}

${JSON.stringify(this.event?.user, null, 4)}
`; } render(): TemplateResult { if (!this.event) { return html``; } switch (this.event?.action) { case "model_created": case "model_updated": case "model_deleted": return html`

${t`Affected model:`}

${this.getModelInfo(this.event.context?.model as EventContext)} `; case "authorize_application": return html`

${t`Authorized application:`}

${this.getModelInfo(this.event.context.authorized_application as EventContext)}

${t`Using flow`}

${until(new FlowsApi(DEFAULT_CONFIG).flowsInstancesList({ flowUuid: this.event.context.flow as string, }).then(resp => { return html`${resp.results[0].name}`; }), html``)}
${this.defaultResponse()}`; case "login_failed": return html`

${t`Attempted to log in as ${this.event.context.username}`}

${this.defaultResponse()}`; case "secret_view": return html`

${t`Secret:`}

${this.getModelInfo(this.event.context.secret as EventContext)}`; case "property_mapping_exception": return html`

${t`Exception`}

${this.event.context.message || this.event.context.error}

${t`Expression`}

${this.event.context.expression}
${this.defaultResponse()}`; case "policy_exception": return html`

${t`Binding`}

${this.getModelInfo(this.event.context.binding as EventContext)}

${t`Request`}

${t`Exception`}

${this.event.context.message || this.event.context.error}
${this.defaultResponse()}`; case "policy_execution": return html`

${t`Binding`}

${this.getModelInfo(this.event.context.binding as EventContext)}

${t`Request`}

${t`Result`}

${this.defaultResponse()}`; case "configuration_error": return html`

${this.event.context.message}

${this.defaultResponse()}`; case "update_available": return html`

${t`New version available!`}

${this.event.context.new_version} `; // Action types which typically don't record any extra context. // If context is not empty, we fall to the default response. case "login": if ("using_source" in this.event.context) { return html`

${t`Using source`}

${this.getModelInfo(this.event.context.using_source as EventContext)}
`; } return this.defaultResponse(); case "logout": if (this.event.context === {}) { return html`${t`No additional data available.`}`; } return this.defaultResponse(); default: return this.defaultResponse(); } } }