From 522cf4f6f5976edcd34c8803491b6a96fcbacf13 Mon Sep 17 00:00:00 2001 From: Aliaksei_Harbuz Date: Tue, 17 Sep 2024 13:59:39 +0300 Subject: [PATCH] MODEXPW-488 - update logging --- .../jobs/permissions/check/PermissionsValidator.java | 7 +++++-- .../jobs/permissions/check/PermissionsValidatorTest.java | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/folio/dew/batch/bulkedit/jobs/permissions/check/PermissionsValidator.java b/src/main/java/org/folio/dew/batch/bulkedit/jobs/permissions/check/PermissionsValidator.java index 11bdce4fc..c0cc5bfda 100644 --- a/src/main/java/org/folio/dew/batch/bulkedit/jobs/permissions/check/PermissionsValidator.java +++ b/src/main/java/org/folio/dew/batch/bulkedit/jobs/permissions/check/PermissionsValidator.java @@ -3,6 +3,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.log4j.Log4j2; import org.folio.dew.domain.dto.EntityType; +import org.folio.spring.FolioExecutionContext; import org.springframework.stereotype.Component; @Component @@ -12,11 +13,13 @@ public class PermissionsValidator { private final PermissionsProvider permissionsProvider; private final RequiredPermissionResolver requiredPermissionResolver; + private final FolioExecutionContext folioExecutionContext; public boolean isBulkEditReadPermissionExists(String tenantId, EntityType entityType) { var readPermissionForEntity = requiredPermissionResolver.getReadPermission(entityType); var userPermissions = permissionsProvider.getUserPermissions(tenantId); - log.info("isBulkEditReadPermissionExists:: user permissions {}", userPermissions); - return userPermissions.contains(readPermissionForEntity); + var isReadPermissionsExist = userPermissions.contains(readPermissionForEntity); + log.info("isBulkEditReadPermissionExists:: user {} has read permissions {} for {}", folioExecutionContext.getUserId(), isReadPermissionsExist, entityType); + return isReadPermissionsExist; } } diff --git a/src/test/java/org/folio/dew/batch/bulkedit/jobs/permissions/check/PermissionsValidatorTest.java b/src/test/java/org/folio/dew/batch/bulkedit/jobs/permissions/check/PermissionsValidatorTest.java index 217e7c81c..a9944e932 100644 --- a/src/test/java/org/folio/dew/batch/bulkedit/jobs/permissions/check/PermissionsValidatorTest.java +++ b/src/test/java/org/folio/dew/batch/bulkedit/jobs/permissions/check/PermissionsValidatorTest.java @@ -2,6 +2,7 @@ import org.folio.dew.domain.dto.EntityType; +import org.folio.spring.FolioExecutionContext; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -9,6 +10,7 @@ import org.mockito.junit.jupiter.MockitoExtension; import java.util.List; +import java.util.UUID; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -21,6 +23,9 @@ class PermissionsValidatorTest { private PermissionsProvider permissionsProvider; @Mock private RequiredPermissionResolver requiredPermissionResolver; + @Mock + private FolioExecutionContext folioExecutionContext; + @InjectMocks private PermissionsValidator permissionsValidator; @@ -29,6 +34,7 @@ void testIsBulkEditReadPermissionExists() { when(permissionsProvider.getUserPermissions("tenant1")).thenReturn(List.of("read_permission", "not_read_permission")); when(permissionsProvider.getUserPermissions("tenant2")).thenReturn(List.of("not_read_permission")); when(requiredPermissionResolver.getReadPermission(EntityType.ITEM)).thenReturn("read_permission"); + when(folioExecutionContext.getUserId()).thenReturn(UUID.randomUUID()); assertTrue(permissionsValidator.isBulkEditReadPermissionExists("tenant1", EntityType.ITEM)); assertFalse(permissionsValidator.isBulkEditReadPermissionExists("tenant2", EntityType.ITEM));