Apply ACL restriction filters for a search query

This logic is not really complicated, but I think this should be extracted and made reusable across the app.