From 2bb73810ef239eb28c9d609b24cb2405293a7ba3 Mon Sep 17 00:00:00 2001 From: Michael Kimberlin Date: Thu, 21 Nov 2024 13:06:12 -0600 Subject: [PATCH] Adjust redirect logic --- web-ui/src/pages/FeedbackSubmitPage.jsx | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/web-ui/src/pages/FeedbackSubmitPage.jsx b/web-ui/src/pages/FeedbackSubmitPage.jsx index 17a45ad91e..a0edf36de4 100644 --- a/web-ui/src/pages/FeedbackSubmitPage.jsx +++ b/web-ui/src/pages/FeedbackSubmitPage.jsx @@ -7,6 +7,7 @@ import { useHistory, useLocation } from 'react-router-dom'; import { selectCsrfToken, selectCurrentUser, + selectIsSubordinateOfCurrentUser, selectProfile } from '../context/selectors'; import { AppContext } from '../context/AppContext'; @@ -52,11 +53,6 @@ const FeedbackSubmitPage = () => { const [requestCanceled, setRequestCanceled] = useState(false); const feedbackRequestFetched = useRef(false); - function isManager(revieweeProfile) { - const supervisorId = revieweeProfile?.supervisorid; - return supervisorId === currentUserId; - } - useEffect(() => { if (!requestQuery && !selfRequestQuery) { history.push('/checkins'); @@ -147,12 +143,12 @@ const FeedbackSubmitPage = () => { feedbackRequest?.recipientId ); - // If this is our review or we are the manager of the reviewer we are - // allowed to view this review. - if (recipientProfile?.id != currentUserId && - !isManager(recipientProfile)) { + // If we know the current user and it's not the recipient or someone in the person having feedback given's + // management heirarchy, then we should issue an error and send them home... + if (currentUserId && feedbackRequest?.recipientId != currentUserId && + !selectIsSubordinateOfCurrentUser(feedbackRequest?.requesteeId)) { // The current user is not the recipients's manager, we need to leave. - history.push('/checkins'); + history.push('/'); window.snackDispatch({ type: UPDATE_TOAST, payload: { @@ -170,7 +166,7 @@ const FeedbackSubmitPage = () => { ); setRecipient(recipientProfile); } - }, [feedbackRequest, selfReviewRequest, state]); + }, [currentUserId, feedbackRequest, selfReviewRequest, state]); return (