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>
This commit is contained in:
stew-ro 2020-07-13 14:53:37 -07:00 коммит произвёл GitHub
Родитель 8cc421c3fe
Коммит d8fa6141cf
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 23 добавлений и 0 удалений

Просмотреть файл

@ -69,6 +69,7 @@ export const english: IAppStrings = {
key: {
title: "Key",
},
duplicateNameErrorMessage: "Token name must be unique for all tokens",
},
securityTokens: {
title: "Security Tokens",

Просмотреть файл

@ -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",

Просмотреть файл

@ -69,6 +69,7 @@ export interface IAppStrings {
key: {
title: string;
},
duplicateNameErrorMessage: string,
},
securityTokens: {
title: string;

Просмотреть файл

@ -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"],