parameters: (self)
return_statement: return teams.order_by("access_control", "id")
docstring: All teams the user has access to on any organization, taking into account project based permissioning
docstring_summary: All teams the user has access to on any organization, taking into account project based permissioning
docstring_tokens: All teams the user has access to on any organization taking into account project based permissioning
function: def teams(self):
          """
          All teams the user has access to on any organization, taking into account project based permissioning
          """
          teams = Team.objects.filter(organization__members=self)
          if Organization.objects.filter(
              members=self, available_features__contains=[AvailableFeature.PROJECT_BASED_PERMISSIONING]
          ).exists():
              from ee.models import ExplicitTeamMembership
  
              available_private_project_ids = ExplicitTeamMembership.objects.filter(
                  Q(parent_membership__user=self)
              ).values_list("team_id", flat=True)
              organizations_where_user_is_admin = OrganizationMembership.objects.filter(
                  user=self, level__gte=OrganizationMembership.Level.ADMIN
              ).values_list("organization_id", flat=True)
              # If project access control IS applicable, make sure
              # - project doesn't have access control OR
              # - the user has explicit access OR
              # - the user is Admin or owner
              teams = teams.filter(
                  Q(access_control=False)
                  | Q(pk__in=available_private_project_ids)
                  | Q(organization__pk__in=organizations_where_user_is_admin)
              )
  
          return teams.order_by("access_control", "id")
function_tokens: def teams ( self ) : teams = Team . objects . filter ( organization__members = self ) if Organization . objects . filter ( members = self , available_features__contains = [ AvailableFeature . PROJECT_BASED_PERMISSIONING ] ) . exists ( ) : from ee . models import ExplicitTeamMembership available_private_project_ids = ExplicitTeamMembership . objects . filter ( Q ( parent_membership__user = self ) ) . values_list ( "team_id" , flat = True ) organizations_where_user_is_admin = OrganizationMembership . objects . filter ( user = self , level__gte = OrganizationMembership . Level . ADMIN ) . values_list ( "organization_id" , flat = True ) # If project access control IS applicable, make sure # - project doesn't have access control OR # - the user has explicit access OR # - the user is Admin or owner teams = teams . filter ( Q ( access_control = False ) | Q ( pk__in = available_private_project_ids ) | Q ( organization__pk__in = organizations_where_user_is_admin ) ) return teams . order_by ( "access_control" , "id" )