From b181c551a57fe7f38a42c37159480c158e52bb9f Mon Sep 17 00:00:00 2001 From: Ken Sternberg <133134217+kensternberg-authentik@users.noreply.github.com> Date: Wed, 13 Dec 2023 07:13:28 -0800 Subject: [PATCH] web: expressing success (#7830) * web: expressing success Ever see an idiom that just, I dunno, *annoyed* you? Automated tools for the win. * web: repetition, repetition, repetition! [throws chair] * web: giving the de-duplication treatment to policy mappings. * Created a BaseStageForm with success message and canonical primary key type for for Providers, Sources, and Stages. --- web/src/admin/applications/ApplicationForm.ts | 8 +++----- web/src/admin/blueprints/BlueprintForm.ts | 8 +++----- web/src/admin/crypto/CertificateKeyPairForm.ts | 8 +++----- web/src/admin/events/RuleForm.ts | 8 +++----- web/src/admin/events/TransportForm.ts | 8 +++----- web/src/admin/flows/FlowForm.ts | 8 +++----- web/src/admin/groups/GroupForm.ts | 8 +++----- web/src/admin/outposts/OutpostForm.ts | 8 +++----- .../admin/outposts/ServiceConnectionDockerForm.ts | 8 +++----- .../outposts/ServiceConnectionKubernetesForm.ts | 8 +++----- web/src/admin/policies/BasePolicyForm.ts | 11 +++++++++++ web/src/admin/policies/dummy/DummyPolicyForm.ts | 12 ++---------- .../policies/event_matcher/EventMatcherPolicyForm.ts | 12 ++---------- web/src/admin/policies/expiry/ExpiryPolicyForm.ts | 12 ++---------- .../policies/expression/ExpressionPolicyForm.ts | 12 ++---------- .../admin/policies/password/PasswordPolicyForm.ts | 12 ++---------- .../policies/reputation/ReputationPolicyForm.ts | 12 ++---------- .../property-mappings/BasePropertyMappingForm.ts | 11 +++++++++++ .../property-mappings/PropertyMappingLDAPForm.ts | 12 ++---------- .../property-mappings/PropertyMappingNotification.ts | 8 +++----- .../property-mappings/PropertyMappingSAMLForm.ts | 12 ++---------- .../property-mappings/PropertyMappingSCIMForm.ts | 12 ++---------- .../property-mappings/PropertyMappingScopeForm.ts | 12 ++---------- web/src/admin/providers/BaseProviderForm.ts | 11 +++++++++++ web/src/admin/providers/ldap/LDAPProviderForm.ts | 12 ++---------- web/src/admin/providers/oauth2/OAuth2ProviderForm.ts | 12 ++---------- web/src/admin/providers/proxy/ProxyProviderForm.ts | 12 ++---------- web/src/admin/providers/radius/RadiusProviderForm.ts | 12 ++---------- web/src/admin/providers/saml/SAMLProviderForm.ts | 12 ++---------- web/src/admin/providers/scim/SCIMProviderForm.ts | 12 ++---------- web/src/admin/roles/RoleForm.ts | 8 +++----- web/src/admin/sources/BaseSourceForm.ts | 11 +++++++++++ web/src/admin/sources/ldap/LDAPSourceForm.ts | 12 ++---------- web/src/admin/sources/oauth/OAuthSourceForm.ts | 12 ++---------- web/src/admin/sources/plex/PlexSourceForm.ts | 12 ++---------- web/src/admin/sources/saml/SAMLSourceForm.ts | 12 ++---------- web/src/admin/stages/BaseStageForm.ts | 11 +++++++++++ .../authenticator_duo/AuthenticatorDuoStageForm.ts | 12 ++---------- .../authenticator_sms/AuthenticatorSMSStageForm.ts | 12 ++---------- .../AuthenticatorStaticStageForm.ts | 12 ++---------- .../authenticator_totp/AuthenticatorTOTPStageForm.ts | 12 ++---------- .../AuthenticatorValidateStageForm.ts | 12 ++---------- .../AuthenticateWebAuthnStageForm.ts | 12 ++---------- web/src/admin/stages/captcha/CaptchaStageForm.ts | 12 ++---------- web/src/admin/stages/consent/ConsentStageForm.ts | 12 ++---------- web/src/admin/stages/deny/DenyStageForm.ts | 12 ++---------- web/src/admin/stages/dummy/DummyStageForm.ts | 12 ++---------- web/src/admin/stages/email/EmailStageForm.ts | 12 ++---------- .../stages/identification/IdentificationStageForm.ts | 12 ++---------- web/src/admin/stages/invitation/InvitationForm.ts | 8 +++----- .../admin/stages/invitation/InvitationStageForm.ts | 12 ++---------- web/src/admin/stages/password/PasswordStageForm.ts | 12 ++---------- web/src/admin/stages/prompt/PromptForm.ts | 8 +++----- web/src/admin/stages/prompt/PromptStageForm.ts | 12 ++---------- .../admin/stages/user_delete/UserDeleteStageForm.ts | 12 ++---------- .../admin/stages/user_login/UserLoginStageForm.ts | 12 ++---------- .../admin/stages/user_logout/UserLogoutStageForm.ts | 12 ++---------- .../admin/stages/user_write/UserWriteStageForm.ts | 12 ++---------- web/src/admin/tenants/TenantForm.ts | 8 +++----- web/src/admin/tokens/TokenForm.ts | 8 +++----- web/src/user/user-settings/tokens/UserTokenForm.ts | 8 +++----- 61 files changed, 184 insertions(+), 475 deletions(-) create mode 100644 web/src/admin/policies/BasePolicyForm.ts create mode 100644 web/src/admin/property-mappings/BasePropertyMappingForm.ts create mode 100644 web/src/admin/providers/BaseProviderForm.ts create mode 100644 web/src/admin/sources/BaseSourceForm.ts create mode 100644 web/src/admin/stages/BaseStageForm.ts diff --git a/web/src/admin/applications/ApplicationForm.ts b/web/src/admin/applications/ApplicationForm.ts index 64ed05adb..970b3638e 100644 --- a/web/src/admin/applications/ApplicationForm.ts +++ b/web/src/admin/applications/ApplicationForm.ts @@ -75,11 +75,9 @@ export class ApplicationForm extends ModelForm { clearIcon = false; getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated application."); - } else { - return msg("Successfully created application."); - } + return this.instance + ? msg("Successfully updated application.") + : msg("Successfully created application."); } async send(data: Application): Promise { diff --git a/web/src/admin/blueprints/BlueprintForm.ts b/web/src/admin/blueprints/BlueprintForm.ts index 47b6c492c..2df50180b 100644 --- a/web/src/admin/blueprints/BlueprintForm.ts +++ b/web/src/admin/blueprints/BlueprintForm.ts @@ -44,11 +44,9 @@ export class BlueprintForm extends ModelForm { } getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated instance."); - } else { - return msg("Successfully created instance."); - } + return this.instance + ? msg("Successfully updated instance.") + : msg("Successfully created instance."); } static get styles(): CSSResult[] { diff --git a/web/src/admin/crypto/CertificateKeyPairForm.ts b/web/src/admin/crypto/CertificateKeyPairForm.ts index 46e7cd4c9..6f194d436 100644 --- a/web/src/admin/crypto/CertificateKeyPairForm.ts +++ b/web/src/admin/crypto/CertificateKeyPairForm.ts @@ -19,11 +19,9 @@ export class CertificateKeyPairForm extends ModelForm { diff --git a/web/src/admin/events/RuleForm.ts b/web/src/admin/events/RuleForm.ts index 43e54ab89..ed392a1ca 100644 --- a/web/src/admin/events/RuleForm.ts +++ b/web/src/admin/events/RuleForm.ts @@ -37,11 +37,9 @@ export class RuleForm extends ModelForm { } getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated rule."); - } else { - return msg("Successfully created rule."); - } + return this.instance + ? msg("Successfully updated rule.") + : msg("Successfully created rule."); } async send(data: NotificationRule): Promise { diff --git a/web/src/admin/events/TransportForm.ts b/web/src/admin/events/TransportForm.ts index 1554d7007..593477c60 100644 --- a/web/src/admin/events/TransportForm.ts +++ b/web/src/admin/events/TransportForm.ts @@ -36,11 +36,9 @@ export class TransportForm extends ModelForm { showWebhook = false; getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated transport."); - } else { - return msg("Successfully created transport."); - } + return this.instance + ? msg("Successfully updated transport.") + : msg("Successfully created transport."); } async send(data: NotificationTransport): Promise { diff --git a/web/src/admin/flows/FlowForm.ts b/web/src/admin/flows/FlowForm.ts index a78c0f4fa..eb37aa4ca 100644 --- a/web/src/admin/flows/FlowForm.ts +++ b/web/src/admin/flows/FlowForm.ts @@ -34,11 +34,9 @@ export class FlowForm extends ModelForm { } getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated flow."); - } else { - return msg("Successfully created flow."); - } + return this.instance + ? msg("Successfully updated flow.") + : msg("Successfully created flow."); } @property({ type: Boolean }) diff --git a/web/src/admin/groups/GroupForm.ts b/web/src/admin/groups/GroupForm.ts index 1d703133e..b55cafb56 100644 --- a/web/src/admin/groups/GroupForm.ts +++ b/web/src/admin/groups/GroupForm.ts @@ -46,11 +46,9 @@ export class GroupForm extends ModelForm { } getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated group."); - } else { - return msg("Successfully created group."); - } + return this.instance + ? msg("Successfully updated group.") + : msg("Successfully created group."); } async load(): Promise { diff --git a/web/src/admin/outposts/OutpostForm.ts b/web/src/admin/outposts/OutpostForm.ts index 65fd60845..1952cfe85 100644 --- a/web/src/admin/outposts/OutpostForm.ts +++ b/web/src/admin/outposts/OutpostForm.ts @@ -79,11 +79,9 @@ export class OutpostForm extends ModelForm { } getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated outpost."); - } else { - return msg("Successfully created outpost."); - } + return this.instance + ? msg("Successfully updated outpost.") + : msg("Successfully created outpost."); } async send(data: Outpost): Promise { diff --git a/web/src/admin/outposts/ServiceConnectionDockerForm.ts b/web/src/admin/outposts/ServiceConnectionDockerForm.ts index ca15d552c..10dc8894b 100644 --- a/web/src/admin/outposts/ServiceConnectionDockerForm.ts +++ b/web/src/admin/outposts/ServiceConnectionDockerForm.ts @@ -21,11 +21,9 @@ export class ServiceConnectionDockerForm extends ModelForm { diff --git a/web/src/admin/outposts/ServiceConnectionKubernetesForm.ts b/web/src/admin/outposts/ServiceConnectionKubernetesForm.ts index f087998cc..414bb8922 100644 --- a/web/src/admin/outposts/ServiceConnectionKubernetesForm.ts +++ b/web/src/admin/outposts/ServiceConnectionKubernetesForm.ts @@ -25,11 +25,9 @@ export class ServiceConnectionKubernetesForm extends ModelForm< } getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated integration."); - } else { - return msg("Successfully created integration."); - } + return this.instance + ? msg("Successfully updated integration.") + : msg("Successfully created integration."); } async send(data: KubernetesServiceConnection): Promise { diff --git a/web/src/admin/policies/BasePolicyForm.ts b/web/src/admin/policies/BasePolicyForm.ts new file mode 100644 index 000000000..450a653a6 --- /dev/null +++ b/web/src/admin/policies/BasePolicyForm.ts @@ -0,0 +1,11 @@ +import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; + +import { msg } from "@lit/localize"; + +export abstract class BasePolicyForm extends ModelForm { + getSuccessMessage(): string { + return this.instance + ? msg("Successfully updated policy.") + : msg("Successfully created policy."); + } +} diff --git a/web/src/admin/policies/dummy/DummyPolicyForm.ts b/web/src/admin/policies/dummy/DummyPolicyForm.ts index 7dcb82ec2..57fe5812d 100644 --- a/web/src/admin/policies/dummy/DummyPolicyForm.ts +++ b/web/src/admin/policies/dummy/DummyPolicyForm.ts @@ -1,8 +1,8 @@ +import { BasePolicyForm } from "@goauthentik/admin/policies/BasePolicyForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { first } from "@goauthentik/common/utils"; import "@goauthentik/elements/forms/FormGroup"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import { msg } from "@lit/localize"; import { TemplateResult, html } from "lit"; @@ -12,21 +12,13 @@ import { ifDefined } from "lit/directives/if-defined.js"; import { DummyPolicy, PoliciesApi } from "@goauthentik/api"; @customElement("ak-policy-dummy-form") -export class DummyPolicyForm extends ModelForm { +export class DummyPolicyForm extends BasePolicyForm { loadInstance(pk: string): Promise { return new PoliciesApi(DEFAULT_CONFIG).policiesDummyRetrieve({ policyUuid: pk, }); } - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated policy."); - } else { - return msg("Successfully created policy."); - } - } - async send(data: DummyPolicy): Promise { if (this.instance) { return new PoliciesApi(DEFAULT_CONFIG).policiesDummyUpdate({ diff --git a/web/src/admin/policies/event_matcher/EventMatcherPolicyForm.ts b/web/src/admin/policies/event_matcher/EventMatcherPolicyForm.ts index a8198d8f6..b6d3e00d1 100644 --- a/web/src/admin/policies/event_matcher/EventMatcherPolicyForm.ts +++ b/web/src/admin/policies/event_matcher/EventMatcherPolicyForm.ts @@ -1,8 +1,8 @@ +import { BasePolicyForm } from "@goauthentik/admin/policies/BasePolicyForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { first } from "@goauthentik/common/utils"; import "@goauthentik/elements/forms/FormGroup"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import "@goauthentik/elements/forms/SearchSelect"; import { msg } from "@lit/localize"; @@ -20,21 +20,13 @@ import { } from "@goauthentik/api"; @customElement("ak-policy-event-matcher-form") -export class EventMatcherPolicyForm extends ModelForm { +export class EventMatcherPolicyForm extends BasePolicyForm { loadInstance(pk: string): Promise { return new PoliciesApi(DEFAULT_CONFIG).policiesEventMatcherRetrieve({ policyUuid: pk, }); } - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated policy."); - } else { - return msg("Successfully created policy."); - } - } - async send(data: EventMatcherPolicy): Promise { if (data.action?.toString() === "") data.action = null; if (data.clientIp?.toString() === "") data.clientIp = null; diff --git a/web/src/admin/policies/expiry/ExpiryPolicyForm.ts b/web/src/admin/policies/expiry/ExpiryPolicyForm.ts index 0ec7caae3..c22311571 100644 --- a/web/src/admin/policies/expiry/ExpiryPolicyForm.ts +++ b/web/src/admin/policies/expiry/ExpiryPolicyForm.ts @@ -1,8 +1,8 @@ +import { BasePolicyForm } from "@goauthentik/admin/policies/BasePolicyForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { first } from "@goauthentik/common/utils"; import "@goauthentik/elements/forms/FormGroup"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import { msg } from "@lit/localize"; import { TemplateResult, html } from "lit"; @@ -12,21 +12,13 @@ import { ifDefined } from "lit/directives/if-defined.js"; import { PasswordExpiryPolicy, PoliciesApi } from "@goauthentik/api"; @customElement("ak-policy-password-expiry-form") -export class PasswordExpiryPolicyForm extends ModelForm { +export class PasswordExpiryPolicyForm extends BasePolicyForm { loadInstance(pk: string): Promise { return new PoliciesApi(DEFAULT_CONFIG).policiesPasswordExpiryRetrieve({ policyUuid: pk, }); } - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated policy."); - } else { - return msg("Successfully created policy."); - } - } - async send(data: PasswordExpiryPolicy): Promise { if (this.instance) { return new PoliciesApi(DEFAULT_CONFIG).policiesPasswordExpiryUpdate({ diff --git a/web/src/admin/policies/expression/ExpressionPolicyForm.ts b/web/src/admin/policies/expression/ExpressionPolicyForm.ts index a00c6584d..01c603914 100644 --- a/web/src/admin/policies/expression/ExpressionPolicyForm.ts +++ b/web/src/admin/policies/expression/ExpressionPolicyForm.ts @@ -1,3 +1,4 @@ +import { BasePolicyForm } from "@goauthentik/admin/policies/BasePolicyForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { docLink } from "@goauthentik/common/global"; import { first } from "@goauthentik/common/utils"; @@ -5,7 +6,6 @@ import "@goauthentik/elements/CodeMirror"; import { CodeMirrorMode } from "@goauthentik/elements/CodeMirror"; import "@goauthentik/elements/forms/FormGroup"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import { msg } from "@lit/localize"; import { TemplateResult, html } from "lit"; @@ -15,21 +15,13 @@ import { ifDefined } from "lit/directives/if-defined.js"; import { ExpressionPolicy, PoliciesApi } from "@goauthentik/api"; @customElement("ak-policy-expression-form") -export class ExpressionPolicyForm extends ModelForm { +export class ExpressionPolicyForm extends BasePolicyForm { loadInstance(pk: string): Promise { return new PoliciesApi(DEFAULT_CONFIG).policiesExpressionRetrieve({ policyUuid: pk, }); } - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated policy."); - } else { - return msg("Successfully created policy."); - } - } - async send(data: ExpressionPolicy): Promise { if (this.instance) { return new PoliciesApi(DEFAULT_CONFIG).policiesExpressionUpdate({ diff --git a/web/src/admin/policies/password/PasswordPolicyForm.ts b/web/src/admin/policies/password/PasswordPolicyForm.ts index 96183b077..08674effa 100644 --- a/web/src/admin/policies/password/PasswordPolicyForm.ts +++ b/web/src/admin/policies/password/PasswordPolicyForm.ts @@ -1,8 +1,8 @@ +import { BasePolicyForm } from "@goauthentik/admin/policies/BasePolicyForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { first } from "@goauthentik/common/utils"; import "@goauthentik/elements/forms/FormGroup"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import { msg } from "@lit/localize"; import { TemplateResult, html } from "lit"; @@ -12,7 +12,7 @@ import { ifDefined } from "lit/directives/if-defined.js"; import { PasswordPolicy, PoliciesApi } from "@goauthentik/api"; @customElement("ak-policy-password-form") -export class PasswordPolicyForm extends ModelForm { +export class PasswordPolicyForm extends BasePolicyForm { @state() showStatic = true; @@ -32,14 +32,6 @@ export class PasswordPolicyForm extends ModelForm { return policy; } - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated policy."); - } else { - return msg("Successfully created policy."); - } - } - async send(data: PasswordPolicy): Promise { if (this.instance) { return new PoliciesApi(DEFAULT_CONFIG).policiesPasswordUpdate({ diff --git a/web/src/admin/policies/reputation/ReputationPolicyForm.ts b/web/src/admin/policies/reputation/ReputationPolicyForm.ts index a32d6febf..d5f12ba1c 100644 --- a/web/src/admin/policies/reputation/ReputationPolicyForm.ts +++ b/web/src/admin/policies/reputation/ReputationPolicyForm.ts @@ -1,8 +1,8 @@ +import { BasePolicyForm } from "@goauthentik/admin/policies/BasePolicyForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { first } from "@goauthentik/common/utils"; import "@goauthentik/elements/forms/FormGroup"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import { msg } from "@lit/localize"; import { TemplateResult, html } from "lit"; @@ -12,21 +12,13 @@ import { ifDefined } from "lit/directives/if-defined.js"; import { PoliciesApi, ReputationPolicy } from "@goauthentik/api"; @customElement("ak-policy-reputation-form") -export class ReputationPolicyForm extends ModelForm { +export class ReputationPolicyForm extends BasePolicyForm { loadInstance(pk: string): Promise { return new PoliciesApi(DEFAULT_CONFIG).policiesReputationRetrieve({ policyUuid: pk, }); } - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated policy."); - } else { - return msg("Successfully created policy."); - } - } - async send(data: ReputationPolicy): Promise { if (this.instance) { return new PoliciesApi(DEFAULT_CONFIG).policiesReputationUpdate({ diff --git a/web/src/admin/property-mappings/BasePropertyMappingForm.ts b/web/src/admin/property-mappings/BasePropertyMappingForm.ts new file mode 100644 index 000000000..82981b9cf --- /dev/null +++ b/web/src/admin/property-mappings/BasePropertyMappingForm.ts @@ -0,0 +1,11 @@ +import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; + +import { msg } from "@lit/localize"; + +export abstract class BasePropertyMappingForm extends ModelForm { + getSuccessMessage(): string { + return this.instance + ? msg("Successfully updated mapping.") + : msg("Successfully created mapping."); + } +} diff --git a/web/src/admin/property-mappings/PropertyMappingLDAPForm.ts b/web/src/admin/property-mappings/PropertyMappingLDAPForm.ts index 6919ab079..0b5afe81b 100644 --- a/web/src/admin/property-mappings/PropertyMappingLDAPForm.ts +++ b/web/src/admin/property-mappings/PropertyMappingLDAPForm.ts @@ -1,9 +1,9 @@ +import { BasePropertyMappingForm } from "@goauthentik/admin/property-mappings/BasePropertyMappingForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { docLink } from "@goauthentik/common/global"; import "@goauthentik/elements/CodeMirror"; import { CodeMirrorMode } from "@goauthentik/elements/CodeMirror"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import { msg } from "@lit/localize"; import { TemplateResult, html } from "lit"; @@ -13,21 +13,13 @@ import { ifDefined } from "lit/directives/if-defined.js"; import { LDAPPropertyMapping, PropertymappingsApi } from "@goauthentik/api"; @customElement("ak-property-mapping-ldap-form") -export class PropertyMappingLDAPForm extends ModelForm { +export class PropertyMappingLDAPForm extends BasePropertyMappingForm { loadInstance(pk: string): Promise { return new PropertymappingsApi(DEFAULT_CONFIG).propertymappingsLdapRetrieve({ pmUuid: pk, }); } - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated mapping."); - } else { - return msg("Successfully created mapping."); - } - } - async send(data: LDAPPropertyMapping): Promise { if (this.instance) { return new PropertymappingsApi(DEFAULT_CONFIG).propertymappingsLdapUpdate({ diff --git a/web/src/admin/property-mappings/PropertyMappingNotification.ts b/web/src/admin/property-mappings/PropertyMappingNotification.ts index 8ab561dec..9991d2a32 100644 --- a/web/src/admin/property-mappings/PropertyMappingNotification.ts +++ b/web/src/admin/property-mappings/PropertyMappingNotification.ts @@ -21,11 +21,9 @@ export class PropertyMappingNotification extends ModelForm { diff --git a/web/src/admin/property-mappings/PropertyMappingSAMLForm.ts b/web/src/admin/property-mappings/PropertyMappingSAMLForm.ts index 77836c505..101455c84 100644 --- a/web/src/admin/property-mappings/PropertyMappingSAMLForm.ts +++ b/web/src/admin/property-mappings/PropertyMappingSAMLForm.ts @@ -1,9 +1,9 @@ +import { BasePropertyMappingForm } from "@goauthentik/admin/property-mappings/BasePropertyMappingForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { docLink } from "@goauthentik/common/global"; import "@goauthentik/elements/CodeMirror"; import { CodeMirrorMode } from "@goauthentik/elements/CodeMirror"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import { msg } from "@lit/localize"; import { TemplateResult, html } from "lit"; @@ -13,21 +13,13 @@ import { ifDefined } from "lit/directives/if-defined.js"; import { PropertymappingsApi, SAMLPropertyMapping } from "@goauthentik/api"; @customElement("ak-property-mapping-saml-form") -export class PropertyMappingSAMLForm extends ModelForm { +export class PropertyMappingSAMLForm extends BasePropertyMappingForm { loadInstance(pk: string): Promise { return new PropertymappingsApi(DEFAULT_CONFIG).propertymappingsSamlRetrieve({ pmUuid: pk, }); } - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated mapping."); - } else { - return msg("Successfully created mapping."); - } - } - async send(data: SAMLPropertyMapping): Promise { if (this.instance) { return new PropertymappingsApi(DEFAULT_CONFIG).propertymappingsSamlUpdate({ diff --git a/web/src/admin/property-mappings/PropertyMappingSCIMForm.ts b/web/src/admin/property-mappings/PropertyMappingSCIMForm.ts index 19bd13aab..30993cbbd 100644 --- a/web/src/admin/property-mappings/PropertyMappingSCIMForm.ts +++ b/web/src/admin/property-mappings/PropertyMappingSCIMForm.ts @@ -1,9 +1,9 @@ +import { BasePropertyMappingForm } from "@goauthentik/admin/property-mappings/BasePropertyMappingForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { docLink } from "@goauthentik/common/global"; import "@goauthentik/elements/CodeMirror"; import { CodeMirrorMode } from "@goauthentik/elements/CodeMirror"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import { msg } from "@lit/localize"; import { TemplateResult, html } from "lit"; @@ -13,21 +13,13 @@ import { ifDefined } from "lit/directives/if-defined.js"; import { PropertymappingsApi, SCIMMapping } from "@goauthentik/api"; @customElement("ak-property-mapping-scim-form") -export class PropertyMappingSCIMForm extends ModelForm { +export class PropertyMappingSCIMForm extends BasePropertyMappingForm { loadInstance(pk: string): Promise { return new PropertymappingsApi(DEFAULT_CONFIG).propertymappingsScimRetrieve({ pmUuid: pk, }); } - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated mapping."); - } else { - return msg("Successfully created mapping."); - } - } - async send(data: SCIMMapping): Promise { if (this.instance) { return new PropertymappingsApi(DEFAULT_CONFIG).propertymappingsScimUpdate({ diff --git a/web/src/admin/property-mappings/PropertyMappingScopeForm.ts b/web/src/admin/property-mappings/PropertyMappingScopeForm.ts index caf2dc11d..3df60889f 100644 --- a/web/src/admin/property-mappings/PropertyMappingScopeForm.ts +++ b/web/src/admin/property-mappings/PropertyMappingScopeForm.ts @@ -1,9 +1,9 @@ +import { BasePropertyMappingForm } from "@goauthentik/admin/property-mappings/BasePropertyMappingForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { docLink } from "@goauthentik/common/global"; import "@goauthentik/elements/CodeMirror"; import { CodeMirrorMode } from "@goauthentik/elements/CodeMirror"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import { msg } from "@lit/localize"; import { TemplateResult, html } from "lit"; @@ -13,21 +13,13 @@ import { ifDefined } from "lit/directives/if-defined.js"; import { PropertymappingsApi, ScopeMapping } from "@goauthentik/api"; @customElement("ak-property-mapping-scope-form") -export class PropertyMappingScopeForm extends ModelForm { +export class PropertyMappingScopeForm extends BasePropertyMappingForm { loadInstance(pk: string): Promise { return new PropertymappingsApi(DEFAULT_CONFIG).propertymappingsScopeRetrieve({ pmUuid: pk, }); } - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated mapping."); - } else { - return msg("Successfully created mapping."); - } - } - async send(data: ScopeMapping): Promise { if (this.instance) { return new PropertymappingsApi(DEFAULT_CONFIG).propertymappingsScopeUpdate({ diff --git a/web/src/admin/providers/BaseProviderForm.ts b/web/src/admin/providers/BaseProviderForm.ts new file mode 100644 index 000000000..3f6134046 --- /dev/null +++ b/web/src/admin/providers/BaseProviderForm.ts @@ -0,0 +1,11 @@ +import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; + +import { msg } from "@lit/localize"; + +export abstract class BaseProviderForm extends ModelForm { + getSuccessMessage(): string { + return this.instance + ? msg("Successfully updated provider.") + : msg("Successfully created provider."); + } +} diff --git a/web/src/admin/providers/ldap/LDAPProviderForm.ts b/web/src/admin/providers/ldap/LDAPProviderForm.ts index 7a6a2eb81..449a3ad5b 100644 --- a/web/src/admin/providers/ldap/LDAPProviderForm.ts +++ b/web/src/admin/providers/ldap/LDAPProviderForm.ts @@ -1,11 +1,11 @@ import "@goauthentik/admin/common/ak-crypto-certificate-search"; import "@goauthentik/admin/common/ak-flow-search/ak-tenanted-flow-search"; +import { BaseProviderForm } from "@goauthentik/admin/providers/BaseProviderForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { first } from "@goauthentik/common/utils"; import { rootInterface } from "@goauthentik/elements/Base"; import "@goauthentik/elements/forms/FormGroup"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import "@goauthentik/elements/forms/Radio"; import "@goauthentik/elements/forms/SearchSelect"; @@ -25,21 +25,13 @@ import { } from "@goauthentik/api"; @customElement("ak-provider-ldap-form") -export class LDAPProviderFormPage extends ModelForm { +export class LDAPProviderFormPage extends BaseProviderForm { async loadInstance(pk: number): Promise { return new ProvidersApi(DEFAULT_CONFIG).providersLdapRetrieve({ id: pk, }); } - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated provider."); - } else { - return msg("Successfully created provider."); - } - } - async send(data: LDAPProvider): Promise { if (this.instance) { return new ProvidersApi(DEFAULT_CONFIG).providersLdapUpdate({ diff --git a/web/src/admin/providers/oauth2/OAuth2ProviderForm.ts b/web/src/admin/providers/oauth2/OAuth2ProviderForm.ts index f5b59efe5..000df8cad 100644 --- a/web/src/admin/providers/oauth2/OAuth2ProviderForm.ts +++ b/web/src/admin/providers/oauth2/OAuth2ProviderForm.ts @@ -1,5 +1,6 @@ import "@goauthentik/admin/common/ak-crypto-certificate-search"; import "@goauthentik/admin/common/ak-flow-search/ak-flow-search"; +import { BaseProviderForm } from "@goauthentik/admin/providers/BaseProviderForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { ascii_letters, digits, first, randomString } from "@goauthentik/common/utils"; import "@goauthentik/components/ak-radio-input"; @@ -7,7 +8,6 @@ import "@goauthentik/components/ak-text-input"; import "@goauthentik/components/ak-textarea-input"; import "@goauthentik/elements/forms/FormGroup"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import "@goauthentik/elements/forms/Radio"; import "@goauthentik/elements/forms/SearchSelect"; import "@goauthentik/elements/utils/TimeDeltaHelp"; @@ -116,7 +116,7 @@ export const redirectUriHelp = html`${redirectUriHelpMessages.map( */ @customElement("ak-provider-oauth2-form") -export class OAuth2ProviderFormPage extends ModelForm { +export class OAuth2ProviderFormPage extends BaseProviderForm { propertyMappings?: PaginatedScopeMappingList; oauthSources?: PaginatedOAuthSourceList; @@ -143,14 +143,6 @@ export class OAuth2ProviderFormPage extends ModelForm { }); } - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated provider."); - } else { - return msg("Successfully created provider."); - } - } - async send(data: OAuth2Provider): Promise { if (this.instance) { return new ProvidersApi(DEFAULT_CONFIG).providersOauth2Update({ diff --git a/web/src/admin/providers/proxy/ProxyProviderForm.ts b/web/src/admin/providers/proxy/ProxyProviderForm.ts index 5f8e79c56..ddd554572 100644 --- a/web/src/admin/providers/proxy/ProxyProviderForm.ts +++ b/web/src/admin/providers/proxy/ProxyProviderForm.ts @@ -1,11 +1,11 @@ import "@goauthentik/admin/common/ak-crypto-certificate-search"; import "@goauthentik/admin/common/ak-flow-search/ak-flow-search"; +import { BaseProviderForm } from "@goauthentik/admin/providers/BaseProviderForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { first } from "@goauthentik/common/utils"; import "@goauthentik/components/ak-toggle-group"; import "@goauthentik/elements/forms/FormGroup"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import "@goauthentik/elements/forms/SearchSelect"; import "@goauthentik/elements/utils/TimeDeltaHelp"; @@ -30,7 +30,7 @@ import { } from "@goauthentik/api"; @customElement("ak-provider-proxy-form") -export class ProxyProviderFormPage extends ModelForm { +export class ProxyProviderFormPage extends BaseProviderForm { static get styles(): CSSResult[] { return [...super.styles, PFContent, PFList, PFSpacing]; } @@ -65,14 +65,6 @@ export class ProxyProviderFormPage extends ModelForm { @state() mode: ProxyMode = ProxyMode.Proxy; - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated provider."); - } else { - return msg("Successfully created provider."); - } - } - async send(data: ProxyProvider): Promise { data.mode = this.mode; if (this.mode !== ProxyMode.ForwardDomain) { diff --git a/web/src/admin/providers/radius/RadiusProviderForm.ts b/web/src/admin/providers/radius/RadiusProviderForm.ts index 3898ba048..269a5ee95 100644 --- a/web/src/admin/providers/radius/RadiusProviderForm.ts +++ b/web/src/admin/providers/radius/RadiusProviderForm.ts @@ -1,9 +1,9 @@ +import { BaseProviderForm } from "@goauthentik/admin/providers/BaseProviderForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { ascii_letters, digits, first, randomString } from "@goauthentik/common/utils"; import { rootInterface } from "@goauthentik/elements/Base"; import "@goauthentik/elements/forms/FormGroup"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import "@goauthentik/elements/forms/SearchSelect"; import { msg } from "@lit/localize"; @@ -14,21 +14,13 @@ import { customElement } from "lit/decorators.js"; import { FlowsInstancesListDesignationEnum, ProvidersApi, RadiusProvider } from "@goauthentik/api"; @customElement("ak-provider-radius-form") -export class RadiusProviderFormPage extends ModelForm { +export class RadiusProviderFormPage extends BaseProviderForm { loadInstance(pk: number): Promise { return new ProvidersApi(DEFAULT_CONFIG).providersRadiusRetrieve({ id: pk, }); } - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated provider."); - } else { - return msg("Successfully created provider."); - } - } - async send(data: RadiusProvider): Promise { if (this.instance) { return new ProvidersApi(DEFAULT_CONFIG).providersRadiusUpdate({ diff --git a/web/src/admin/providers/saml/SAMLProviderForm.ts b/web/src/admin/providers/saml/SAMLProviderForm.ts index 181a0c831..006a32545 100644 --- a/web/src/admin/providers/saml/SAMLProviderForm.ts +++ b/web/src/admin/providers/saml/SAMLProviderForm.ts @@ -1,9 +1,9 @@ import "@goauthentik/admin/common/ak-crypto-certificate-search"; import "@goauthentik/admin/common/ak-flow-search/ak-flow-search"; +import { BaseProviderForm } from "@goauthentik/admin/providers/BaseProviderForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import "@goauthentik/elements/forms/FormGroup"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import "@goauthentik/elements/forms/Radio"; import "@goauthentik/elements/forms/SearchSelect"; import "@goauthentik/elements/utils/TimeDeltaHelp"; @@ -27,7 +27,7 @@ import { } from "@goauthentik/api"; @customElement("ak-provider-saml-form") -export class SAMLProviderFormPage extends ModelForm { +export class SAMLProviderFormPage extends BaseProviderForm { loadInstance(pk: number): Promise { return new ProvidersApi(DEFAULT_CONFIG).providersSamlRetrieve({ id: pk, @@ -44,14 +44,6 @@ export class SAMLProviderFormPage extends ModelForm { propertyMappings?: PaginatedSAMLPropertyMappingList; - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated provider."); - } else { - return msg("Successfully created provider."); - } - } - async send(data: SAMLProvider): Promise { if (this.instance) { return new ProvidersApi(DEFAULT_CONFIG).providersSamlUpdate({ diff --git a/web/src/admin/providers/scim/SCIMProviderForm.ts b/web/src/admin/providers/scim/SCIMProviderForm.ts index cdc935973..e505c4b23 100644 --- a/web/src/admin/providers/scim/SCIMProviderForm.ts +++ b/web/src/admin/providers/scim/SCIMProviderForm.ts @@ -1,8 +1,8 @@ +import { BaseProviderForm } from "@goauthentik/admin/providers/BaseProviderForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { first } from "@goauthentik/common/utils"; import "@goauthentik/elements/forms/FormGroup"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import "@goauthentik/elements/forms/Radio"; import "@goauthentik/elements/forms/SearchSelect"; @@ -22,7 +22,7 @@ import { } from "@goauthentik/api"; @customElement("ak-provider-scim-form") -export class SCIMProviderFormPage extends ModelForm { +export class SCIMProviderFormPage extends BaseProviderForm { loadInstance(pk: number): Promise { return new ProvidersApi(DEFAULT_CONFIG).providersScimRetrieve({ id: pk, @@ -39,14 +39,6 @@ export class SCIMProviderFormPage extends ModelForm { propertyMappings?: PaginatedSCIMMappingList; - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated provider."); - } else { - return msg("Successfully created provider."); - } - } - async send(data: SCIMProvider): Promise { if (this.instance) { return new ProvidersApi(DEFAULT_CONFIG).providersScimUpdate({ diff --git a/web/src/admin/roles/RoleForm.ts b/web/src/admin/roles/RoleForm.ts index 7d4778469..e5cc0e8f3 100644 --- a/web/src/admin/roles/RoleForm.ts +++ b/web/src/admin/roles/RoleForm.ts @@ -21,11 +21,9 @@ export class RoleForm extends ModelForm { } getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated role."); - } else { - return msg("Successfully created role."); - } + return this.instance + ? msg("Successfully updated role.") + : msg("Successfully created role."); } async send(data: Role): Promise { diff --git a/web/src/admin/sources/BaseSourceForm.ts b/web/src/admin/sources/BaseSourceForm.ts new file mode 100644 index 000000000..f8c68c4bd --- /dev/null +++ b/web/src/admin/sources/BaseSourceForm.ts @@ -0,0 +1,11 @@ +import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; + +import { msg } from "@lit/localize"; + +export abstract class BaseSourceForm extends ModelForm { + getSuccessMessage(): string { + return this.instance + ? msg("Successfully updated source.") + : msg("Successfully created source."); + } +} diff --git a/web/src/admin/sources/ldap/LDAPSourceForm.ts b/web/src/admin/sources/ldap/LDAPSourceForm.ts index 188f177fe..39a121cb9 100644 --- a/web/src/admin/sources/ldap/LDAPSourceForm.ts +++ b/web/src/admin/sources/ldap/LDAPSourceForm.ts @@ -1,10 +1,10 @@ import "@goauthentik/admin/common/ak-crypto-certificate-search"; import { placeholderHelperText } from "@goauthentik/admin/helperText"; +import { BaseSourceForm } from "@goauthentik/admin/sources/BaseSourceForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { first } from "@goauthentik/common/utils"; import "@goauthentik/elements/forms/FormGroup"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import "@goauthentik/elements/forms/SearchSelect"; import { msg } from "@lit/localize"; @@ -24,7 +24,7 @@ import { } from "@goauthentik/api"; @customElement("ak-source-ldap-form") -export class LDAPSourceForm extends ModelForm { +export class LDAPSourceForm extends BaseSourceForm { loadInstance(pk: string): Promise { return new SourcesApi(DEFAULT_CONFIG).sourcesLdapRetrieve({ slug: pk, @@ -41,14 +41,6 @@ export class LDAPSourceForm extends ModelForm { propertyMappings?: PaginatedLDAPPropertyMappingList; - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated source."); - } else { - return msg("Successfully created source."); - } - } - async send(data: LDAPSource): Promise { if (this.instance) { return new SourcesApi(DEFAULT_CONFIG).sourcesLdapPartialUpdate({ diff --git a/web/src/admin/sources/oauth/OAuthSourceForm.ts b/web/src/admin/sources/oauth/OAuthSourceForm.ts index 51b1c6e42..cf0209fcb 100644 --- a/web/src/admin/sources/oauth/OAuthSourceForm.ts +++ b/web/src/admin/sources/oauth/OAuthSourceForm.ts @@ -1,5 +1,6 @@ import "@goauthentik/admin/common/ak-flow-search/ak-source-flow-search"; import { iconHelperText, placeholderHelperText } from "@goauthentik/admin/helperText"; +import { BaseSourceForm } from "@goauthentik/admin/sources/BaseSourceForm"; import { UserMatchingModeToLabel } from "@goauthentik/admin/sources/oauth/utils"; import { DEFAULT_CONFIG, config } from "@goauthentik/common/api/config"; import { first } from "@goauthentik/common/utils"; @@ -8,7 +9,6 @@ import "@goauthentik/elements/CodeMirror"; import { CodeMirrorMode } from "@goauthentik/elements/CodeMirror"; import "@goauthentik/elements/forms/FormGroup"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import "@goauthentik/elements/forms/SearchSelect"; import { msg } from "@lit/localize"; @@ -28,7 +28,7 @@ import { } from "@goauthentik/api"; @customElement("ak-source-oauth-form") -export class OAuthSourceForm extends ModelForm { +export class OAuthSourceForm extends BaseSourceForm { async loadInstance(pk: string): Promise { const source = await new SourcesApi(DEFAULT_CONFIG).sourcesOauthRetrieve({ slug: pk, @@ -61,14 +61,6 @@ export class OAuthSourceForm extends ModelForm { @state() clearIcon = false; - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated source."); - } else { - return msg("Successfully created source."); - } - } - async send(data: OAuthSource): Promise { data.providerType = (this.providerType?.slug || "") as ProviderTypeEnum; let source: OAuthSource; diff --git a/web/src/admin/sources/plex/PlexSourceForm.ts b/web/src/admin/sources/plex/PlexSourceForm.ts index 1318a1ae9..8091067ff 100644 --- a/web/src/admin/sources/plex/PlexSourceForm.ts +++ b/web/src/admin/sources/plex/PlexSourceForm.ts @@ -1,5 +1,6 @@ import "@goauthentik/admin/common/ak-flow-search/ak-source-flow-search"; import { iconHelperText, placeholderHelperText } from "@goauthentik/admin/helperText"; +import { BaseSourceForm } from "@goauthentik/admin/sources/BaseSourceForm"; import { UserMatchingModeToLabel } from "@goauthentik/admin/sources/oauth/utils"; import { DEFAULT_CONFIG, config } from "@goauthentik/common/api/config"; import { PlexAPIClient, PlexResource, popupCenterScreen } from "@goauthentik/common/helpers/plex"; @@ -7,7 +8,6 @@ import { ascii_letters, digits, first, randomString } from "@goauthentik/common/ import { rootInterface } from "@goauthentik/elements/Base"; import "@goauthentik/elements/forms/FormGroup"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import "@goauthentik/elements/forms/SearchSelect"; import { msg } from "@lit/localize"; @@ -24,7 +24,7 @@ import { } from "@goauthentik/api"; @customElement("ak-source-plex-form") -export class PlexSourceForm extends ModelForm { +export class PlexSourceForm extends BaseSourceForm { async loadInstance(pk: string): Promise { const source = await new SourcesApi(DEFAULT_CONFIG).sourcesPlexRetrieve({ slug: pk, @@ -50,14 +50,6 @@ export class PlexSourceForm extends ModelForm { } as PlexSource; } - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated source."); - } else { - return msg("Successfully created source."); - } - } - async send(data: PlexSource): Promise { data.plexToken = this.plexToken || ""; let source: PlexSource; diff --git a/web/src/admin/sources/saml/SAMLSourceForm.ts b/web/src/admin/sources/saml/SAMLSourceForm.ts index 49ba30b28..76e996322 100644 --- a/web/src/admin/sources/saml/SAMLSourceForm.ts +++ b/web/src/admin/sources/saml/SAMLSourceForm.ts @@ -1,13 +1,13 @@ import "@goauthentik/admin/common/ak-crypto-certificate-search"; import "@goauthentik/admin/common/ak-flow-search/ak-source-flow-search"; import { iconHelperText, placeholderHelperText } from "@goauthentik/admin/helperText"; +import { BaseSourceForm } from "@goauthentik/admin/sources/BaseSourceForm"; import { UserMatchingModeToLabel } from "@goauthentik/admin/sources/oauth/utils"; import { DEFAULT_CONFIG, config } from "@goauthentik/common/api/config"; import { first } from "@goauthentik/common/utils"; import { rootInterface } from "@goauthentik/elements/Base"; import "@goauthentik/elements/forms/FormGroup"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import "@goauthentik/elements/forms/Radio"; import "@goauthentik/elements/utils/TimeDeltaHelp"; @@ -29,7 +29,7 @@ import { } from "@goauthentik/api"; @customElement("ak-source-saml-form") -export class SAMLSourceForm extends ModelForm { +export class SAMLSourceForm extends BaseSourceForm { @state() clearIcon = false; @@ -41,14 +41,6 @@ export class SAMLSourceForm extends ModelForm { return source; } - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated source."); - } else { - return msg("Successfully created source."); - } - } - async send(data: SAMLSource): Promise { let source: SAMLSource; if (this.instance) { diff --git a/web/src/admin/stages/BaseStageForm.ts b/web/src/admin/stages/BaseStageForm.ts new file mode 100644 index 000000000..67c5ffc35 --- /dev/null +++ b/web/src/admin/stages/BaseStageForm.ts @@ -0,0 +1,11 @@ +import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; + +import { msg } from "@lit/localize"; + +export abstract class BaseStageForm extends ModelForm { + getSuccessMessage(): string { + return this.instance + ? msg("Successfully updated stage.") + : msg("Successfully created stage."); + } +} diff --git a/web/src/admin/stages/authenticator_duo/AuthenticatorDuoStageForm.ts b/web/src/admin/stages/authenticator_duo/AuthenticatorDuoStageForm.ts index 4d74059be..db9322a84 100644 --- a/web/src/admin/stages/authenticator_duo/AuthenticatorDuoStageForm.ts +++ b/web/src/admin/stages/authenticator_duo/AuthenticatorDuoStageForm.ts @@ -1,9 +1,9 @@ import { RenderFlowOption } from "@goauthentik/admin/flows/utils"; +import { BaseStageForm } from "@goauthentik/admin/stages/BaseStageForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { first } from "@goauthentik/common/utils"; import "@goauthentik/elements/forms/FormGroup"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import "@goauthentik/elements/forms/SearchSelect"; import { msg } from "@lit/localize"; @@ -21,21 +21,13 @@ import { } from "@goauthentik/api"; @customElement("ak-stage-authenticator-duo-form") -export class AuthenticatorDuoStageForm extends ModelForm { +export class AuthenticatorDuoStageForm extends BaseStageForm { loadInstance(pk: string): Promise { return new StagesApi(DEFAULT_CONFIG).stagesAuthenticatorDuoRetrieve({ stageUuid: pk, }); } - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated stage."); - } else { - return msg("Successfully created stage."); - } - } - async send(data: AuthenticatorDuoStage): Promise { if (this.instance) { return new StagesApi(DEFAULT_CONFIG).stagesAuthenticatorDuoPartialUpdate({ diff --git a/web/src/admin/stages/authenticator_sms/AuthenticatorSMSStageForm.ts b/web/src/admin/stages/authenticator_sms/AuthenticatorSMSStageForm.ts index 4522d050b..2938b156a 100644 --- a/web/src/admin/stages/authenticator_sms/AuthenticatorSMSStageForm.ts +++ b/web/src/admin/stages/authenticator_sms/AuthenticatorSMSStageForm.ts @@ -1,9 +1,9 @@ import { RenderFlowOption } from "@goauthentik/admin/flows/utils"; +import { BaseStageForm } from "@goauthentik/admin/stages/BaseStageForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { first } from "@goauthentik/common/utils"; import "@goauthentik/elements/forms/FormGroup"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import "@goauthentik/elements/forms/Radio"; import "@goauthentik/elements/forms/SearchSelect"; @@ -26,7 +26,7 @@ import { } from "@goauthentik/api"; @customElement("ak-stage-authenticator-sms-form") -export class AuthenticatorSMSStageForm extends ModelForm { +export class AuthenticatorSMSStageForm extends BaseStageForm { loadInstance(pk: string): Promise { return new StagesApi(DEFAULT_CONFIG) .stagesAuthenticatorSmsRetrieve({ @@ -45,14 +45,6 @@ export class AuthenticatorSMSStageForm extends ModelForm { if (this.instance) { return new StagesApi(DEFAULT_CONFIG).stagesAuthenticatorSmsUpdate({ diff --git a/web/src/admin/stages/authenticator_static/AuthenticatorStaticStageForm.ts b/web/src/admin/stages/authenticator_static/AuthenticatorStaticStageForm.ts index f9f2684d0..7a5dcab47 100644 --- a/web/src/admin/stages/authenticator_static/AuthenticatorStaticStageForm.ts +++ b/web/src/admin/stages/authenticator_static/AuthenticatorStaticStageForm.ts @@ -1,8 +1,8 @@ import { RenderFlowOption } from "@goauthentik/admin/flows/utils"; +import { BaseStageForm } from "@goauthentik/admin/stages/BaseStageForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { first } from "@goauthentik/common/utils"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import "@goauthentik/elements/forms/SearchSelect"; import { msg } from "@lit/localize"; @@ -19,21 +19,13 @@ import { } from "@goauthentik/api"; @customElement("ak-stage-authenticator-static-form") -export class AuthenticatorStaticStageForm extends ModelForm { +export class AuthenticatorStaticStageForm extends BaseStageForm { loadInstance(pk: string): Promise { return new StagesApi(DEFAULT_CONFIG).stagesAuthenticatorStaticRetrieve({ stageUuid: pk, }); } - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated stage."); - } else { - return msg("Successfully created stage."); - } - } - async send(data: AuthenticatorStaticStage): Promise { if (this.instance) { return new StagesApi(DEFAULT_CONFIG).stagesAuthenticatorStaticUpdate({ diff --git a/web/src/admin/stages/authenticator_totp/AuthenticatorTOTPStageForm.ts b/web/src/admin/stages/authenticator_totp/AuthenticatorTOTPStageForm.ts index aebca9872..91ddcab19 100644 --- a/web/src/admin/stages/authenticator_totp/AuthenticatorTOTPStageForm.ts +++ b/web/src/admin/stages/authenticator_totp/AuthenticatorTOTPStageForm.ts @@ -1,9 +1,9 @@ import { RenderFlowOption } from "@goauthentik/admin/flows/utils"; +import { BaseStageForm } from "@goauthentik/admin/stages/BaseStageForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { first } from "@goauthentik/common/utils"; import "@goauthentik/elements/forms/FormGroup"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import "@goauthentik/elements/forms/SearchSelect"; import { msg } from "@lit/localize"; @@ -21,21 +21,13 @@ import { } from "@goauthentik/api"; @customElement("ak-stage-authenticator-totp-form") -export class AuthenticatorTOTPStageForm extends ModelForm { +export class AuthenticatorTOTPStageForm extends BaseStageForm { loadInstance(pk: string): Promise { return new StagesApi(DEFAULT_CONFIG).stagesAuthenticatorTotpRetrieve({ stageUuid: pk, }); } - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated stage."); - } else { - return msg("Successfully created stage."); - } - } - async send(data: AuthenticatorTOTPStage): Promise { if (this.instance) { return new StagesApi(DEFAULT_CONFIG).stagesAuthenticatorTotpUpdate({ diff --git a/web/src/admin/stages/authenticator_validate/AuthenticatorValidateStageForm.ts b/web/src/admin/stages/authenticator_validate/AuthenticatorValidateStageForm.ts index 146422988..2884f948c 100644 --- a/web/src/admin/stages/authenticator_validate/AuthenticatorValidateStageForm.ts +++ b/web/src/admin/stages/authenticator_validate/AuthenticatorValidateStageForm.ts @@ -1,7 +1,7 @@ +import { BaseStageForm } from "@goauthentik/admin/stages/BaseStageForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import "@goauthentik/elements/forms/FormGroup"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import "@goauthentik/elements/forms/Radio"; import "@goauthentik/elements/utils/TimeDeltaHelp"; @@ -20,7 +20,7 @@ import { } from "@goauthentik/api"; @customElement("ak-stage-authenticator-validate-form") -export class AuthenticatorValidateStageForm extends ModelForm { +export class AuthenticatorValidateStageForm extends BaseStageForm { async loadInstance(pk: string): Promise { const stage = await new StagesApi(DEFAULT_CONFIG).stagesAuthenticatorValidateRetrieve({ stageUuid: pk, @@ -41,14 +41,6 @@ export class AuthenticatorValidateStageForm extends ModelForm { if (this.instance) { return new StagesApi(DEFAULT_CONFIG).stagesAuthenticatorValidateUpdate({ diff --git a/web/src/admin/stages/authenticator_webauthn/AuthenticateWebAuthnStageForm.ts b/web/src/admin/stages/authenticator_webauthn/AuthenticateWebAuthnStageForm.ts index 9bd8bebe1..d8464b6f3 100644 --- a/web/src/admin/stages/authenticator_webauthn/AuthenticateWebAuthnStageForm.ts +++ b/web/src/admin/stages/authenticator_webauthn/AuthenticateWebAuthnStageForm.ts @@ -1,8 +1,8 @@ import { RenderFlowOption } from "@goauthentik/admin/flows/utils"; +import { BaseStageForm } from "@goauthentik/admin/stages/BaseStageForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { first } from "@goauthentik/common/utils"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import "@goauthentik/elements/forms/Radio"; import "@goauthentik/elements/forms/SearchSelect"; @@ -23,21 +23,13 @@ import { } from "@goauthentik/api"; @customElement("ak-stage-authenticator-webauthn-form") -export class AuthenticateWebAuthnStageForm extends ModelForm { +export class AuthenticateWebAuthnStageForm extends BaseStageForm { loadInstance(pk: string): Promise { return new StagesApi(DEFAULT_CONFIG).stagesAuthenticatorWebauthnRetrieve({ stageUuid: pk, }); } - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated stage."); - } else { - return msg("Successfully created stage."); - } - } - async send(data: AuthenticateWebAuthnStage): Promise { if (data.authenticatorAttachment?.toString() === "") { data.authenticatorAttachment = null; diff --git a/web/src/admin/stages/captcha/CaptchaStageForm.ts b/web/src/admin/stages/captcha/CaptchaStageForm.ts index cc8299f30..cacdee5de 100644 --- a/web/src/admin/stages/captcha/CaptchaStageForm.ts +++ b/web/src/admin/stages/captcha/CaptchaStageForm.ts @@ -1,7 +1,7 @@ +import { BaseStageForm } from "@goauthentik/admin/stages/BaseStageForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import "@goauthentik/elements/forms/FormGroup"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import { msg } from "@lit/localize"; import { TemplateResult, html } from "lit"; @@ -11,21 +11,13 @@ import { ifDefined } from "lit/directives/if-defined.js"; import { CaptchaStage, CaptchaStageRequest, StagesApi } from "@goauthentik/api"; @customElement("ak-stage-captcha-form") -export class CaptchaStageForm extends ModelForm { +export class CaptchaStageForm extends BaseStageForm { loadInstance(pk: string): Promise { return new StagesApi(DEFAULT_CONFIG).stagesCaptchaRetrieve({ stageUuid: pk, }); } - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated stage."); - } else { - return msg("Successfully created stage."); - } - } - async send(data: CaptchaStage): Promise { if (this.instance) { return new StagesApi(DEFAULT_CONFIG).stagesCaptchaPartialUpdate({ diff --git a/web/src/admin/stages/consent/ConsentStageForm.ts b/web/src/admin/stages/consent/ConsentStageForm.ts index 84866b10d..7bc5ad0ec 100644 --- a/web/src/admin/stages/consent/ConsentStageForm.ts +++ b/web/src/admin/stages/consent/ConsentStageForm.ts @@ -1,7 +1,7 @@ +import { BaseStageForm } from "@goauthentik/admin/stages/BaseStageForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import "@goauthentik/elements/forms/FormGroup"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import "@goauthentik/elements/utils/TimeDeltaHelp"; import { msg } from "@lit/localize"; @@ -12,7 +12,7 @@ import { ifDefined } from "lit/directives/if-defined.js"; import { ConsentStage, ConsentStageModeEnum, StagesApi } from "@goauthentik/api"; @customElement("ak-stage-consent-form") -export class ConsentStageForm extends ModelForm { +export class ConsentStageForm extends BaseStageForm { loadInstance(pk: string): Promise { return new StagesApi(DEFAULT_CONFIG) .stagesConsentRetrieve({ @@ -27,14 +27,6 @@ export class ConsentStageForm extends ModelForm { @property({ type: Boolean }) showExpiresIn = false; - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated stage."); - } else { - return msg("Successfully created stage."); - } - } - async send(data: ConsentStage): Promise { if (this.instance) { return new StagesApi(DEFAULT_CONFIG).stagesConsentUpdate({ diff --git a/web/src/admin/stages/deny/DenyStageForm.ts b/web/src/admin/stages/deny/DenyStageForm.ts index 340e911d2..ed3dffa5f 100644 --- a/web/src/admin/stages/deny/DenyStageForm.ts +++ b/web/src/admin/stages/deny/DenyStageForm.ts @@ -1,6 +1,6 @@ +import { BaseStageForm } from "@goauthentik/admin/stages/BaseStageForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import { msg } from "@lit/localize"; import { TemplateResult, html } from "lit"; @@ -10,21 +10,13 @@ import { ifDefined } from "lit/directives/if-defined.js"; import { DenyStage, StagesApi } from "@goauthentik/api"; @customElement("ak-stage-deny-form") -export class DenyStageForm extends ModelForm { +export class DenyStageForm extends BaseStageForm { loadInstance(pk: string): Promise { return new StagesApi(DEFAULT_CONFIG).stagesDenyRetrieve({ stageUuid: pk, }); } - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated stage."); - } else { - return msg("Successfully created stage."); - } - } - async send(data: DenyStage): Promise { if (this.instance) { return new StagesApi(DEFAULT_CONFIG).stagesDenyUpdate({ diff --git a/web/src/admin/stages/dummy/DummyStageForm.ts b/web/src/admin/stages/dummy/DummyStageForm.ts index 03fbbb4c3..39d36b99d 100644 --- a/web/src/admin/stages/dummy/DummyStageForm.ts +++ b/web/src/admin/stages/dummy/DummyStageForm.ts @@ -1,7 +1,7 @@ +import { BaseStageForm } from "@goauthentik/admin/stages/BaseStageForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { first } from "@goauthentik/common/utils"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import { msg } from "@lit/localize"; import { TemplateResult, html } from "lit"; @@ -11,21 +11,13 @@ import { ifDefined } from "lit/directives/if-defined.js"; import { DummyStage, StagesApi } from "@goauthentik/api"; @customElement("ak-stage-dummy-form") -export class DummyStageForm extends ModelForm { +export class DummyStageForm extends BaseStageForm { loadInstance(pk: string): Promise { return new StagesApi(DEFAULT_CONFIG).stagesDummyRetrieve({ stageUuid: pk, }); } - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated stage."); - } else { - return msg("Successfully created stage."); - } - } - async send(data: DummyStage): Promise { if (this.instance) { return new StagesApi(DEFAULT_CONFIG).stagesDummyUpdate({ diff --git a/web/src/admin/stages/email/EmailStageForm.ts b/web/src/admin/stages/email/EmailStageForm.ts index a08b5c115..c2595674d 100644 --- a/web/src/admin/stages/email/EmailStageForm.ts +++ b/web/src/admin/stages/email/EmailStageForm.ts @@ -1,8 +1,8 @@ +import { BaseStageForm } from "@goauthentik/admin/stages/BaseStageForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { first } from "@goauthentik/common/utils"; import "@goauthentik/elements/forms/FormGroup"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import { msg } from "@lit/localize"; import { TemplateResult, html } from "lit"; @@ -12,7 +12,7 @@ import { ifDefined } from "lit/directives/if-defined.js"; import { EmailStage, StagesApi, TypeCreate } from "@goauthentik/api"; @customElement("ak-stage-email-form") -export class EmailStageForm extends ModelForm { +export class EmailStageForm extends BaseStageForm { async loadInstance(pk: string): Promise { const stage = await new StagesApi(DEFAULT_CONFIG).stagesEmailRetrieve({ stageUuid: pk, @@ -30,14 +30,6 @@ export class EmailStageForm extends ModelForm { @property({ type: Boolean }) showConnectionSettings = false; - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated stage."); - } else { - return msg("Successfully created stage."); - } - } - async send(data: EmailStage): Promise { if (this.instance) { return new StagesApi(DEFAULT_CONFIG).stagesEmailPartialUpdate({ diff --git a/web/src/admin/stages/identification/IdentificationStageForm.ts b/web/src/admin/stages/identification/IdentificationStageForm.ts index 6fad5fbb2..cc064adf1 100644 --- a/web/src/admin/stages/identification/IdentificationStageForm.ts +++ b/web/src/admin/stages/identification/IdentificationStageForm.ts @@ -1,9 +1,9 @@ import "@goauthentik/admin/common/ak-flow-search/ak-flow-search"; +import { BaseStageForm } from "@goauthentik/admin/stages/BaseStageForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { first, groupBy } from "@goauthentik/common/utils"; import "@goauthentik/elements/forms/FormGroup"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import "@goauthentik/elements/forms/SearchSelect"; import { msg } from "@lit/localize"; @@ -23,7 +23,7 @@ import { } from "@goauthentik/api"; @customElement("ak-stage-identification-form") -export class IdentificationStageForm extends ModelForm { +export class IdentificationStageForm extends BaseStageForm { loadInstance(pk: string): Promise { return new StagesApi(DEFAULT_CONFIG).stagesIdentificationRetrieve({ stageUuid: pk, @@ -38,14 +38,6 @@ export class IdentificationStageForm extends ModelForm { if (this.instance) { return new StagesApi(DEFAULT_CONFIG).stagesIdentificationUpdate({ diff --git a/web/src/admin/stages/invitation/InvitationForm.ts b/web/src/admin/stages/invitation/InvitationForm.ts index 4555a547e..24b2c34cf 100644 --- a/web/src/admin/stages/invitation/InvitationForm.ts +++ b/web/src/admin/stages/invitation/InvitationForm.ts @@ -23,11 +23,9 @@ export class InvitationForm extends ModelForm { } getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated invitation."); - } else { - return msg("Successfully created invitation."); - } + return this.instance + ? msg("Successfully updated invitation.") + : msg("Successfully created invitation."); } async send(data: Invitation): Promise { diff --git a/web/src/admin/stages/invitation/InvitationStageForm.ts b/web/src/admin/stages/invitation/InvitationStageForm.ts index 549c58ae6..822d8a2da 100644 --- a/web/src/admin/stages/invitation/InvitationStageForm.ts +++ b/web/src/admin/stages/invitation/InvitationStageForm.ts @@ -1,8 +1,8 @@ +import { BaseStageForm } from "@goauthentik/admin/stages/BaseStageForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { first } from "@goauthentik/common/utils"; import "@goauthentik/elements/forms/FormGroup"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import { msg } from "@lit/localize"; import { TemplateResult, html } from "lit"; @@ -11,21 +11,13 @@ import { customElement } from "lit/decorators.js"; import { InvitationStage, StagesApi } from "@goauthentik/api"; @customElement("ak-stage-invitation-form") -export class InvitationStageForm extends ModelForm { +export class InvitationStageForm extends BaseStageForm { loadInstance(pk: string): Promise { return new StagesApi(DEFAULT_CONFIG).stagesInvitationStagesRetrieve({ stageUuid: pk, }); } - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated stage."); - } else { - return msg("Successfully created stage."); - } - } - async send(data: InvitationStage): Promise { if (this.instance) { return new StagesApi(DEFAULT_CONFIG).stagesInvitationStagesUpdate({ diff --git a/web/src/admin/stages/password/PasswordStageForm.ts b/web/src/admin/stages/password/PasswordStageForm.ts index ce503ef00..939f92931 100644 --- a/web/src/admin/stages/password/PasswordStageForm.ts +++ b/web/src/admin/stages/password/PasswordStageForm.ts @@ -1,9 +1,9 @@ import { RenderFlowOption } from "@goauthentik/admin/flows/utils"; +import { BaseStageForm } from "@goauthentik/admin/stages/BaseStageForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { first } from "@goauthentik/common/utils"; import "@goauthentik/elements/forms/FormGroup"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import "@goauthentik/elements/forms/SearchSelect"; import { msg } from "@lit/localize"; @@ -22,21 +22,13 @@ import { } from "@goauthentik/api"; @customElement("ak-stage-password-form") -export class PasswordStageForm extends ModelForm { +export class PasswordStageForm extends BaseStageForm { loadInstance(pk: string): Promise { return new StagesApi(DEFAULT_CONFIG).stagesPasswordRetrieve({ stageUuid: pk, }); } - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated stage."); - } else { - return msg("Successfully created stage."); - } - } - async send(data: PasswordStage): Promise { if (this.instance) { return new StagesApi(DEFAULT_CONFIG).stagesPasswordUpdate({ diff --git a/web/src/admin/stages/prompt/PromptForm.ts b/web/src/admin/stages/prompt/PromptForm.ts index f46a6be5a..bddf1c368 100644 --- a/web/src/admin/stages/prompt/PromptForm.ts +++ b/web/src/admin/stages/prompt/PromptForm.ts @@ -90,11 +90,9 @@ export class PromptForm extends ModelForm { } getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated prompt."); - } else { - return msg("Successfully created prompt."); - } + return this.instance + ? msg("Successfully updated prompt.") + : msg("Successfully created prompt."); } static get styles(): CSSResult[] { diff --git a/web/src/admin/stages/prompt/PromptStageForm.ts b/web/src/admin/stages/prompt/PromptStageForm.ts index f3841e10f..43e35f475 100644 --- a/web/src/admin/stages/prompt/PromptStageForm.ts +++ b/web/src/admin/stages/prompt/PromptStageForm.ts @@ -1,9 +1,9 @@ +import { BaseStageForm } from "@goauthentik/admin/stages/BaseStageForm"; import "@goauthentik/admin/stages/prompt/PromptForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import "@goauthentik/elements/forms/FormGroup"; import "@goauthentik/elements/forms/HorizontalFormElement"; import "@goauthentik/elements/forms/ModalForm"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import { msg, str } from "@lit/localize"; import { TemplateResult, html } from "lit"; @@ -19,7 +19,7 @@ import { } from "@goauthentik/api"; @customElement("ak-stage-prompt-form") -export class PromptStageForm extends ModelForm { +export class PromptStageForm extends BaseStageForm { loadInstance(pk: string): Promise { return new StagesApi(DEFAULT_CONFIG).stagesPromptStagesRetrieve({ stageUuid: pk, @@ -38,14 +38,6 @@ export class PromptStageForm extends ModelForm { prompts?: PaginatedPromptList; policies?: PaginatedPolicyList; - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated stage."); - } else { - return msg("Successfully created stage."); - } - } - async send(data: PromptStage): Promise { if (this.instance) { return new StagesApi(DEFAULT_CONFIG).stagesPromptStagesUpdate({ diff --git a/web/src/admin/stages/user_delete/UserDeleteStageForm.ts b/web/src/admin/stages/user_delete/UserDeleteStageForm.ts index 3d15b52ff..617cd182a 100644 --- a/web/src/admin/stages/user_delete/UserDeleteStageForm.ts +++ b/web/src/admin/stages/user_delete/UserDeleteStageForm.ts @@ -1,6 +1,6 @@ +import { BaseStageForm } from "@goauthentik/admin/stages/BaseStageForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import { msg } from "@lit/localize"; import { TemplateResult, html } from "lit"; @@ -10,21 +10,13 @@ import { ifDefined } from "lit/directives/if-defined.js"; import { StagesApi, UserDeleteStage } from "@goauthentik/api"; @customElement("ak-stage-user-delete-form") -export class UserDeleteStageForm extends ModelForm { +export class UserDeleteStageForm extends BaseStageForm { loadInstance(pk: string): Promise { return new StagesApi(DEFAULT_CONFIG).stagesUserDeleteRetrieve({ stageUuid: pk, }); } - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated stage."); - } else { - return msg("Successfully created stage."); - } - } - async send(data: UserDeleteStage): Promise { if (this.instance) { return new StagesApi(DEFAULT_CONFIG).stagesUserDeleteUpdate({ diff --git a/web/src/admin/stages/user_login/UserLoginStageForm.ts b/web/src/admin/stages/user_login/UserLoginStageForm.ts index 6ba879799..c386a9af2 100644 --- a/web/src/admin/stages/user_login/UserLoginStageForm.ts +++ b/web/src/admin/stages/user_login/UserLoginStageForm.ts @@ -1,9 +1,9 @@ +import { BaseStageForm } from "@goauthentik/admin/stages/BaseStageForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { first } from "@goauthentik/common/utils"; import "@goauthentik/elements/Alert"; import "@goauthentik/elements/forms/FormGroup"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import "@goauthentik/elements/utils/TimeDeltaHelp"; import { msg } from "@lit/localize"; @@ -13,21 +13,13 @@ import { customElement } from "lit/decorators.js"; import { StagesApi, UserLoginStage } from "@goauthentik/api"; @customElement("ak-stage-user-login-form") -export class UserLoginStageForm extends ModelForm { +export class UserLoginStageForm extends BaseStageForm { loadInstance(pk: string): Promise { return new StagesApi(DEFAULT_CONFIG).stagesUserLoginRetrieve({ stageUuid: pk, }); } - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated stage."); - } else { - return msg("Successfully created stage."); - } - } - async send(data: UserLoginStage): Promise { if (this.instance) { return new StagesApi(DEFAULT_CONFIG).stagesUserLoginUpdate({ diff --git a/web/src/admin/stages/user_logout/UserLogoutStageForm.ts b/web/src/admin/stages/user_logout/UserLogoutStageForm.ts index 7e90aade6..40a99500f 100644 --- a/web/src/admin/stages/user_logout/UserLogoutStageForm.ts +++ b/web/src/admin/stages/user_logout/UserLogoutStageForm.ts @@ -1,6 +1,6 @@ +import { BaseStageForm } from "@goauthentik/admin/stages/BaseStageForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import { msg } from "@lit/localize"; import { TemplateResult, html } from "lit"; @@ -10,21 +10,13 @@ import { ifDefined } from "lit/directives/if-defined.js"; import { StagesApi, UserLogoutStage } from "@goauthentik/api"; @customElement("ak-stage-user-logout-form") -export class UserLogoutStageForm extends ModelForm { +export class UserLogoutStageForm extends BaseStageForm { loadInstance(pk: string): Promise { return new StagesApi(DEFAULT_CONFIG).stagesUserLogoutRetrieve({ stageUuid: pk, }); } - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated stage."); - } else { - return msg("Successfully created stage."); - } - } - async send(data: UserLogoutStage): Promise { if (this.instance) { return new StagesApi(DEFAULT_CONFIG).stagesUserLogoutUpdate({ diff --git a/web/src/admin/stages/user_write/UserWriteStageForm.ts b/web/src/admin/stages/user_write/UserWriteStageForm.ts index 3ef5185cd..08b436f9b 100644 --- a/web/src/admin/stages/user_write/UserWriteStageForm.ts +++ b/web/src/admin/stages/user_write/UserWriteStageForm.ts @@ -1,9 +1,9 @@ +import { BaseStageForm } from "@goauthentik/admin/stages/BaseStageForm"; import { UserCreationModeEnum } from "@goauthentik/api/dist/models/UserCreationModeEnum"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { first } from "@goauthentik/common/utils"; import "@goauthentik/elements/forms/FormGroup"; import "@goauthentik/elements/forms/HorizontalFormElement"; -import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import "@goauthentik/elements/forms/Radio"; import "@goauthentik/elements/forms/SearchSelect"; @@ -22,21 +22,13 @@ import { } from "@goauthentik/api"; @customElement("ak-stage-user-write-form") -export class UserWriteStageForm extends ModelForm { +export class UserWriteStageForm extends BaseStageForm { loadInstance(pk: string): Promise { return new StagesApi(DEFAULT_CONFIG).stagesUserWriteRetrieve({ stageUuid: pk, }); } - getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated stage."); - } else { - return msg("Successfully created stage."); - } - } - async send(data: UserWriteStage): Promise { if (this.instance) { return new StagesApi(DEFAULT_CONFIG).stagesUserWriteUpdate({ diff --git a/web/src/admin/tenants/TenantForm.ts b/web/src/admin/tenants/TenantForm.ts index 438396660..51e81b24e 100644 --- a/web/src/admin/tenants/TenantForm.ts +++ b/web/src/admin/tenants/TenantForm.ts @@ -26,11 +26,9 @@ export class TenantForm extends ModelForm { } getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated tenant."); - } else { - return msg("Successfully created tenant."); - } + return this.instance + ? msg("Successfully updated tenant.") + : msg("Successfully created tenant."); } async send(data: Tenant): Promise { diff --git a/web/src/admin/tokens/TokenForm.ts b/web/src/admin/tokens/TokenForm.ts index 904c8cdac..7324b0e70 100644 --- a/web/src/admin/tokens/TokenForm.ts +++ b/web/src/admin/tokens/TokenForm.ts @@ -26,11 +26,9 @@ export class TokenForm extends ModelForm { } getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated token."); - } else { - return msg("Successfully created token."); - } + return this.instance + ? msg("Successfully updated token.") + : msg("Successfully created token."); } async send(data: Token): Promise { diff --git a/web/src/user/user-settings/tokens/UserTokenForm.ts b/web/src/user/user-settings/tokens/UserTokenForm.ts index 05bb3b111..78ce3413d 100644 --- a/web/src/user/user-settings/tokens/UserTokenForm.ts +++ b/web/src/user/user-settings/tokens/UserTokenForm.ts @@ -21,11 +21,9 @@ export class UserTokenForm extends ModelForm { } getSuccessMessage(): string { - if (this.instance) { - return msg("Successfully updated token."); - } else { - return msg("Successfully created token."); - } + return this.instance + ? msg("Successfully updated token.") + : msg("Successfully created token."); } async send(data: Token): Promise {