From 32f69e4d2bd80997a1569a8d08ce312473ae8b2d Mon Sep 17 00:00:00 2001 From: Jeremy Clements <79224539+jeclrsg@users.noreply.github.com> Date: Fri, 5 Jul 2024 14:59:38 -0400 Subject: [PATCH] HPCC-32211 ECL Watch v9 fix password expiry check change ECL Watch v9's password expiry check to work the same as v5, relying only on the value of passwordDaysRemaining from ESP Signed-off-by: Jeremy Clements <79224539+jeclrsg@users.noreply.github.com> --- esp/src/eclwatch/HPCCPlatformWidget.js | 4 +-- esp/src/src-react/components/Title.tsx | 39 ++++++++++++++++++-------- esp/src/src-react/hooks/confirm.tsx | 2 +- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/esp/src/eclwatch/HPCCPlatformWidget.js b/esp/src/eclwatch/HPCCPlatformWidget.js index 4424fe0c4ef..1701a07c39c 100644 --- a/esp/src/eclwatch/HPCCPlatformWidget.js +++ b/esp/src/eclwatch/HPCCPlatformWidget.js @@ -258,11 +258,11 @@ define([ switch (response.MyAccountResponse.passwordDaysRemaining) { case null: break; - case -1: + case -1: // password has expired alert(context.i18n.PasswordExpired); context._onUserID(); break; - case -2: + case -2: // password never expires break; default: if (response.MyAccountResponse.passwordDaysRemaining && response.MyAccountResponse.passwordDaysRemaining <= response.MyAccountResponse.passwordExpirationWarningDays) { diff --git a/esp/src/src-react/components/Title.tsx b/esp/src/src-react/components/Title.tsx index a2daa39e66e..f42b2e6ad77 100644 --- a/esp/src/src-react/components/Title.tsx +++ b/esp/src/src-react/components/Title.tsx @@ -10,12 +10,12 @@ import nlsHPCC from "src/nlsHPCC"; import * as Utility from "src/Utility"; import { useBanner } from "../hooks/banner"; +import { useConfirm } from "../hooks/confirm"; +import { replaceUrl } from "../util/history"; import { useECLWatchLogger } from "../hooks/logging"; -import { useBuildInfo, useModernMode } from "../hooks/platform"; +import { useBuildInfo, useModernMode, useCheckFeatures } from "../hooks/platform"; import { useGlobalStore } from "../hooks/store"; import { useMyAccount, useUserSession } from "../hooks/user"; -import { replaceUrl } from "../util/history"; -import { useCheckFeatures } from "../hooks/platform"; import { TitlebarConfig } from "./forms/TitlebarConfig"; import { switchTechPreview } from "./controls/ComingSoon"; @@ -65,6 +65,15 @@ export const DevTitle: React.FunctionComponent = ({ const [showBannerConfig, setShowBannerConfig] = React.useState(false); const [BannerMessageBar, BannerConfig] = useBanner({ showForm: showBannerConfig, setShowForm: setShowBannerConfig }); + const [PasswordExpiredConfirm, setPasswordExpiredConfirm] = useConfirm({ + title: nlsHPCC.PasswordExpiration, + message: nlsHPCC.PasswordExpired, + cancelLabel: null, + onSubmit: React.useCallback(() => { + setShowMyAccount(true); + }, []) + }); + const titlebarColorSet = React.useMemo(() => { return titlebarColor && titlebarColor !== theme.palette.themeLight; }, [theme.palette, titlebarColor]); @@ -236,16 +245,23 @@ export const DevTitle: React.FunctionComponent = ({ if (!cookie("PasswordExpiredCheck")) { // cookie expires option expects whole number of days, use a decimal < 1 for hours cookie("PasswordExpiredCheck", "true", { expires: 0.5, path: "/" }); - if (currentUser.passwordIsExpired) { - alert(nlsHPCC.PasswordExpired); - setShowMyAccount(true); - } else if (currentUser.passwordDaysRemaining && currentUser.passwordDaysRemaining <= currentUser.passwordExpirationWarningDays) { - if (confirm(nlsHPCC.PasswordExpirePrefix + currentUser.passwordDaysRemaining + nlsHPCC.PasswordExpirePostfix)) { - setShowMyAccount(true); - } + switch (currentUser.passwordDaysRemaining) { + case -1: // password has expired + setPasswordExpiredConfirm(true); + break; + case -2: // password never expires + case null: + break; + default: + if (currentUser?.passwordDaysRemaining <= currentUser?.passwordExpirationWarningDays) { + if (confirm(nlsHPCC.PasswordExpirePrefix + currentUser.passwordDaysRemaining + nlsHPCC.PasswordExpirePostfix)) { + setShowMyAccount(true); + } + } + break; } } - }, [currentUser]); + }, [currentUser, setPasswordExpiredConfirm]); return
@@ -296,6 +312,7 @@ export const DevTitle: React.FunctionComponent = ({ setShowMyAccount(false)}> +
; }; diff --git a/esp/src/src-react/hooks/confirm.tsx b/esp/src/src-react/hooks/confirm.tsx index d0eed3617d1..5c2e3615327 100644 --- a/esp/src/src-react/hooks/confirm.tsx +++ b/esp/src/src-react/hooks/confirm.tsx @@ -39,7 +39,7 @@ export function useConfirm({ title, message, items = [], onSubmit, submitLabel = setShow(false); }} /> - setShow(false)} /> + {cancelLabel && setShow(false)} />} ; }, [cancelLabel, items, message, onSubmit, show, submitLabel, title]);