Skip to content

Commit

Permalink
Fix restore when access rights is null (#118)
Browse files Browse the repository at this point in the history
Signed-off-by: Seddik Yengui <seddik.yengui@rte-france.com>
  • Loading branch information
YenguiSeddik authored Mar 5, 2024
1 parent bb06425 commit ee232d8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,8 @@ private List<DirectoryElementEntity> getEntitiesToRestore(List<DirectoryElementE

return entities.stream()
.filter(entity -> {
boolean isUpdatable = Objects.equals(userId, entity.getOwner()) || !entity.getIsPrivate();
boolean isPublicElement = entity.getIsPrivate() == null && !getParentElement(entity.getId()).getAccessRights().isPrivate() || !entity.getIsPrivate();
boolean isUpdatable = Objects.equals(userId, entity.getOwner()) || isPublicElement;
if (!isUpdatable) {
rejectedEntities.add(entity);
}
Expand All @@ -603,6 +604,9 @@ private List<DirectoryElementEntity> getEntitiesToRestore(List<DirectoryElementE
public void restoreElements(List<UUID> elementsUuid, UUID parentUuid, String userId) {
// Get parent directory
ElementAttributes parent = getElement(parentUuid);
if (parent == null) {
throw new DirectoryException(NOT_FOUND, String.format("The directory '%s' not found !", parentUuid));
}

// Get all updatable entities. Entities should be public or created by the user, so it can be restored
List<DirectoryElementEntity> notUpdatableEntities = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ interface SubDirectoryCount {
@Query("SELECT e FROM DirectoryElementEntity e " +
"WHERE e.id IN :uuids " +
"AND e.stashed = :stashed " +
"AND (e.owner = :userId OR e.isPrivate = false)")
"AND (e.owner = :userId OR e.isPrivate = false OR (e.isPrivate IS NULL AND NOT EXISTS (SELECT 1 FROM DirectoryElementEntity parent WHERE parent.id = e.parentId AND parent.isPrivate = true)))")
List<DirectoryElementEntity> findAllStashedElements(@Param("uuids") List<UUID> uuids,
@Param("stashed") boolean stashed,
@Param("userId") String userId);
Expand Down

0 comments on commit ee232d8

Please sign in to comment.