2525import jakarta .inject .Singleton ;
2626import org .slf4j .Logger ;
2727import org .slf4j .LoggerFactory ;
28+
2829import java .io .BufferedReader ;
2930import java .time .format .DateTimeFormatter ;
3031import java .time .LocalDate ;
@@ -76,12 +77,12 @@ private record ReviewPeriodInfo(String subject, LocalDate closeDate) {}
7677
7778 public FeedbackRequestServicesImpl (
7879 FeedbackRequestRepository feedbackReqRepository ,
79- CurrentUserServices currentUserServices ,
80- MemberProfileServices memberProfileServices ,
81- ReviewPeriodRepository reviewPeriodRepository ,
82- ReviewAssignmentRepository reviewAssignmentRepository ,
83- @ Named (MailJetFactory .MJML_FORMAT ) EmailSender emailSender ,
84- CheckInsConfiguration checkInsConfiguration ,
80+ CurrentUserServices currentUserServices ,
81+ MemberProfileServices memberProfileServices ,
82+ ReviewPeriodRepository reviewPeriodRepository ,
83+ ReviewAssignmentRepository reviewAssignmentRepository ,
84+ @ Named (MailJetFactory .MJML_FORMAT ) EmailSender emailSender ,
85+ CheckInsConfiguration checkInsConfiguration ,
8586 FeedbackExternalRecipientServices feedbackExternalRecipientServices
8687 ) {
8788 this .feedbackReqRepository = feedbackReqRepository ;
@@ -106,7 +107,7 @@ private void validateMembers(FeedbackRequest feedbackRequest) {
106107 throw new BadArgException ("Cannot save feedback request with both recipient and external-recipient ID" );
107108 }
108109 if (feedbackRequest .getExternalRecipientId () == null && feedbackRequest .getRecipientId () == null ) {
109- throw new BadArgException ("Cannot save feedback request without both recipient and external-recipient ID" );
110+ throw new BadArgException ("Cannot save feedback request without recipient or external-recipient ID" );
110111 }
111112
112113 try {
@@ -130,7 +131,6 @@ private void validateMembers(FeedbackRequest feedbackRequest) {
130131 } catch (NotFoundException e ) {
131132 throw new BadArgException ("Cannot save feedback request with invalid requestee ID" );
132133 }
133-
134134 }
135135
136136 @ Override
@@ -254,16 +254,9 @@ public FeedbackRequest update(FeedbackRequestUpdateDTO feedbackRequestUpdateDTO)
254254 MemberProfile reviewerMemberProfile ;
255255 FeedbackExternalRecipient reviewerExternalRecipient ;
256256 String reviewerFirstName , reviewerEmail ;
257- MemberProfile currentUser ;
257+ final UUID currentUserId = currentUserServices . getCurrentUserId () ;
258258 boolean currentUserEqualsRequestee = false ;
259259
260- try {
261- currentUser = currentUserServices .getCurrentUser ();
262- } catch (NotFoundException notFoundException ) {
263- currentUser = null ;
264- }
265-
266-
267260 final FeedbackRequest feedbackRequest = this .getFromDTO (feedbackRequestUpdateDTO );
268261 FeedbackRequest originalFeedback = null ;
269262
@@ -275,7 +268,9 @@ public FeedbackRequest update(FeedbackRequestUpdateDTO feedbackRequestUpdateDTO)
275268 throw new BadArgException ("Cannot update feedback request that does not exist" );
276269 }
277270
278- if (currentUser != null ) currentUserEqualsRequestee = currentUser .getId ().equals (originalFeedback .getRequesteeId ());
271+ if (currentUserId != null ) {
272+ currentUserEqualsRequestee = currentUserId .equals (originalFeedback .getRequesteeId ());
273+ }
279274
280275 validateMembers (originalFeedback );
281276
@@ -360,7 +355,7 @@ public FeedbackRequest update(FeedbackRequestUpdateDTO feedbackRequestUpdateDTO)
360355 sendNewRequestEmail (storedRequest );
361356 }
362357
363- boolean currentUserSameAsRequestee = currentUser != null && currentUser . getId () .equals (requestee .getId ());
358+ boolean currentUserSameAsRequestee = currentUserId != null && currentUserId .equals (requestee .getId ());
364359 // Send self-review completion email to supervisor and pdl if appropriate
365360 if (currentUserSameAsRequestee ) {
366361 sendSelfReviewCompletionEmailToSupervisor (feedbackRequest );
@@ -411,15 +406,10 @@ public FeedbackRequest getById(UUID id) {
411406
412407 @ Override
413408 public List <FeedbackRequest > findByValues (UUID creatorId , UUID requesteeId , UUID recipientId , LocalDate oldestDate , UUID reviewPeriodId , UUID templateId , UUID externalRecipientId , List <UUID > requesteeIds ) {
414- MemberProfile currentUser ;
409+ final UUID currentUserId = currentUserServices . getCurrentUserId () ;
415410 List <FeedbackRequest > feedbackReqList = new ArrayList <>();
416411
417- try {
418- currentUser = currentUserServices .getCurrentUser ();
419- } catch (NotFoundException notFoundException ) {
420- currentUser = null ;
421- }
422- if (currentUser == null && externalRecipientId == null ) {
412+ if (currentUserId == null && externalRecipientId == null ) {
423413 throw new PermissionException (NOT_AUTHORIZED_MSG );
424414 }
425415 if (requesteeIds != null && !requesteeIds .isEmpty ()) {
@@ -434,21 +424,11 @@ public List<FeedbackRequest> findByValues(UUID creatorId, UUID requesteeId, UUID
434424 if (currentUserServices .isAdmin ()) {
435425 visible = true ;
436426 } else if (request != null ) {
437- MemberProfile currentUserLambda ;
438- UUID currentUserIdLambda ;
439-
440- try {
441- currentUserLambda = currentUserServices .getCurrentUser ();
442- currentUserIdLambda = currentUserLambda .getId ();
443- } catch (NotFoundException notFoundException ) {
444- currentUserLambda = null ;
445- currentUserIdLambda = null ;
446- }
447- if (currentUserIdLambda != null ) {
448- if (currentUserIdLambda .equals (request .getCreatorId ())) visible = true ;
449- if (isSupervisor (request .getRequesteeId (), currentUserIdLambda )) visible = true ;
450- if (currentUserIdLambda .equals (request .getRecipientId ())) visible = true ;
451- if (selfRevieweeIsCurrentUserReviewee (request , currentUserIdLambda )) visible = true ;
427+ if (currentUserId != null ) {
428+ if (currentUserId .equals (request .getCreatorId ())) visible = true ;
429+ if (isSupervisor (request .getRequesteeId (), currentUserId )) visible = true ;
430+ if (currentUserId .equals (request .getRecipientId ())) visible = true ;
431+ if (selfRevieweeIsCurrentUserReviewee (request , currentUserId )) visible = true ;
452432 } else {
453433 if (request .getExternalRecipientId () != null ) visible = true ;
454434 }
@@ -510,16 +490,11 @@ private boolean getIsPermitted(FeedbackRequest feedbackReq) {
510490 private boolean getIsPermittedForExternalRecipient (FeedbackRequest feedbackReq ) {
511491 final LocalDate sendDate = feedbackReq .getSendDate ();
512492 final LocalDate today = LocalDate .now ();
513- MemberProfile currentUser ;
514- try {
515- currentUser = currentUserServices .getCurrentUser ();
516- } catch (NotFoundException notFoundException ) {
517- currentUser = null ;
518- }
493+ final UUID currentUserId = currentUserServices .getCurrentUserId ();
519494
520495 // The recipient can only access the feedback request after it has been sent
521496 // Since request is for an external recipient, any logged in user can access it as long as they have feedback-reques-id
522- if (sendDate .isAfter (today ) && currentUser == null ) {
497+ if (sendDate .isAfter (today ) && currentUserId == null ) {
523498 throw new PermissionException ("You are not permitted to access this request before the send date." );
524499 }
525500 return true ;
@@ -534,34 +509,19 @@ private boolean reassignIsPermitted(FeedbackRequest feedbackRequest) {
534509 }
535510
536511 private boolean isCurrentUserAdminOrOwner (FeedbackRequest feedbackRequest ) {
537- boolean isAdmin = currentUserServices .isAdmin ();
538- boolean currentUserIsSameAsCreator = false ;
539- UUID currentUserId ;
540- MemberProfile currentUser ;
541- try {
542- currentUser = currentUserServices .getCurrentUser ();
543- } catch (NotFoundException notFoundException ) {
544- currentUser = null ;
545- }
546- if (currentUser != null ) {
547- currentUserId = currentUserServices .getCurrentUser ().getId ();
548- currentUserIsSameAsCreator = currentUserId .equals (feedbackRequest .getCreatorId ());
549- }
550- return isAdmin || currentUserIsSameAsCreator ;
512+ final UUID currentUserId = currentUserServices .getCurrentUserId ();
513+ return currentUserServices .isAdmin () || (currentUserId != null && currentUserId .equals (feedbackRequest .getCreatorId ()));
551514 }
552515
553516 private boolean updateSubmitDateIsPermitted (FeedbackRequest feedbackRequest ) {
554- MemberProfile currentUser ;
555- boolean isAdmin = false ;
556517 try {
557- currentUser = currentUserServices .getCurrentUser ();
558- isAdmin = currentUserServices .isAdmin ();
518+ if (currentUserServices .isAdmin ()) {
519+ return true ;
520+ }
559521 } catch (NotFoundException notFoundException ) {
560- currentUser = null ;
561-
562522 }
563- if ( isAdmin ) return true ;
564- UUID currentUserId = currentUser != null ? currentUser . getId () : null ;
523+
524+ final UUID currentUserId = currentUserServices . getCurrentUserId () ;
565525 if (((currentUserId != null && currentUserId .equals (feedbackRequest .getCreatorId ())) && feedbackRequest .getSubmitDate () != null )) return true ;
566526 if (currentUserId != null && currentUserId .equals (feedbackRequest .getRecipientId ())) return true ;
567527 if (feedbackRequest .getExternalRecipientId () != null ) return true ;
0 commit comments