code: def get_user_roles(user):
      
      if user:
          groups = user.groups.all()   # Important! all() query may be cached on User with prefetch_related.
          roles = (RolesManager.retrieve_role(group.name) for group in groups if group.name in RolesManager.get_roles_names())
          return sorted(roles, key=lambda r: r.get_name() )
      else:
          return []
docs: Get a list of a users's roles.