Skip to content

Conversation

Meklo
Copy link
Contributor

@Meklo Meklo commented Oct 6, 2025

No description provided.

@Meklo Meklo requested a review from TheMaskedTurtle October 7, 2025 13:32
@dbraquart dbraquart self-requested a review October 9, 2025 18:44
Signed-off-by: David BRAQUART <[email protected]>
Copy link
Contributor

@dbraquart dbraquart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code: ok, just a suggestion made
tests: ok, works fine. I added a unit test for the issue

DirectoryElementRepository.ElementParentage::getParentId,
Collectors.counting()
));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can do differently: rather than finding all children in N directories (each child will be checked by checking its parent directory), we could first eliminate the non-readable dirs among the N, and then retrieve the children ?
Ex:

List<UUID> readableSubDirectories = subDirectories.stream().filter(dirId -> checkPermission(userId, List.of(dirId), READ)).toList();
return repositoryService.findAllByParentIdInAndTypeIn(readableSubDirectories, types).stream()
        .collect(Collectors.groupingBy(
                DirectoryElementRepository.ElementParentage::getParentId,
                Collectors.counting()
        ));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In our current uses cases it might be a bit overkill because we already check directories permissions in functions calling getSubDirectoriesCounts but I reckon it's still worth because by adding it here too we're avoiding future permissions mistakes related to it if it gets involved in new use cases

Copy link

@Meklo Meklo requested a review from dbraquart October 10, 2025 09:00
return repositoryService.findAllByParentIdInAndTypeIn(subDirectories, types).stream()
List<UUID> readableSubDirectories = subDirectories.stream().filter(dirId -> hasReadPermissions(userId, List.of(dirId))).toList();
return repositoryService.findAllByParentIdInAndTypeIn(readableSubDirectories, types).stream()
.filter(child -> hasReadPermissions(userId, List.of(child.getId())))
Copy link
Contributor

@dbraquart dbraquart Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All children are in readable dirs, so we dont need to check (their parent dir) anymore.
Or maybe we have to filter/check in case the child is a sub-dir ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ye a subdirectory can be read protected while its parent isn't so I don't think we can bypass this check

@Meklo Meklo merged commit 3ffad38 into main Oct 10, 2025
4 checks passed
@Meklo Meklo deleted the fix/homogenize_permissions_checks branch October 10, 2025 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants