mirror of
https://github.com/peeringdb/peeringdb.git
synced 2024-05-11 05:55:09 +00:00
Prep 2.29 (#1024)
* django3, py39, lgtm, linting (#715) * IX-F Importer: ticket status change when posting re-occuring conflict to existing resolved ticket (#920) * fix recaptcha requirement for user creation in django-admin (#715) * IX-F Importer: fix command output buffering #967 * Drop dot1q_support field #903 * fix test (#967) * Add name, city, country to ixfac (GET operation) #166 * additional tests fir #166 * Allow IXP to trigger ix-f importer for their exchange #779 * add docker compose for dev * add selinux labels for mountpoints * fixes #1013: The process to permanently remove old soft-deleted network contacts pdb_delete_pocs raises a false ProtectedAction * fix api test * relock poetry * remove django_namespace_perms from installed apps * fix user permissios ui * remove remaining references to django namespace perms * linting * copy tox.ini * comment flake8 check until we figure out why it ignores configs from tox.ini * black format * poetry lock Co-authored-by: Stefan Pratter <stefan@20c.com>
This commit is contained in:
@@ -1,26 +1,23 @@
|
||||
import ipaddress
|
||||
import re
|
||||
|
||||
import reversion
|
||||
from django.conf import settings
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.exceptions import FieldError, ValidationError
|
||||
from django.core.validators import URLValidator
|
||||
from django.db import IntegrityError, models, transaction
|
||||
from django.db.models import Case, IntegerField, Prefetch, Q, Sum, When
|
||||
from django.db.models import Prefetch
|
||||
from django.db.models.expressions import RawSQL
|
||||
from django.db.models.fields.related import (
|
||||
ForwardManyToOneDescriptor,
|
||||
ReverseManyToOneDescriptor,
|
||||
)
|
||||
from django.db.models.query import QuerySet
|
||||
from django.http import JsonResponse
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django_grainy.rest import PermissionDenied
|
||||
|
||||
# from drf_toolbox import serializers
|
||||
from django_handleref.rest.serializers import HandleRefSerializer
|
||||
from django_inet.rest import IPAddressField, IPPrefixField
|
||||
from django_inet.rest import IPAddressField, IPNetworkField
|
||||
from django_peeringdb.models.abstract import AddressModel
|
||||
from rest_framework import serializers, validators
|
||||
from rest_framework.exceptions import ValidationError as RestValidationError
|
||||
@@ -32,7 +29,6 @@ from peeringdb_server.deskpro import (
|
||||
from peeringdb_server.inet import (
|
||||
RdapException,
|
||||
RdapLookup,
|
||||
RdapNotFoundError,
|
||||
get_prefix_protocol,
|
||||
rdap_pretty_error_message,
|
||||
)
|
||||
@@ -49,7 +45,6 @@ from peeringdb_server.models import (
|
||||
NetworkFacility,
|
||||
NetworkIXLan,
|
||||
Organization,
|
||||
OrganizationAPIKey,
|
||||
VerificationQueueItem,
|
||||
)
|
||||
from peeringdb_server.permissions import (
|
||||
@@ -487,7 +482,7 @@ class AsnRdapValidator:
|
||||
asn = attrs.get(self.field)
|
||||
try:
|
||||
rdap = RdapLookup().get_asn(asn)
|
||||
emails = rdap.emails
|
||||
rdap.emails
|
||||
self.request.rdap_result = rdap
|
||||
except RdapException as exc:
|
||||
self.request.rdap_error = (asn, exc)
|
||||
@@ -554,14 +549,14 @@ class ParentStatusException(IOError):
|
||||
|
||||
def __init__(self, parent, typ):
|
||||
if parent.status == "pending":
|
||||
super(IOError, self).__init__(
|
||||
super().__init__(
|
||||
_(
|
||||
"Object of type '%(type)s' cannot be created because its parent entity '%(parent_tag)s/%(parent_id)s' has not yet been approved"
|
||||
)
|
||||
% {"type": typ, "parent_tag": parent.ref_tag, "parent_id": parent.id}
|
||||
)
|
||||
elif parent.status == "deleted":
|
||||
super(IOError, self).__init__(
|
||||
super().__init__(
|
||||
_(
|
||||
"Object of type '%(type)s' cannot be created because its parent entity '%(parent_tag)s/%(parent_id)s' has been marked as deleted"
|
||||
)
|
||||
@@ -961,8 +956,7 @@ class ModelSerializer(serializers.ModelSerializer):
|
||||
|
||||
else:
|
||||
# sub element
|
||||
l = self.in_list
|
||||
if l:
|
||||
if self.in_list:
|
||||
# sub element in set
|
||||
if d < j:
|
||||
return_full = False
|
||||
@@ -1196,7 +1190,7 @@ class ModelSerializer(serializers.ModelSerializer):
|
||||
# if field can't be nulled this will
|
||||
# fail and raise the original error
|
||||
instance.save()
|
||||
except:
|
||||
except Exception:
|
||||
raise exc
|
||||
|
||||
rv = super().run_validation(data=data)
|
||||
@@ -1243,15 +1237,12 @@ class ModelSerializer(serializers.ModelSerializer):
|
||||
|
||||
def finalize_create(self, request):
|
||||
"""this will be called on the end of POST request to this serializer"""
|
||||
pass
|
||||
|
||||
def finalize_update(self, request):
|
||||
"""this will be called on the end of PUT request to this serializer"""
|
||||
pass
|
||||
|
||||
def finalize_delete(self, request):
|
||||
"""this will be called on the end of DELETE request to this serializer"""
|
||||
pass
|
||||
|
||||
|
||||
class RequestAwareListSerializer(serializers.ListSerializer):
|
||||
@@ -1628,6 +1619,10 @@ class InternetExchangeFacilitySerializer(ModelSerializer):
|
||||
ix = serializers.SerializerMethodField()
|
||||
fac = serializers.SerializerMethodField()
|
||||
|
||||
name = serializers.SerializerMethodField()
|
||||
country = serializers.SerializerMethodField()
|
||||
city = serializers.SerializerMethodField()
|
||||
|
||||
def validate_create(self, data):
|
||||
# we don't want users to be able to create ixfacs if the parent
|
||||
# ix or fac status is pending or deleted
|
||||
@@ -1641,6 +1636,9 @@ class InternetExchangeFacilitySerializer(ModelSerializer):
|
||||
model = InternetExchangeFacility
|
||||
fields = [
|
||||
"id",
|
||||
"name",
|
||||
"city",
|
||||
"country",
|
||||
"ix_id",
|
||||
"ix",
|
||||
"fac_id",
|
||||
@@ -1661,7 +1659,18 @@ class InternetExchangeFacilitySerializer(ModelSerializer):
|
||||
|
||||
@classmethod
|
||||
def prepare_query(cls, qset, **kwargs):
|
||||
return qset.select_related("ix", "ix__org"), {}
|
||||
qset = qset.select_related("ix", "ix__org", "facility")
|
||||
|
||||
filters = get_relation_filters(["name", "country", "city"], cls, **kwargs)
|
||||
for field, e in list(filters.items()):
|
||||
for valid in ["name", "country", "city"]:
|
||||
if validate_relation_filter_field(field, valid):
|
||||
fn = getattr(cls.Meta.model, "related_to_%s" % valid)
|
||||
field = f"facility__{valid}"
|
||||
qset = fn(qset=qset, field=field, **e)
|
||||
break
|
||||
|
||||
return qset, filters
|
||||
|
||||
def get_ix(self, inst):
|
||||
return self.sub_serializer(InternetExchangeSerializer, inst.ix)
|
||||
@@ -1669,6 +1678,15 @@ class InternetExchangeFacilitySerializer(ModelSerializer):
|
||||
def get_fac(self, inst):
|
||||
return self.sub_serializer(FacilitySerializer, inst.facility)
|
||||
|
||||
def get_name(self, inst):
|
||||
return inst.facility.name
|
||||
|
||||
def get_country(self, inst):
|
||||
return inst.facility.country
|
||||
|
||||
def get_city(self, inst):
|
||||
return inst.facility.city
|
||||
|
||||
|
||||
class NetworkContactSerializer(ModelSerializer):
|
||||
"""
|
||||
@@ -1869,7 +1887,7 @@ class NetworkIXLanSerializer(ModelSerializer):
|
||||
try:
|
||||
net = Network.objects.get(id=data.get("net_id"))
|
||||
data["asn"] = net.asn
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
return super().run_validation(data=data)
|
||||
|
||||
@@ -2042,7 +2060,7 @@ class NetworkFacilitySerializer(ModelSerializer):
|
||||
try:
|
||||
net = Network.objects.get(id=data.get("net_id"))
|
||||
data["local_asn"] = net.asn
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
return super().run_validation(data=data)
|
||||
|
||||
@@ -2282,7 +2300,7 @@ class NetworkSerializer(ModelSerializer):
|
||||
|
||||
def create(self, validated_data):
|
||||
request = self._context.get("request")
|
||||
user = request.user
|
||||
request.user
|
||||
|
||||
asn = validated_data.get("asn")
|
||||
|
||||
@@ -2357,7 +2375,7 @@ class IXLanPrefixSerializer(ModelSerializer):
|
||||
|
||||
ixlan = serializers.SerializerMethodField()
|
||||
|
||||
prefix = IPPrefixField(
|
||||
prefix = IPNetworkField(
|
||||
validators=[
|
||||
validators.UniqueValidator(queryset=IXLanPrefix.objects.all()),
|
||||
validate_address_space,
|
||||
@@ -2419,7 +2437,7 @@ class IXLanPrefixSerializer(ModelSerializer):
|
||||
|
||||
# validate prefix against selected protocol
|
||||
#
|
||||
# Note: While the IPPrefixField already has this validator set on it
|
||||
# Note: While the IPNetworkField already has this validator set on it
|
||||
# there is no good way to set the field's version from the protocol
|
||||
# specified in the rest data at this point, so we instead opt to validate
|
||||
# it again here.
|
||||
@@ -2442,7 +2460,7 @@ class IXLanPrefixSerializer(ModelSerializer):
|
||||
# to actively set it to `False` let them know it is no
|
||||
# longer supported
|
||||
|
||||
if self.initial_data.get("in_dfz", True) == False:
|
||||
if self.initial_data.get("in_dfz", True) is False:
|
||||
raise serializers.ValidationError(
|
||||
_(
|
||||
"The `in_dfz` property has been deprecated "
|
||||
@@ -2468,6 +2486,8 @@ class IXLanSerializer(ModelSerializer):
|
||||
- ix_id, handled by serializer
|
||||
"""
|
||||
|
||||
dot1q_support = serializers.SerializerMethodField()
|
||||
|
||||
ix_id = serializers.PrimaryKeyRelatedField(
|
||||
queryset=InternetExchange.objects.all(), source="ix"
|
||||
)
|
||||
@@ -2528,6 +2548,11 @@ class IXLanSerializer(ModelSerializer):
|
||||
def get_ix(self, inst):
|
||||
return self.sub_serializer(InternetExchangeSerializer, inst.ix)
|
||||
|
||||
def get_dot1q_support(self, inst):
|
||||
# as per #903 this should always return false as the field
|
||||
# is now deprecated
|
||||
return False
|
||||
|
||||
def validate(self, data):
|
||||
# Per issue 846
|
||||
if data["ixf_ixp_member_list_url"] == "" and data["ixf_ixp_import_enabled"]:
|
||||
@@ -2582,7 +2607,7 @@ class InternetExchangeSerializer(ModelSerializer):
|
||||
# creation. It will be a required field during `POST` requests
|
||||
# but will be ignored during `PUT` so we cannot just do
|
||||
# required=True here
|
||||
prefix = IPPrefixField(
|
||||
prefix = IPNetworkField(
|
||||
validators=[
|
||||
validators.UniqueValidator(
|
||||
queryset=IXLanPrefix.objects.filter(status__in=["ok", "pending"])
|
||||
@@ -2636,6 +2661,8 @@ class InternetExchangeSerializer(ModelSerializer):
|
||||
"fac_count",
|
||||
"ixf_net_count",
|
||||
"ixf_last_import",
|
||||
"ixf_import_request",
|
||||
"ixf_import_request_status",
|
||||
"service_level",
|
||||
"terms",
|
||||
] + HandleRefSerializer.Meta.fields
|
||||
|
||||
Reference in New Issue
Block a user