mirror of
https://github.com/peeringdb/peeringdb.git
synced 2024-05-11 05:55:09 +00:00
* Add check for existing pending affiliations to org * Fix message * 883 consolidation for deskpro tickets * add views tests * ipaddress normalization during search (#913) * remove unused imports * Update lat and long admin fields to not required * black formatting * relock pipfile * fix conditions for failing asn affil test * Update affiliation logic and add tests * make name search case insensitive * add asn to org_id lookup * black format * skip sync test while test.peeringdb.com is down Co-authored-by: Elliot Frank <elliot@20c.com> Co-authored-by: Stefan Pratter <stefan@20c.com>
66 lines
2.0 KiB
Python
66 lines
2.0 KiB
Python
import ipaddress
|
|
from decimal import Decimal
|
|
|
|
from grainy.const import *
|
|
from grainy.core import NamespaceKeyApplicator
|
|
from django.conf import settings
|
|
from django_grainy.const import *
|
|
from django_grainy.util import get_permissions, check_permissions, Permissions
|
|
|
|
|
|
def round_decimal(value, places):
|
|
if value is not None:
|
|
return value.quantize(Decimal(10) ** -places)
|
|
return value
|
|
|
|
|
|
def coerce_ipaddr(value):
|
|
"""
|
|
ipaddresses can have multiple formats that are equivalent.
|
|
This function will standardize a ipaddress string.
|
|
|
|
Note: this function is not a validator. If it errors
|
|
It will return the original string.
|
|
"""
|
|
try:
|
|
value = str(ipaddress.ip_address(value))
|
|
except ValueError:
|
|
pass
|
|
return value
|
|
|
|
|
|
class APIPermissionsApplicator(NamespaceKeyApplicator):
|
|
@property
|
|
def is_generating_api_cache(self):
|
|
try:
|
|
return getattr(settings, "GENERATING_API_CACHE", False)
|
|
except IndexError:
|
|
return False
|
|
|
|
def __init__(self, user):
|
|
super().__init__(None)
|
|
self.permissions = Permissions(user)
|
|
self.pset = self.permissions
|
|
self.set_peeringdb_handlers()
|
|
|
|
if self.is_generating_api_cache:
|
|
self.drop_namespace_key = False
|
|
|
|
def set_peeringdb_handlers(self):
|
|
self.handler(
|
|
"peeringdb.organization.*.network.*.poc_set.private", explicit=True
|
|
)
|
|
self.handler("peeringdb.organization.*.network.*.poc_set.users", explicit=True)
|
|
self.handler(
|
|
"peeringdb.organization.*.internetexchange.*", fn=self.handle_ixlan
|
|
)
|
|
|
|
def handle_ixlan(self, namespace, data):
|
|
if "ixf_ixp_member_list_url" in data:
|
|
visible = data["ixf_ixp_member_list_url_visible"].lower()
|
|
_namespace = f"{namespace}.ixf_ixp_member_list_url.{visible}"
|
|
|
|
perms = self.permissions.check(_namespace, 0x01, explicit=True)
|
|
if not perms:
|
|
del data["ixf_ixp_member_list_url"]
|