@@ -338,70 +338,62 @@ public void delete(UUID id) {
338338
339339 @ Override
340340 public FeedbackRequest getById (UUID id ) {
341- MemberProfile currentUser ;
342-
343- try {
344- currentUser = currentUserServices .getCurrentUser ();
345- } catch (NotFoundException notFoundException ) {
346- currentUser = null ;
347- }
348-
349341 final Optional <FeedbackRequest > feedbackReq = feedbackReqRepository .findById (id );
350342 if (feedbackReq .isEmpty ()) {
351343 throw new NotFoundException ("No feedback req with id " + id );
352344 }
353- final LocalDate sendDate = feedbackReq .get ().getSendDate ();
354- final UUID requesteeId = feedbackReq .get ().getRequesteeId ();
355- final UUID recipientId = feedbackReq .get ().getRecipientId ();
356- final UUID externalRecipientId = feedbackReq .get ().getExternalRecipientId ();
357- final UUID recipientOrExternalRecipientId = (recipientId != null ) ? recipientId : externalRecipientId ;
358- if (currentUser != null ) {
359- if (!getIsPermitted (requesteeId , recipientOrExternalRecipientId , sendDate )) {
345+ if (feedbackReq .get ().getExternalRecipientId () != null ) {
346+ if (!getIsPermittedForExternalRecipient (feedbackReq .get ())) {
360347 throw new PermissionException (NOT_AUTHORIZED_MSG );
361348 }
362349 } else {
363- if (externalRecipientId == null ) {
350+ if (! getIsPermitted ( feedbackReq . get ()) ) {
364351 throw new PermissionException (NOT_AUTHORIZED_MSG );
365- } else {
366- if (!getIsPermittedForExternalRecipient (requesteeId , sendDate )) {
367- throw new PermissionException (NOT_AUTHORIZED_MSG );
368- }
369352 }
370353 }
371354 return feedbackReq .get ();
372355 }
373356
374357 @ Override
375358 public List <FeedbackRequest > findByValues (UUID creatorId , UUID requesteeId , UUID recipientId , LocalDate oldestDate , UUID reviewPeriodId , UUID templateId , UUID externalRecipientId , List <UUID > requesteeIds ) {
376-
359+ MemberProfile currentUser ;
377360 List <FeedbackRequest > feedbackReqList = new ArrayList <>();
361+
362+ try {
363+ currentUser = currentUserServices .getCurrentUser ();
364+ } catch (NotFoundException notFoundException ) {
365+ currentUser = null ;
366+ }
367+ if (currentUser == null && externalRecipientId == null ) {
368+ throw new PermissionException (NOT_AUTHORIZED_MSG );
369+ }
378370 if (requesteeIds != null && !requesteeIds .isEmpty ()) {
379371 LOG .debug ("Finding feedback requests for {} requesteeIds." , requesteeIds .size ());
380372 feedbackReqList .addAll (feedbackReqRepository .findByValuesWithRequesteeIds (Util .nullSafeUUIDToString (creatorId ), Util .nullSafeUUIDToString (recipientId ), oldestDate , Util .nullSafeUUIDToString (reviewPeriodId ), Util .nullSafeUUIDToString (templateId ), Util .nullSafeUUIDToString (externalRecipientId ), Util .nullSafeUUIDListToStringList (requesteeIds )));
381373 } else {
382374 LOG .debug ("Finding feedback requests one or fewer requesteeIds: {}" , requesteeId );
383375 feedbackReqList .addAll (feedbackReqRepository .findByValues (Util .nullSafeUUIDToString (creatorId ), Util .nullSafeUUIDToString (requesteeId ), Util .nullSafeUUIDToString (recipientId ), oldestDate , Util .nullSafeUUIDToString (reviewPeriodId ), Util .nullSafeUUIDToString (templateId ), Util .nullSafeUUIDToString (externalRecipientId )));
384376 }
385-
386377 feedbackReqList = feedbackReqList .stream ().filter ((FeedbackRequest request ) -> {
387378 boolean visible = false ;
388379 if (currentUserServices .isAdmin ()) {
389380 visible = true ;
390381 } else if (request != null ) {
391- MemberProfile currentUser ;
392- UUID currentUserId ;
382+ MemberProfile currentUserLambda ;
383+ UUID currentUserIdLambda ;
393384
394385 try {
395- currentUser = currentUserServices .getCurrentUser ();
396- currentUserId = currentUser .getId ();
386+ currentUserLambda = currentUserServices .getCurrentUser ();
387+ currentUserIdLambda = currentUserLambda .getId ();
397388 } catch (NotFoundException notFoundException ) {
398- currentUser = null ;
399- currentUserId = null ;
389+ currentUserLambda = null ;
390+ currentUserIdLambda = null ;
400391 }
401- if (currentUserId != null ) {
402- if (currentUserId .equals (request .getCreatorId ())) visible = true ;
403- if (isSupervisor (request .getRequesteeId (), currentUserId )) visible = true ;
404- if (currentUserId .equals (request .getRecipientId ())) visible = true ;
392+ if (currentUserIdLambda != null ) {
393+ if (currentUserIdLambda .equals (request .getCreatorId ())) visible = true ;
394+ if (isSupervisor (request .getRequesteeId (), currentUserIdLambda )) visible = true ;
395+ if (currentUserIdLambda .equals (request .getRecipientId ())) visible = true ;
396+ if (selfRevieweeIsCurrentUserReviewee (request , currentUserIdLambda )) visible = true ;
405397 } else {
406398 if (request .getExternalRecipientId () != null ) visible = true ;
407399 }
@@ -418,8 +410,7 @@ private boolean isSupervisor(UUID requesteeId, UUID currentUserId) {
418410 && memberProfileServices .getSupervisorsForId (requesteeId ).stream ().anyMatch (profile -> currentUserId .equals (profile .getId ()));
419411 }
420412
421- public boolean selfRevieweeIsCurrentUserReviewee (FeedbackRequest request ,
422- UUID currentUserId ) {
413+ public boolean selfRevieweeIsCurrentUserReviewee (FeedbackRequest request , UUID currentUserId ) {
423414 // If we are looking at a self-review request, see if there is a review
424415 // request in the same review period that is assigned to the current
425416 // user and the requestee is the same as the self-review request. If
@@ -446,28 +437,29 @@ private boolean createIsPermitted(UUID requesteeId) {
446437 return isAdmin || currentUserId .equals (requesteePDL ) || isRequesteesSupervisor || currentUserId .equals (requesteeId );
447438 }
448439
449- private boolean getIsPermitted (UUID requesteeId , UUID recipientOrExternalRecipientId , LocalDate sendDate ) {
450- LocalDate today = LocalDate .now ();
451- boolean getIsPermittedReturn ;
440+ private boolean getIsPermitted (FeedbackRequest feedbackReq ) {
441+ final LocalDate sendDate = feedbackReq .getSendDate ();
442+ final UUID requesteeId = feedbackReq .getRequesteeId ();
443+ final UUID recipientId = feedbackReq .getRecipientId ();
444+ final LocalDate today = LocalDate .now ();
452445 final UUID currentUserId = currentUserServices .getCurrentUser ().getId ();
453446
454447 // The recipient can only access the feedback request after it has been sent
455- if (sendDate .isAfter (today ) && currentUserId .equals (recipientOrExternalRecipientId )) {
448+ if (sendDate .isAfter (today ) && currentUserId .equals (recipientId )) {
456449 throw new PermissionException ("You are not permitted to access this request before the send date." );
457450 }
458451
459- getIsPermittedReturn = createIsPermitted (requesteeId ) || currentUserId .equals (recipientOrExternalRecipientId );
460- return getIsPermittedReturn ;
452+ return createIsPermitted (requesteeId ) || currentUserId .equals (recipientId ) || selfRevieweeIsCurrentUserReviewee (feedbackReq , currentUserId );
461453 }
462454
463- private boolean getIsPermittedForExternalRecipient (UUID requesteeId , LocalDate sendDate ) {
464- LocalDate today = LocalDate .now ();
455+ private boolean getIsPermittedForExternalRecipient (FeedbackRequest feedbackReq ) {
456+ final LocalDate sendDate = feedbackReq .getSendDate ();
457+ final LocalDate today = LocalDate .now ();
465458
466459 // The recipient can only access the feedback request after it has been sent
467460 if (sendDate .isAfter (today )) {
468461 throw new PermissionException ("You are not permitted to access this request before the send date." );
469462 }
470-
471463 return true ;
472464 }
473465
0 commit comments