From 197475409c23dd6d3795ecf538bf655f8f7a3d6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Sun, 10 Jun 2018 00:50:57 +0000 Subject: [PATCH] DNS Zone endpoint is now a viewset --- api/serializers.py | 7 +++++-- api/urls.py | 3 ++- api/views.py | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/api/serializers.py b/api/serializers.py index 44dfc0bc..608e077d 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -561,7 +561,7 @@ class CNAMERecordSerializer(serializers.ModelSerializer): fields = ('alias', 'hostname') -class DNSZonesSerializer(serializers.ModelSerializer): +class DNSZonesSerializer(NamespacedHMSerializer): soa = SOARecordSerializer() ns_records = NSRecordSerializer(many=True, source='ns_set') originv4 = OriginV4RecordSerializer(source='origin') @@ -577,4 +577,7 @@ class DNSZonesSerializer(serializers.ModelSerializer): model = machines.Extension fields = ('name', 'soa', 'ns_records', 'originv4', 'originv6', 'mx_records', 'txt_records', 'srv_records', 'a_records', - 'aaaa_records', 'cname_records') + 'aaaa_records', 'cname_records', 'api_url') + extra_kwargs = { + 'api_url': {'view_name': 'dnszone-detail'} + } diff --git a/api/urls.py b/api/urls.py index 07f83afb..8138facb 100644 --- a/api/urls.py +++ b/api/urls.py @@ -86,11 +86,12 @@ router.register(r'users/listrights', views.ListRightViewSet) router.register(r'users/shells', views.ShellViewSet, base_name='shell') router.register(r'users/bans', views.BanViewSet) router.register(r'users/whitelists', views.WhitelistViewSet) +# DNS +router.register(r'dns/zones', views.DNSZonesViewSet, base_name='dnszone') urlpatterns = [ url(r'^', include(router.urls)), url(r'^dhcp/hostmacip', views.HostMacIpView.as_view()), - url(r'^dns/zones', views.DNSZonesView.as_view()), url(r'^services/regen', views.ServiceRegenView.as_view()), url(r'^token-auth', views.ObtainExpiringAuthToken.as_view()) ] diff --git a/api/views.py b/api/views.py index 1530fbb3..36061deb 100644 --- a/api/views.py +++ b/api/views.py @@ -340,7 +340,7 @@ class HostMacIpView(generics.ListAPIView): # DNS views -class DNSZonesView(generics.ListAPIView): +class DNSZonesViewSet(viewsets.ReadOnlyModelViewSet): queryset = machines.Extension.objects.all() serializer_class = serializers.DNSZonesSerializer