11package com .objectcomputing .checkins .services .kudos ;
22
3+ import com .objectcomputing .checkins .services .permissions .Permission ;
34import com .objectcomputing .checkins .configuration .CheckInsConfiguration ;
45import com .objectcomputing .checkins .notifications .email .EmailSender ;
56import com .objectcomputing .checkins .notifications .email .MailJetFactory ;
@@ -147,7 +148,7 @@ public KudosResponseDTO getById(UUID id) {
147148
148149 if (kudos .getDateApproved () == null ) {
149150 // If not yet approved, only admins and the sender can access the kudos
150- if (!currentUserServices . isAdmin () && !isSender ) {
151+ if (!hasAdministerKudosPermission () && !isSender ) {
151152 throw new PermissionException (NOT_AUTHORIZED_MSG );
152153 }
153154 } else {
@@ -158,7 +159,7 @@ public KudosResponseDTO getById(UUID id) {
158159 .stream ()
159160 .anyMatch (recipient -> recipient .getMemberId ().equals (currentUserId ));
160161
161- if (!currentUserServices . isAdmin () && !isSender && !isRecipient ) {
162+ if (!hasAdministerKudosPermission () && !isSender && !isRecipient ) {
162163 throw new PermissionException (NOT_AUTHORIZED_MSG );
163164 }
164165 }
@@ -188,7 +189,7 @@ public List<KudosResponseDTO> findByValues(@Nullable UUID recipientId, @Nullable
188189 } else if (senderId != null ) {
189190 return findAllFromMember (senderId );
190191 } else {
191- if (!currentUserServices . isAdmin ()) {
192+ if (!hasAdministerKudosPermission ()) {
192193 throw new PermissionException (NOT_AUTHORIZED_MSG );
193194 }
194195
@@ -207,7 +208,7 @@ public List<KudosResponseDTO> getRecent() {
207208 }
208209
209210 private List <KudosResponseDTO > findByPending (boolean isPending ) {
210- if (!currentUserServices . isAdmin ()) {
211+ if (!hasAdministerKudosPermission ()) {
211212 throw new PermissionException (NOT_AUTHORIZED_MSG );
212213 }
213214
@@ -227,10 +228,10 @@ private List<KudosResponseDTO> findByPending(boolean isPending) {
227228
228229
229230 private List <KudosResponseDTO > findAllToMember (UUID memberId ) {
230- boolean isAdmin = currentUserServices .isAdmin ();
231231 UUID currentUserId = currentUserServices .getCurrentUser ().getId ();
232232
233- if (!currentUserId .equals (memberId ) && !isAdmin ) {
233+ if (!currentUserId .equals (memberId ) &&
234+ !hasAdministerKudosPermission ()) {
234235 throw new PermissionException ("You are not authorized to retrieve the kudos another user has received" );
235236 }
236237
@@ -253,10 +254,10 @@ private List<KudosResponseDTO> findAllToMember(UUID memberId) {
253254
254255 private List <KudosResponseDTO > findAllFromMember (UUID senderId ) {
255256
256- boolean isAdmin = currentUserServices .isAdmin ();
257257 UUID currentUserId = currentUserServices .getCurrentUser ().getId ();
258258
259- if (!currentUserId .equals (senderId ) && !isAdmin ) {
259+ if (!currentUserId .equals (senderId ) &&
260+ !hasAdministerKudosPermission ()) {
260261 throw new PermissionException ("You are not authorized to retrieve the kudos another user has sent" );
261262 }
262263
@@ -378,4 +379,8 @@ private void slackApprovedKudos(Kudos kudos) {
378379 LOG .error ("Unable to POST to Slack: " + httpResponse .reason ());
379380 }
380381 }
382+
383+ private boolean hasAdministerKudosPermission () {
384+ return currentUserServices .hasPermission (Permission .CAN_ADMINISTER_KUDOS );
385+ }
381386}
0 commit comments