(self, user: "User")
Return an effective membership level.
        None returned if the user has no explicit membership and organization access is too low for implicit membership.
Return an effective membership level.
        None returned if the user has no explicit membership and organization access is too low for implicit membership.
Return an effective membership level . None returned if the user has no explicit membership and organization access is too low for implicit membership .
def get_effective_membership_level(self, user: "User") -> Optional["OrganizationMembership.Level"]:
        """Return an effective membership level.
        None returned if the user has no explicit membership and organization access is too low for implicit membership.
        """
        from posthog.models.organization import OrganizationMembership

        try:
            requesting_parent_membership: OrganizationMembership = OrganizationMembership.objects.select_related(
                "organization"
            ).get(organization_id=self.organization_id, user=user)
        except OrganizationMembership.DoesNotExist:
            return None
        if (
            not requesting_parent_membership.organization.is_feature_available(
                AvailableFeature.PROJECT_BASED_PERMISSIONING
            )
            or not self.access_control
        ):
            return requesting_parent_membership.level
        from ee.models import ExplicitTeamMembership

        try:
            return (
                requesting_parent_membership.explicit_team_memberships.only("parent_membership", "level")
                .get(team=self)
                .effective_level
            )
        except ExplicitTeamMembership.DoesNotExist:
            # Only organizations admins and above get implicit project membership
            if requesting_parent_membership.level < OrganizationMembership.Level.ADMIN:
                return None
            return requesting_parent_membership.level
def get_effective_membership_level ( self , user : "User" ) -> Optional [ "OrganizationMembership.Level" ] : from posthog . models . organization import OrganizationMembership try : requesting_parent_membership : OrganizationMembership = OrganizationMembership . objects . select_related ( "organization" ) . get ( organization_id = self . organization_id , user = user ) except OrganizationMembership . DoesNotExist : return None if ( not requesting_parent_membership . organization . is_feature_available ( AvailableFeature . PROJECT_BASED_PERMISSIONING ) or not self . access_control ) : return requesting_parent_membership . level from ee . models import ExplicitTeamMembership try : return ( requesting_parent_membership . explicit_team_memberships . only ( "parent_membership" , "level" ) . get ( team = self ) . effective_level ) except ExplicitTeamMembership . DoesNotExist : # Only organizations admins and above get implicit project membership if requesting_parent_membership . level < OrganizationMembership . Level . ADMIN : return None return requesting_parent_membership . level