'Returns a list of all teams a user has some level of access to.'

def get_for_user(self, organization, user, scope=None, with_projects=False):

    from sentry.models import OrganizationMemberTeam, Project, ProjectStatus, OrganizationMember
    if (not user.is_authenticated()):
        return []
    base_team_qs = self.filter(organization=organization, status=TeamStatus.VISIBLE)
    if ((env.request and env.request.is_superuser()) or settings.SENTRY_PUBLIC):
        team_list = list(base_team_qs)
    else:
        try:
            om = OrganizationMember.objects.get(user=user, organization=organization)
        except OrganizationMember.DoesNotExist:
            return []
        if ((scope is not None) and (scope not in om.get_scopes())):
            return []
        team_list = list(base_team_qs.filter(id__in=OrganizationMemberTeam.objects.filter(organizationmember=om, is_active=True).values_list('team')))
    results = sorted(team_list, key=(lambda x: x.name.lower()))
    if with_projects:
        project_list = sorted(Project.objects.filter(team__in=team_list, status=ProjectStatus.VISIBLE), key=(lambda x: x.name.lower()))
        projects_by_team = {t.id: [] for t in team_list}
        for project in project_list:
            projects_by_team[project.team_id].append(project)
        for (idx, team) in enumerate(results):
            team_projects = projects_by_team[team.id]
            for project in team_projects:
                project.team = team
            results[idx] = (team, team_projects)
    return results
