-
Notifications
You must be signed in to change notification settings - Fork 0
Homogenize permissions checks #215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…neffective on count
Signed-off-by: David BRAQUART <[email protected]>
There was a problem hiding this 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() | ||
)); | ||
} |
There was a problem hiding this comment.
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()
));
There was a problem hiding this comment.
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
…ubDirectoriesCounts
|
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()))) |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
No description provided.