Skip to content

Commit 2bb7381

Browse files
committed
Adjust redirect logic
1 parent 7c3552a commit 2bb7381

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

web-ui/src/pages/FeedbackSubmitPage.jsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { useHistory, useLocation } from 'react-router-dom';
77
import {
88
selectCsrfToken,
99
selectCurrentUser,
10+
selectIsSubordinateOfCurrentUser,
1011
selectProfile
1112
} from '../context/selectors';
1213
import { AppContext } from '../context/AppContext';
@@ -52,11 +53,6 @@ const FeedbackSubmitPage = () => {
5253
const [requestCanceled, setRequestCanceled] = useState(false);
5354
const feedbackRequestFetched = useRef(false);
5455

55-
function isManager(revieweeProfile) {
56-
const supervisorId = revieweeProfile?.supervisorid;
57-
return supervisorId === currentUserId;
58-
}
59-
6056
useEffect(() => {
6157
if (!requestQuery && !selfRequestQuery) {
6258
history.push('/checkins');
@@ -147,12 +143,12 @@ const FeedbackSubmitPage = () => {
147143
feedbackRequest?.recipientId
148144
);
149145

150-
// If this is our review or we are the manager of the reviewer we are
151-
// allowed to view this review.
152-
if (recipientProfile?.id != currentUserId &&
153-
!isManager(recipientProfile)) {
146+
// If we know the current user and it's not the recipient or someone in the person having feedback given's
147+
// management heirarchy, then we should issue an error and send them home...
148+
if (currentUserId && feedbackRequest?.recipientId != currentUserId &&
149+
!selectIsSubordinateOfCurrentUser(feedbackRequest?.requesteeId)) {
154150
// The current user is not the recipients's manager, we need to leave.
155-
history.push('/checkins');
151+
history.push('/');
156152
window.snackDispatch({
157153
type: UPDATE_TOAST,
158154
payload: {
@@ -170,7 +166,7 @@ const FeedbackSubmitPage = () => {
170166
);
171167
setRecipient(recipientProfile);
172168
}
173-
}, [feedbackRequest, selfReviewRequest, state]);
169+
}, [currentUserId, feedbackRequest, selfReviewRequest, state]);
174170

175171
return (
176172
<Root className="feedback-submit-page">

0 commit comments

Comments
 (0)