def _get_permission_set_tree(user):
if hasattr(user, CACHED_PSET_PROPERTY_KEY):<EOL><INDENT>return getattr(user, CACHED_PSET_PROPERTY_KEY)<EOL><DEDENT>if user.is_authenticated():<EOL><INDENT>try:<EOL><INDENT>return user.permissionset.first().tree()<EOL><DEDENT>except AttributeError:<EOL><INDENT>raise ObjectDoesNotExist<EOL><DEDENT><DEDENT>return PermissionSet.objects.get(anonymous_user=True).tree()<EOL>
Helper to return cached permission set tree from user instance if set, else
generates and returns analyzed permission set tree. Does not cache set
automatically, that must be done explicitely.