Skip to content

Commit

Permalink
MODEXPW-488 - update logging
Browse files Browse the repository at this point in the history
  • Loading branch information
alekGbuz committed Sep 17, 2024
1 parent 7b8270f commit 522cf4f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@


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;
import org.mockito.Mock;
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;
Expand All @@ -21,6 +23,9 @@ class PermissionsValidatorTest {
private PermissionsProvider permissionsProvider;
@Mock
private RequiredPermissionResolver requiredPermissionResolver;
@Mock
private FolioExecutionContext folioExecutionContext;

@InjectMocks
private PermissionsValidator permissionsValidator;

Expand All @@ -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));
Expand Down

0 comments on commit 522cf4f

Please sign in to comment.