stages/identification: auto-redirect to source when no user fields are selected (#5583)

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens L
2023-05-11 16:52:30 +02:00
committed by GitHub
parent 7265a56f05
commit 61434c807d
8 changed files with 81 additions and 30 deletions

View File

@ -1,4 +1,4 @@
import { SeverityToLabel } from "@goauthentik/admin/events/RuleListPage";
import { SeverityToLabel } from "@goauthentik/admin/events/utils";
import { DEFAULT_CONFIG } from "@goauthentik/common/api/config";
import "@goauthentik/elements/forms/HorizontalFormElement";
import { ModelForm } from "@goauthentik/elements/forms/ModelForm";

View File

@ -1,4 +1,5 @@
import "@goauthentik/admin/events/RuleForm";
import { SeverityToLabel } from "@goauthentik/admin/events/utils";
import "@goauthentik/admin/policies/BoundPoliciesList";
import { DEFAULT_CONFIG } from "@goauthentik/common/api/config";
import { uiConfig } from "@goauthentik/common/ui/config";
@ -14,20 +15,7 @@ import { t } from "@lingui/macro";
import { TemplateResult, html } from "lit";
import { customElement, property } from "lit/decorators.js";
import { EventsApi, NotificationRule, SeverityEnum } from "@goauthentik/api";
export function SeverityToLabel(severity: SeverityEnum | null | undefined): string {
if (!severity) return t`Unknown severity`;
switch (severity) {
case SeverityEnum.Alert:
return t`Alert`;
case SeverityEnum.Notice:
return t`Notice`;
case SeverityEnum.Warning:
return t`Warning`;
}
return t`Unknown severity`;
}
import { EventsApi, NotificationRule } from "@goauthentik/api";
@customElement("ak-event-rule-list")
export class RuleListPage extends TablePage<NotificationRule> {

View File

@ -5,7 +5,7 @@ import { t } from "@lingui/macro";
import { TemplateResult, html } from "lit";
import { EventActions } from "@goauthentik/api";
import { EventActions, SeverityEnum } from "@goauthentik/api";
export function EventGeo(event: EventWithContext): TemplateResult {
let geo: KeyUnknown | undefined = undefined;
@ -78,3 +78,16 @@ export function ActionToLabel(action?: EventActions): string {
return action;
}
}
export function SeverityToLabel(severity: SeverityEnum | null | undefined): string {
if (!severity) return t`Unknown severity`;
switch (severity) {
case SeverityEnum.Alert:
return t`Alert`;
case SeverityEnum.Notice:
return t`Notice`;
case SeverityEnum.Warning:
return t`Warning`;
}
return t`Unknown severity`;
}

View File

@ -66,6 +66,23 @@ export class IdentificationStage extends BaseStage<
}
firstUpdated(): void {
this.autoRedirect();
this.createHelperForm();
}
autoRedirect(): void {
if (!this.challenge) return;
// we only want to auto-redirect to a source if there's only one source
if (this.challenge.sources?.length !== 1) return;
// and we also only do an auto-redirect if no user fields are select
// meaning that without the auto-redirect the user would only have the option
// to manually click on the source button
if ((this.challenge.userFields || []).length !== 0) return;
const source = this.challenge.sources[0];
this.host.challenge = source.challenge;
}
createHelperForm(): void {
this.form = document.createElement("form");
document.documentElement.appendChild(this.form);
// Only add the additional username input if we're in a shadow dom
@ -206,7 +223,6 @@ export class IdentificationStage extends BaseStage<
class="pf-c-form__group"
.errors=${(this.challenge.responseErrors || {})["uid_field"]}
>
<!-- @ts-ignore -->
<input
type=${type}
name="uidField"