From 0d0e086913074448f65bd0882dd6aa68faeb71f2 Mon Sep 17 00:00:00 2001 From: Jon Koops Date: Mon, 30 May 2022 12:20:17 +0200 Subject: [PATCH] Use correct field for authentication of e-mail server (#2706) --- src/realm-settings/EmailTab.tsx | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/src/realm-settings/EmailTab.tsx b/src/realm-settings/EmailTab.tsx index 9f0f855dac..7eda131684 100644 --- a/src/realm-settings/EmailTab.tsx +++ b/src/realm-settings/EmailTab.tsx @@ -56,7 +56,7 @@ export const RealmSettingsEmailTab = ({ const authenticationEnabled = useWatch({ control, - name: "smtpServer.authentication", + name: "smtpServer.auth", defaultValue: "", }); @@ -78,25 +78,19 @@ export const RealmSettingsEmailTab = ({ }; const testConnection = async () => { + const toNumber = (value: string) => Number(value); + const toBoolean = (value: string) => value === true.toString(); + const valueMapper = new Map unknown>([ + ["port", toNumber], + ["ssl", toBoolean], + ["starttls", toBoolean], + ["auth", toBoolean], + ]); + const serverSettings = { ...getValues()["smtpServer"] }; - // Code below uses defensive coding as the server configuration uses an ambiguous record type. - if (typeof serverSettings.port === "string") { - serverSettings.port = Number(serverSettings.port); - } - - if (typeof serverSettings.ssl === "string") { - serverSettings.ssl = serverSettings.ssl === true.toString(); - } - - if (typeof serverSettings.starttls === "string") { - serverSettings.starttls = serverSettings.starttls === true.toString(); - } - - // For some reason the API wants a duplicate field for the authentication status. - // Somebody thought this was a good idea, so here we are. - if (serverSettings.authentication === true.toString()) { - serverSettings.auth = true; + for (const [key, mapperFn] of valueMapper.entries()) { + serverSettings[key] = mapperFn(serverSettings[key]); } try { @@ -321,7 +315,7 @@ export const RealmSettingsEmailTab = ({ fieldId="kc-authentication" > (