I have a hierarchical user structure, so every user has a entity reference field that points to another user - his/her supervisor.
The thing is that I need to give every user the permission to modify/delete the users that are under him/her in the hierarchy but to no one else.
It is a bit more complicated due to the fact that the hierarchy can be quite high, so a user has to be able to modify even users that points to someone (as to their supervisor) who points to him.
I've Googled for quite a few minutes but didn't find any solution whatsoever. I also need to implement it with my module so programmatic approach would be proffered to another module.