From 505b61225a46cb1cfe05745d291dde381e781cc3 Mon Sep 17 00:00:00 2001 From: Ken Sternberg <133134217+kensternberg-authentik@users.noreply.github.com> Date: Wed, 20 Nov 2024 15:23:55 -0800 Subject: [PATCH] web: fix bug that prevented error reporting in current wizard. (#12033) * web: Add InvalidationFlow to Radius Provider dialogues ## What - Bugfix: adds the InvalidationFlow to the Radius Provider dialogues - Repairs: `{"invalidation_flow":["This field is required."]}` message, which was *not* propagated to the Notification. - Nitpick: Pretties `?foo=${true}` expressions: `s/\?([^=]+)=\$\{true\}/\1/` ## Note Yes, I know I'm going to have to do more magic when we harmonize the forms, and no, I didn't add the Property Mappings to the wizard, and yes, I know I'm going to have pain with the *new* version of the wizard. But this is a serious bug; you can't make Radius servers with *either* of the current dialogues at the moment. * web/bugfix/fix-reporting-in-wizard-submit # What - Preserves the errors locally for the Wizard, providing explanation and links to fix the issues # Why Just a silly mistake on my part. There shouldn't be two copies of errors (and there isn't in the BIG PRs), but this is how it's designed right now and making the errors show up is an easy fix. In doing so, the "hack" to move the "bad provider name" to the provider page is included. * Updated package.json to use Chromedriver 130 --- web/package-lock.json | 8 +++---- web/package.json | 2 +- ...k-application-wizard-commit-application.ts | 21 ++++++++++++++++++- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/web/package-lock.json b/web/package-lock.json index dbd76c407f..1540d5b665 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -84,7 +84,7 @@ "@wdio/cli": "^9.1.2", "@wdio/spec-reporter": "^9.1.2", "chokidar": "^4.0.1", - "chromedriver": "^129.0.2", + "chromedriver": "^130.0.4", "esbuild": "^0.24.0", "eslint": "^9.11.1", "eslint-plugin-lit": "^1.15.0", @@ -8699,9 +8699,9 @@ } }, "node_modules/chromedriver": { - "version": "129.0.2", - "resolved": "https://registry.npmjs.org/chromedriver/-/chromedriver-129.0.2.tgz", - "integrity": "sha512-rUEFCJAmAwOdFfaDFtveT97fFeA7NOxlkgyPyN+G09Ws4qGW39aLDxMQBbS9cxQQHhTihqZZobgF5CLVYXnmGA==", + "version": "130.0.4", + "resolved": "https://registry.npmjs.org/chromedriver/-/chromedriver-130.0.4.tgz", + "integrity": "sha512-lpR+PWXszij1k4Ig3t338Zvll9HtCTiwoLM7n4pCCswALHxzmgwaaIFBh3rt9+5wRk9D07oFblrazrBxwaYYAQ==", "dev": true, "hasInstallScript": true, "dependencies": { diff --git a/web/package.json b/web/package.json index 97db2787ce..d23a93e857 100644 --- a/web/package.json +++ b/web/package.json @@ -72,7 +72,7 @@ "@wdio/cli": "^9.1.2", "@wdio/spec-reporter": "^9.1.2", "chokidar": "^4.0.1", - "chromedriver": "^129.0.2", + "chromedriver": "^130.0.4", "esbuild": "^0.24.0", "eslint": "^9.11.1", "eslint-plugin-lit": "^1.15.0", diff --git a/web/src/admin/applications/wizard/commit/ak-application-wizard-commit-application.ts b/web/src/admin/applications/wizard/commit/ak-application-wizard-commit-application.ts index 087d05703a..a571c89e20 100644 --- a/web/src/admin/applications/wizard/commit/ak-application-wizard-commit-application.ts +++ b/web/src/admin/applications/wizard/commit/ak-application-wizard-commit-application.ts @@ -25,6 +25,7 @@ import { type TransactionApplicationRequest, type TransactionApplicationResponse, ValidationError, + instanceOfValidationError, } from "@goauthentik/api"; import BasePanel from "../BasePanel"; @@ -69,6 +70,9 @@ const successState: State = { icon: ["fa-check-circle", "pf-m-success"], }; +// eslint-disable-next-line @typescript-eslint/no-explicit-any +const isValidationError = (v: any): v is ValidationError => instanceOfValidationError(v); + @customElement("ak-application-wizard-commit-application") export class ApplicationWizardCommitApplication extends BasePanel { static get styles() { @@ -134,10 +138,25 @@ export class ApplicationWizardCommitApplication extends BasePanel { // eslint-disable-next-line @typescript-eslint/no-explicit-any .catch(async (resolution: any) => { const errors = await parseAPIError(resolution); + + // THIS is a really gross special case; if the user is duplicating the name of an + // existing provider, the error appears on the `app` (!) error object. We have to + // move that to the `provider.name` error field so it shows up in the right place. + if (isValidationError(errors) && Array.isArray(errors?.app?.provider)) { + const providerError = errors.app.provider; + errors.provider = errors.provider ?? {}; + errors.provider.name = providerError; + delete errors.app.provider; + if (Object.keys(errors.app).length === 0) { + delete errors.app; + } + } + + this.errors = errors; this.dispatchWizardUpdate({ update: { ...this.wizard, - errors, + errors: this.errors, }, status: "failed", });