Skip to content

Commit

Permalink
fix: make sure token names are unique (#404)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
stew-ro and kunzms authored Jul 13, 2020
1 parent 8cc421c commit d8fa614
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/common/localization/en-us.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const english: IAppStrings = {
key: {
title: "Key",
},
duplicateNameErrorMessage: "Token name must be unique for all tokens",
},
securityTokens: {
title: "Security Tokens",
Expand Down
1 change: 1 addition & 0 deletions src/common/localization/es-cl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/common/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export interface IAppStrings {
key: {
title: string;
},
duplicateNameErrorMessage: string,
},
securityTokens: {
title: string;
Expand Down
20 changes: 20 additions & 0 deletions src/react/components/pages/appSettings/appSettingsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,26 @@ export class AppSettingsForm extends React.Component<IAppSettingsFormProps, IApp
}

private onFormValidate(appSettings: IAppSettings, errors: FormValidation) {
const tokensMap = {};
appSettings.securityTokens.forEach((token, index) => {
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"],
Expand Down

0 comments on commit d8fa614

Please sign in to comment.