Skip to content

Commit

Permalink
Bugfix: rename access control attributes for search engine (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zorin95670 authored Mar 29, 2024
2 parents 55cf87f + 8247cc4 commit 0517d8f
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 42 deletions.
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3'

services:
libraries:
image: nginx:latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,8 @@ public Response getGroupsOfRole(final @Context HttpServletRequest request,
userPermissionService.checkIsAdmin(user, null);

Map<String, String> filters = new HashMap<>(this.getFilters(uriInfo));
filters.put("parentAccessControlId", id.toString());
filters.put("parentAccessControlType", AccessControlType.ROLE.name());
filters.put("parentId", id.toString());
filters.put("parentType", AccessControlType.ROLE.name());

log.info(
"[{}] Received GET request to get groups of role {} with the following filters: {}",
Expand Down Expand Up @@ -658,8 +658,8 @@ public Response getScopesOfRole(final @Context HttpServletRequest request,
userPermissionService.checkIsAdmin(user, null);

Map<String, String> filters = new HashMap<>(this.getFilters(uriInfo));
filters.put("parentAccessControlId", id.toString());
filters.put("parentAccessControlType", AccessControlType.ROLE.name());
filters.put("parentId", id.toString());
filters.put("parentType", AccessControlType.ROLE.name());

log.info(
"[{}] Received GET request to get scopes of role {} with the following filters: {}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public AccessControlDirectDTO apply(final AccessControlTreeView accessControlTre
AccessControlDirectDTO dto = new AccessControlDirectDTO();

if (this.fromParent) {
dto.setId(accessControlTreeView.getParentAccessControlId());
dto.setName(accessControlTreeView.getParentAccessControlName());
dto.setId(accessControlTreeView.getParentId());
dto.setName(accessControlTreeView.getParentName());
} else {
dto.setId(accessControlTreeView.getAccessControlId());
dto.setName(accessControlTreeView.getAccessControlName());
dto.setId(accessControlTreeView.getId());
dto.setName(accessControlTreeView.getName());
}

dto.setIsDirect(accessControlTreeView.getIsDirect());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,50 +29,50 @@ public class AccessControlTreeView {
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "aca_id")
@FilterType(type = FilterType.Type.TEXT)
private String id;
private String internalId;

/**
* Identifier of the current access control.
* This field represents the current node in the access control tree structure.
*/
@Column(name = "aco_id")
@FilterType(type = FilterType.Type.UUID)
private UUID accessControlId;
private UUID id;

/**
* Type of the current access control.
*/
@Column(name = "type")
@FilterType(type = FilterType.Type.TEXT)
private String accessControlType;
private String type;

/**
* Name of the current access control.
*/
@Column(name = "name")
@FilterType(type = FilterType.Type.TEXT)
private String accessControlName;
private String name;

/**
* Identifier of the parent access control in the tree structure.
*/
@Column(name = "parent")
@FilterType(type = FilterType.Type.UUID)
private UUID parentAccessControlId;
private UUID parentId;

/**
* Name of the parent access control.
*/
@Column(name = "parent_name")
@FilterType(type = FilterType.Type.TEXT)
private String parentAccessControlName;
private String parentName;

/**
* Type of the parent access control.
*/
@Column(name = "parent_type")
@FilterType(type = FilterType.Type.TEXT)
private String parentAccessControlType;
private String parentType;

/**
* Indicates whether the access control relationship is direct.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class UserAccessControlView {
/**
* The name of the access control.
*/
@Column(name = "access_control_name")
@Column(name = "name")
@FilterType(type = FilterType.Type.TEXT)
private String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ public interface AccessControlTreeViewRepository extends JpaRepository<AccessCon
* @return an {@link Optional} containing the found {@link AccessControlTreeView} entity, or an empty Optional
* if no entity matches the provided IDs.
*/
Optional<AccessControlTreeView> findByAccessControlIdAndParentAccessControlId(UUID id, UUID parent);
Optional<AccessControlTreeView> findByIdAndParentId(UUID id, UUID parent);
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@ public Page<AccessControlDirectDTO> findAllChildren(final AccessControlType type
AccessControl accessControl = findById(type, id);
Map<String, String> filters = new HashMap<>(immutableFilters);
filters.put("type", childrenType.name());
filters.put("parentAccessControlId", accessControl.getId().toString());
filters.put("parentId", accessControl.getId().toString());

return accessControlTreeViewRepository.findAll(
new SpecificationHelper<>(AccessControlTreeView.class, filters),
PageRequest.of(
pageable.getPageNumber(),
pageable.getPageSize(),
pageable.getSortOr(Sort.by(Sort.Direction.ASC, "parentAccessControlName"))
pageable.getSortOr(Sort.by(Sort.Direction.ASC, "parentName"))
)
).map(new AccessControlTreeViewToAccessControlDirectDTOFunction(false));
}
Expand Down Expand Up @@ -180,14 +180,14 @@ public Page<AccessControlDirectDTO> findAllAccessControls(final AccessControlTyp
final Pageable pageable) {
AccessControl accessControl = this.findById(type, id);
Map<String, String> filters = new HashMap<>(immutableFilters);
filters.put("accessControlId", accessControl.getId().toString());
filters.put("parentAccessControlType", subType.name());
filters.put("id", accessControl.getId().toString());
filters.put("parentType", subType.name());

return accessControlTreeViewRepository.findAll(new SpecificationHelper<>(AccessControlTreeView.class, filters),
PageRequest.of(
pageable.getPageNumber(),
pageable.getPageSize(),
pageable.getSortOr(Sort.by(Sort.Direction.ASC, "parentAccessControlName")))
pageable.getSortOr(Sort.by(Sort.Direction.ASC, "parentName")))
).map(new AccessControlTreeViewToAccessControlDirectDTOFunction());
}

Expand Down Expand Up @@ -230,7 +230,7 @@ public void associate(final AccessControlType parentType,
AccessControl parentAccessControl = findById(parentType, id);
AccessControl accessControl = findById(type, roleId);
Optional<AccessControlTreeView> userAccessControlOptional = accessControlTreeViewRepository
.findByAccessControlIdAndParentAccessControlId(parentAccessControl.getId(), accessControl.getId());
.findByIdAndParentId(parentAccessControl.getId(), accessControl.getId());

if (userAccessControlOptional.isPresent()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ SELECT DISTINCT
users.email,
users.name as "user_name",
access_controls.aco_id,
access_controls.name as "access_control_name",
access_controls.name as "name",
access_controls.type::text,
not all_access_controls.direct as "direct"
FROM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ class AccessControlTreeViewToAccessControlDirectDTOFunctionTest {
@DisplayName("Test apply: should transform AccessControlTreeView to AccessControlDirectDTO with parent")
void testApply() {
AccessControlTreeView accessControlTreeView = new AccessControlTreeView();
accessControlTreeView.setAccessControlId(UUID.randomUUID());
accessControlTreeView.setAccessControlName("current");
accessControlTreeView.setAccessControlType("current_Type");
accessControlTreeView.setParentAccessControlId(UUID.randomUUID());
accessControlTreeView.setParentAccessControlName("parent");
accessControlTreeView.setParentAccessControlType("parent_type");
accessControlTreeView.setId(UUID.randomUUID());
accessControlTreeView.setName("current");
accessControlTreeView.setType("current_Type");
accessControlTreeView.setParentId(UUID.randomUUID());
accessControlTreeView.setParentName("parent");
accessControlTreeView.setParentType("parent_type");
accessControlTreeView.setIsDirect(true);

AccessControlDirectDTO accessControl = new AccessControlTreeViewToAccessControlDirectDTOFunction()
.apply(accessControlTreeView);

assertEquals(accessControlTreeView.getParentAccessControlId(), accessControl.getId());
assertEquals(accessControlTreeView.getParentId(), accessControl.getId());
assertEquals("parent", accessControl.getName());
assertTrue(accessControl.getIsDirect());
}
Expand All @@ -39,18 +39,18 @@ void testApply() {
@DisplayName("Test apply: should transform AccessControlTreeView to AccessControlDirectDTO with current")
void testApplyNotFromParent() {
AccessControlTreeView accessControlTreeView = new AccessControlTreeView();
accessControlTreeView.setAccessControlId(UUID.randomUUID());
accessControlTreeView.setAccessControlName("current");
accessControlTreeView.setAccessControlType("current_Type");
accessControlTreeView.setParentAccessControlId(UUID.randomUUID());
accessControlTreeView.setParentAccessControlName("parent");
accessControlTreeView.setParentAccessControlType("parent_type");
accessControlTreeView.setId(UUID.randomUUID());
accessControlTreeView.setName("current");
accessControlTreeView.setType("current_Type");
accessControlTreeView.setParentId(UUID.randomUUID());
accessControlTreeView.setParentName("parent");
accessControlTreeView.setParentType("parent_type");
accessControlTreeView.setIsDirect(true);

AccessControlDirectDTO accessControl = new AccessControlTreeViewToAccessControlDirectDTOFunction(false)
.apply(accessControlTreeView);

assertEquals(accessControlTreeView.getAccessControlId(), accessControl.getId());
assertEquals(accessControlTreeView.getId(), accessControl.getId());
assertEquals("current", accessControl.getName());
assertTrue(accessControl.getIsDirect());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ void testAssociate() {
.when(accessControlRepository.findOne(Mockito.any(Specification.class)))
.thenReturn(Optional.of(accessControl));
Mockito
.when(accessControlTreeViewRepository.findByAccessControlIdAndParentAccessControlId(Mockito.any(), Mockito.any()))
.when(accessControlTreeViewRepository.findByIdAndParentId(Mockito.any(), Mockito.any()))
.thenReturn(Optional.empty());

service.associate(AccessControlType.ROLE, UUID.randomUUID(), AccessControlType.ROLE, UUID.randomUUID());
Expand All @@ -379,7 +379,7 @@ void testAssociateDoNothing() {
.when(accessControlRepository.findOne(Mockito.any(Specification.class)))
.thenReturn(Optional.of(accessControl));
Mockito
.when(accessControlTreeViewRepository.findByAccessControlIdAndParentAccessControlId(Mockito.any(), Mockito.any()))
.when(accessControlTreeViewRepository.findByIdAndParentId(Mockito.any(), Mockito.any()))
.thenReturn(Optional.of(new AccessControlTreeView()));
ApiException exception = null;

Expand Down

0 comments on commit 0517d8f

Please sign in to comment.