'Return a unique list of Roles associated with this user or any of their groups.'

def all_roles(self):

    try:
        db_session = object_session(self)
        user = db_session.query(User).filter_by(id=self.id).options(joinedload('roles'), joinedload('roles.role'), joinedload('groups'), joinedload('groups.group'), joinedload('groups.group.roles'), joinedload('groups.group.roles.role')).one()
    except Exception:
        user = self
    roles = [ura.role for ura in user.roles]
    for group in [uga.group for uga in user.groups]:
        for role in [gra.role for gra in group.roles]:
            if (role not in roles):
                roles.append(role)
    return roles
