From d8fa6141cff4d00ba22e95ef4f5dcc9102e1c1c2 Mon Sep 17 00:00:00 2001 From: stew-ro <60453211+stew-ro@users.noreply.github.com> Date: Mon, 13 Jul 2020 14:53:37 -0700 Subject: [PATCH] fix: make sure token names are unique (#404) * fix: make sure token names are unique * refactor: fix whitespacing and use string constants * refactor: fix whitespacing Co-authored-by: kunzheng <58841788+kunzms@users.noreply.github.com> --- src/common/localization/en-us.ts | 1 + src/common/localization/es-cl.ts | 1 + src/common/strings.ts | 1 + .../pages/appSettings/appSettingsForm.tsx | 20 +++++++++++++++++++ 4 files changed, 23 insertions(+) diff --git a/src/common/localization/en-us.ts b/src/common/localization/en-us.ts index 87f83cc6..24edff1f 100644 --- a/src/common/localization/en-us.ts +++ b/src/common/localization/en-us.ts @@ -69,6 +69,7 @@ export const english: IAppStrings = { key: { title: "Key", }, + duplicateNameErrorMessage: "Token name must be unique for all tokens", }, securityTokens: { title: "Security Tokens", diff --git a/src/common/localization/es-cl.ts b/src/common/localization/es-cl.ts index fb3ad642..8cf2216f 100644 --- a/src/common/localization/es-cl.ts +++ b/src/common/localization/es-cl.ts @@ -69,6 +69,7 @@ export const spanish: IAppStrings = { key: { title: "Clave", }, + duplicateNameErrorMessage: "El nombre del token debe ser Ășnico para todos los tokens", }, securityTokens: { title: "Tokens de seguridad", diff --git a/src/common/strings.ts b/src/common/strings.ts index f4820dc9..3e068833 100644 --- a/src/common/strings.ts +++ b/src/common/strings.ts @@ -69,6 +69,7 @@ export interface IAppStrings { key: { title: string; }, + duplicateNameErrorMessage: string, }, securityTokens: { title: string; diff --git a/src/react/components/pages/appSettings/appSettingsForm.tsx b/src/react/components/pages/appSettings/appSettingsForm.tsx index 9e1e41b1..6fc9e91e 100644 --- a/src/react/components/pages/appSettings/appSettingsForm.tsx +++ b/src/react/components/pages/appSettings/appSettingsForm.tsx @@ -106,6 +106,26 @@ export class AppSettingsForm extends React.Component { + if (!token.name) { + return; + } + const tokenName = token.name; // not trimmed because user's might already have non trimmed token names + if (tokensMap[tokenName] !== undefined) { + const initialSecurityTokenErrorName = errors.securityTokens[tokensMap[tokenName]].name; + const duplicateSecurityTokenErrorName = errors.securityTokens[index.toString()].name + if (duplicateSecurityTokenErrorName) { + duplicateSecurityTokenErrorName.addError(strings.appSettings.securityToken.duplicateNameErrorMessage); + } + if (initialSecurityTokenErrorName.__errors.length === 0) { + initialSecurityTokenErrorName.addError(strings.appSettings.securityToken.duplicateNameErrorMessage); + } + } else { + tokensMap[tokenName] = index; + } + }); + if (this.state.classNames.indexOf("was-validated") === -1) { this.setState({ classNames: [...this.state.classNames, "was-validated"],