Fixed a bug in the permissions system where nested groups weren't
working as expected under certain conditions and added protection
against recursively nested groups.