1
0
mirror of https://github.com/peeringdb/peeringdb.git synced 2024-05-11 05:55:09 +00:00

June updates (#751)

* Add pointer from API docs to tutorial #650

* Sorting by clicking table headers should use local-compare #356

* Mark IXP peering LAN as bogon #352

* Add help text to "Add (Facility, Network, Exchange)" tab #669

* Add Looking Glass field to the IX object #672

* Add read-only Superuser #679

* Make spelling of traffic levels consistent #519 (#723)

* Offer 2FA (#290)

* Show "Last Updated" fields on fac, ix, org records (#526)

* Enable sort and reverse sort of IP column in IX display (#72)

* IRR validation not handling unexpected characters gracefully (#712)

* Support alternative direction of writing, e.g. Arabic (#618)

* Undeleting an ixlan with an emtpy IPv4 XOR IPv6 field throws a silly error (#644)

* Changing org while adding net results in 500 #654

* missing delete button for organisations (#121)

* When changing owner of an ix admin GUI borks because of "Ixlan for exchange already exists" #666

* Selection should only present undeleted objects (#664)

* change default encoding of API calls to 'utf-8' #663

* Posting https://www.peeringdb.com onto social media doesn't select a good preview image #537

* Revert "Add Looking Glass field to the IX object #672"

This reverts commit 4daf2520043c241fabe9a521757efa86a274e28a.

Conflicts:
	peeringdb_server/migrations/0037_ix_looking_glass.py
	peeringdb_server/views.py

* 500 Internal Error when creating IX where prefix already exists elsewhere #718

* Fix graceful restore of soft-deleted objects with translation active (#580)

* Don't return any POC data with status=deleted #569
Hard delete soft-deleted pocs after grace period #566

* django-peeringdb from github@2.0.0.2-beta

Co-authored-by: Stefan Pratter <stefan@20c.com>
This commit is contained in:
Matt Griswold
2020-06-24 12:55:01 -05:00
committed by GitHub
parent 09b4759b02
commit af6974e3d3
60 changed files with 1797 additions and 336 deletions

View File

@ -15,6 +15,7 @@ from django.contrib.auth import forms
from django.contrib.admin import helpers
from django.contrib.admin.actions import delete_selected
from django.contrib.admin.views.main import ChangeList
from django.http import HttpResponseForbidden
from django import forms as baseForms
from django.utils import html
from django.core.exceptions import ValidationError
@ -72,9 +73,17 @@ delete_selected.short_description = "HARD DELETE - Proceed with caution"
from django.utils.translation import ugettext_lazy as _
# def _(x):
# return x
# these app labels control permissions for the views
# currently exposed in admin
PERMISSION_APP_LABELS = [
"peeringdb_server",
"socialaccount",
"sites",
"auth",
"account",
"oauth2_provider"
]
class StatusFilter(admin.SimpleListFilter):
"""
@ -131,7 +140,8 @@ def fk_handleref_filter(form, field, tag=None):
except Exception:
pass
form.fields[field].queryset = qset
if field in form.fields:
form.fields[field].queryset = qset
###############################################################################
@ -415,7 +425,7 @@ class IXLanInline(SanitizedAdmin, admin.StackedInline):
extra = 0
form = StatusForm
exclude = ["arp_sponge"]
readonly_fields = ["id", "ixf_import_attempt_info", "prefixes"]
readonly_fields = ["ixf_import_attempt_info", "prefixes"]
def has_add_permission(self, request):
return False
@ -465,48 +475,12 @@ class NetworkFacilityInline(SanitizedAdmin, admin.TabularInline):
}
class NetworkIXLanValidationMixin(object):
"""
For issue #70
Makes sure netixlans cannot be saved if they have a duplicate ip address
This should ideally be done in mysql, however we need to clear out the other
duplicates first, so we validate on the django side for now
"""
def clean_ipaddr4(self):
ipaddr4 = self.cleaned_data["ipaddr4"]
instance = self.instance
if (
NetworkIXLan.objects.filter(ipaddr4=ipaddr4, status="ok")
.exclude(id=getattr(instance, "id", 0))
.exists()
):
raise ValidationError(_("Ipaddress already exists elsewhere"))
return ipaddr4
def clean_ipaddr6(self):
ipaddr6 = self.cleaned_data["ipaddr6"]
instance = self.instance
if (
NetworkIXLan.objects.filter(ipaddr6=ipaddr6, status="ok")
.exclude(id=getattr(instance, "id", 0))
.exists()
):
raise ValidationError(_("Ipaddress already exists elsewhere"))
return ipaddr6
class NetworkIXLanForm(NetworkIXLanValidationMixin, StatusForm):
pass
class NetworkInternetExchangeInline(SanitizedAdmin, admin.TabularInline):
model = NetworkIXLan
extra = 0
raw_id_fields = ("ixlan", "network")
form = NetworkIXLanForm
form = StatusForm
class UserOrgAffiliationRequestInlineForm(baseForms.ModelForm):
@ -828,7 +802,8 @@ class OrganizationAdmin(ModelAdminWithVQCtrl, SoftDeleteAdmin):
def org_merge_tool_view(self, request):
if not request.user.is_superuser:
return redirect("admin:login")
return HttpResponseForbidden()
context = dict(
self.admin_site.each_context(request),
undo_url=django.urls.reverse(
@ -861,7 +836,11 @@ class OrganizationMergeLog(ModelAdminWithUrlActions):
def undo_merge(self, obj):
return mark_safe(
'<a class="grp-button grp-delete-link" href="action/undo">{}</a>'.format(
'<a class="grp-button grp-delete-link" href="{}">{}</a>'.format(
django.urls.reverse(
"admin:peeringdb_server_organizationmerge_actions",
args=(obj.id,"undo")
),
_("Undo merge")
)
)
@ -874,6 +853,7 @@ class OrganizationMergeLog(ModelAdminWithUrlActions):
each.undo()
undo.short_description = _("Undo merge")
undo.allowed_permissions = ('change',)
actions = [undo]
@ -1099,12 +1079,14 @@ class VerificationQueueAdmin(ModelAdminWithUrlActions):
each.approve()
vq_approve.short_description = _("APPROVE selected items")
vq_approve.allowed_permissions = ('change',)
def vq_deny(modeladmin, request, queryset):
for each in queryset:
each.deny()
vq_deny.short_description = _("DENY and delete selected items")
vq_deny.allowed_permissions = ('change',)
actions = [vq_approve, vq_deny]
@ -1444,7 +1426,7 @@ class DuplicateIPAdmin(SoftDeleteAdmin):
list_display = ("id_ro", "ip", "asn", "ix", "net", "updated_ro", "status_ro")
readonly_fields = ("id_ro", "ip", "net", "ix", "asn", "updated_ro", "status_ro")
form = NetworkIXLanForm
form = StatusForm
list_per_page = 1000
fieldsets = (
(
@ -1458,7 +1440,7 @@ class DuplicateIPAdmin(SoftDeleteAdmin):
"ipaddr6",
"ix",
"net",
"updated",
"updated_ro",
),
},
),
@ -1570,8 +1552,8 @@ class CommandLineToolAdmin(admin.ModelAdmin):
This view has the user select which command they want to run and
with which arguments.
"""
if not request.user.is_superuser:
return redirect("admin:login")
if not self.has_add_permission(request):
return HttpResponseForbidden()
context = dict(self.admin_site.each_context(request))
title = "Commandline Tools"
@ -1611,8 +1593,8 @@ class CommandLineToolAdmin(admin.ModelAdmin):
"""
This view has the user preview the result of running the command
"""
if not request.user.is_superuser:
return redirect("admin:login")
if not self.has_add_permission(request):
return HttpResponseForbidden()
context = dict(self.admin_site.each_context(request))
if request.method == "POST":
@ -1622,7 +1604,7 @@ class CommandLineToolAdmin(admin.ModelAdmin):
action = "run"
tool.run(request.user, commit=False)
else:
print((tool.form_instance.errors))
action = "run"
form = tool.form_instance
else:
raise Exception(_("Only POST requests allowed."))
@ -1651,8 +1633,9 @@ class CommandLineToolAdmin(admin.ModelAdmin):
This view has the user running the command and commiting changes
to the database.
"""
if not request.user.is_superuser:
return redirect("admin:login")
if not self.has_add_permission(request):
return HttpResponseForbidden()
context = dict(self.admin_site.each_context(request))
if request.method == "POST":
tool = acltools.get_tool_from_data(request.POST)