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:
Родитель
8cc421c3fe
Коммит
d8fa6141cf
|
@ -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"],
|
||||
|
|
Загрузка…
Ссылка в новой задаче