2018-06-30 01:25:46 +00:00
|
|
|
# -*- mode: python; coding: utf-8 -*-
|
2018-03-17 17:20:31 +00:00
|
|
|
# Re2o est un logiciel d'administration développé initiallement au rezometz. Il
|
|
|
|
# se veut agnostique au réseau considéré, de manière à être installable en
|
|
|
|
# quelques clics.
|
|
|
|
#
|
2018-06-17 01:06:58 +00:00
|
|
|
# Copyright © 2018 Maël Kervella
|
2018-03-17 17:20:31 +00:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Defines the serializers of the API
|
2018-03-17 17:20:31 +00:00
|
|
|
"""
|
2018-03-17 17:50:03 +00:00
|
|
|
|
|
|
|
from rest_framework import serializers
|
2018-04-21 22:36:10 +00:00
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
import cotisations.models as cotisations
|
|
|
|
import machines.models as machines
|
|
|
|
import preferences.models as preferences
|
|
|
|
import topologie.models as topologie
|
|
|
|
import users.models as users
|
|
|
|
|
2018-06-17 01:06:58 +00:00
|
|
|
# The namespace used for the API. It must match the namespace used in the
|
|
|
|
# urlpatterns to include the API URLs.
|
2019-11-04 16:55:03 +00:00
|
|
|
API_NAMESPACE = "api"
|
2018-04-24 15:57:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
class NamespacedHRField(serializers.HyperlinkedRelatedField):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""A `rest_framework.serializers.HyperlinkedRelatedField` subclass to
|
|
|
|
automatically prefix view names with the API namespace.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
def __init__(self, view_name=None, **kwargs):
|
|
|
|
if view_name is not None:
|
2019-11-04 16:55:03 +00:00
|
|
|
view_name = "%s:%s" % (API_NAMESPACE, view_name)
|
2018-04-24 15:57:55 +00:00
|
|
|
super(NamespacedHRField, self).__init__(view_name=view_name, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
class NamespacedHIField(serializers.HyperlinkedIdentityField):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""A `rest_framework.serializers.HyperlinkedIdentityField` subclass to
|
|
|
|
automatically prefix view names with teh API namespace.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
def __init__(self, view_name=None, **kwargs):
|
|
|
|
if view_name is not None:
|
2019-11-04 16:55:03 +00:00
|
|
|
view_name = "%s:%s" % (API_NAMESPACE, view_name)
|
2018-04-24 15:57:55 +00:00
|
|
|
super(NamespacedHIField, self).__init__(view_name=view_name, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
class NamespacedHMSerializer(serializers.HyperlinkedModelSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""A `rest_framework.serializers.HyperlinkedModelSerializer` subclass to
|
|
|
|
automatically prefix view names with the API namespace.
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
serializer_related_field = NamespacedHRField
|
|
|
|
serializer_url_field = NamespacedHIField
|
2018-03-17 17:50:03 +00:00
|
|
|
|
2018-04-22 00:36:06 +00:00
|
|
|
|
2018-06-17 01:06:58 +00:00
|
|
|
# COTISATIONS
|
2018-04-21 22:36:10 +00:00
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
|
|
|
|
class FactureSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `cotisations.models.Facture` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-21 22:36:10 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = cotisations.Facture
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = (
|
|
|
|
"user",
|
|
|
|
"paiement",
|
|
|
|
"banque",
|
|
|
|
"cheque",
|
|
|
|
"date",
|
|
|
|
"valid",
|
|
|
|
"control",
|
|
|
|
"prix_total",
|
|
|
|
"name",
|
|
|
|
"api_url",
|
|
|
|
)
|
2018-04-21 22:36:10 +00:00
|
|
|
|
|
|
|
|
2018-10-12 11:05:38 +00:00
|
|
|
class BaseInvoiceSerializer(NamespacedHMSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = cotisations.BaseInvoice
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = "__all__"
|
|
|
|
|
2018-10-12 11:05:38 +00:00
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class VenteSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `cotisations.models.Vente` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-21 22:36:10 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = cotisations.Vente
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = (
|
|
|
|
"facture",
|
|
|
|
"number",
|
|
|
|
"name",
|
|
|
|
"prix",
|
|
|
|
"duration",
|
|
|
|
"type_cotisation",
|
|
|
|
"prix_total",
|
|
|
|
"api_url",
|
|
|
|
)
|
2018-04-21 22:36:10 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class ArticleSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `cotisations.models.Article` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-21 22:36:10 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = cotisations.Article
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("name", "prix", "duration", "type_user", "type_cotisation", "api_url")
|
2018-04-21 22:36:10 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class BanqueSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `cotisations.models.Banque` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-21 22:36:10 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = cotisations.Banque
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("name", "api_url")
|
2018-04-21 22:36:10 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class PaiementSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `cotisations.models.Paiement` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-21 22:36:10 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = cotisations.Paiement
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("moyen", "api_url")
|
2018-04-21 22:36:10 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class CotisationSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `cotisations.models.Cotisation` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-21 22:36:10 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = cotisations.Cotisation
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("vente", "type_cotisation", "date_start", "date_end", "api_url")
|
2018-04-21 22:36:10 +00:00
|
|
|
|
|
|
|
|
2018-06-17 01:06:58 +00:00
|
|
|
# MACHINES
|
2018-04-22 00:36:06 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class MachineSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `machines.models.Machine` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-22 00:36:06 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = machines.Machine
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("user", "name", "active", "api_url")
|
2018-04-22 00:36:06 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class MachineTypeSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `machines.models.MachineType` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-22 00:36:06 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = machines.MachineType
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("name", "ip_type", "api_url")
|
2018-04-22 00:36:06 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class IpTypeSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `machines.models.IpType` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-22 00:36:06 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = machines.IpType
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = (
|
|
|
|
"name",
|
|
|
|
"extension",
|
|
|
|
"need_infra",
|
|
|
|
"domaine_ip_start",
|
|
|
|
"domaine_ip_stop",
|
|
|
|
"prefix_v6",
|
|
|
|
"vlan",
|
|
|
|
"ouverture_ports",
|
|
|
|
"api_url",
|
|
|
|
)
|
2018-04-22 00:36:06 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class VlanSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `machines.models.Vlan` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-22 00:36:06 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = machines.Vlan
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = (
|
|
|
|
"vlan_id",
|
|
|
|
"name",
|
|
|
|
"comment",
|
|
|
|
"arp_protect",
|
|
|
|
"dhcp_snooping",
|
|
|
|
"dhcpv6_snooping",
|
|
|
|
"igmp",
|
|
|
|
"mld",
|
|
|
|
"api_url",
|
|
|
|
)
|
2018-04-22 00:36:06 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class NasSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `machines.models.Nas` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-22 00:36:06 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = machines.Nas
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = (
|
|
|
|
"name",
|
|
|
|
"nas_type",
|
|
|
|
"machine_type",
|
|
|
|
"port_access_mode",
|
|
|
|
"autocapture_mac",
|
|
|
|
"api_url",
|
|
|
|
)
|
2018-04-22 00:36:06 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class SOASerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `machines.models.SOA` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-22 00:36:06 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = machines.SOA
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("name", "mail", "refresh", "retry", "expire", "ttl", "api_url")
|
2018-04-22 00:36:06 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class ExtensionSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `machines.models.Extension` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-22 00:36:06 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = machines.Extension
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("name", "need_infra", "origin", "origin_v6", "soa", "api_url")
|
2018-04-22 00:36:06 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class MxSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `machines.models.Mx` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-22 00:36:06 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = machines.Mx
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("zone", "priority", "name", "api_url")
|
2018-04-22 00:36:06 +00:00
|
|
|
|
|
|
|
|
2018-06-25 15:35:40 +00:00
|
|
|
class DNameSerializer(NamespacedHMSerializer):
|
|
|
|
"""Serialize `machines.models.DName` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-06-25 15:35:40 +00:00
|
|
|
class Meta:
|
|
|
|
model = machines.DName
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("zone", "alias", "api_url")
|
2018-06-25 15:35:40 +00:00
|
|
|
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class NsSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `machines.models.Ns` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-22 00:36:06 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = machines.Ns
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("zone", "ns", "api_url")
|
2018-04-22 00:36:06 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class TxtSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `machines.models.Txt` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-22 00:36:06 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = machines.Txt
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("zone", "field1", "field2", "api_url")
|
2018-04-22 00:36:06 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class SrvSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `machines.models.Srv` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-22 00:36:06 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = machines.Srv
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = (
|
|
|
|
"service",
|
|
|
|
"protocole",
|
|
|
|
"extension",
|
|
|
|
"ttl",
|
|
|
|
"priority",
|
|
|
|
"weight",
|
|
|
|
"port",
|
|
|
|
"target",
|
|
|
|
"api_url",
|
|
|
|
)
|
2018-04-22 00:36:06 +00:00
|
|
|
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-07-29 17:07:40 +00:00
|
|
|
class SshFpSerializer(NamespacedHMSerializer):
|
|
|
|
"""Serialize `machines.models.SSHFP` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-07-29 17:07:40 +00:00
|
|
|
class Meta:
|
|
|
|
model = machines.SshFp
|
2019-11-04 16:55:03 +00:00
|
|
|
field = ("machine", "pub_key_entry", "algo", "comment", "api_url")
|
2018-07-29 17:07:40 +00:00
|
|
|
|
2018-04-22 00:36:06 +00:00
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class InterfaceSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `machines.models.Interface` objects.
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2018-04-26 22:44:27 +00:00
|
|
|
mac_address = serializers.CharField()
|
2019-11-04 16:55:03 +00:00
|
|
|
active = serializers.BooleanField(source="is_active")
|
2018-04-22 00:36:06 +00:00
|
|
|
|
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = machines.Interface
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = (
|
|
|
|
"ipv4",
|
|
|
|
"mac_address",
|
|
|
|
"machine",
|
|
|
|
"machine_type",
|
|
|
|
"details",
|
|
|
|
"port_lists",
|
|
|
|
"active",
|
|
|
|
"api_url",
|
|
|
|
)
|
2018-04-22 00:36:06 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class Ipv6ListSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `machines.models.Ipv6List` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-22 00:36:06 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = machines.Ipv6List
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("ipv6", "interface", "slaac_ip", "api_url")
|
2018-04-22 00:36:06 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class DomainSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `machines.models.Domain` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-22 00:36:06 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = machines.Domain
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("interface_parent", "name", "extension", "cname", "api_url")
|
2018-04-22 00:36:06 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class IpListSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `machines.models.IpList` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-22 00:36:06 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = machines.IpList
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("ipv4", "ip_type", "need_infra", "api_url")
|
2018-04-22 00:36:06 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class ServiceSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `machines.models.Service` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-22 00:36:06 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = machines.Service
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = (
|
|
|
|
"service_type",
|
|
|
|
"min_time_regen",
|
|
|
|
"regular_time_regen",
|
|
|
|
"servers",
|
|
|
|
"api_url",
|
|
|
|
)
|
2018-04-22 00:36:06 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class ServiceLinkSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `machines.models.Service_link` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-22 00:36:06 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = machines.Service_link
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = (
|
|
|
|
"service",
|
|
|
|
"server",
|
|
|
|
"last_regen",
|
|
|
|
"asked_regen",
|
|
|
|
"need_regen",
|
|
|
|
"api_url",
|
|
|
|
)
|
|
|
|
extra_kwargs = {"api_url": {"view_name": "servicelink-detail"}}
|
2018-04-22 00:36:06 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class OuverturePortListSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `machines.models.OuverturePortList` objects.
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
|
|
|
tcp_ports_in = NamespacedHRField(
|
|
|
|
view_name="ouvertureport-detail", many=True, read_only=True
|
|
|
|
)
|
|
|
|
udp_ports_in = NamespacedHRField(
|
|
|
|
view_name="ouvertureport-detail", many=True, read_only=True
|
|
|
|
)
|
|
|
|
tcp_ports_out = NamespacedHRField(
|
|
|
|
view_name="ouvertureport-detail", many=True, read_only=True
|
|
|
|
)
|
|
|
|
udp_ports_out = NamespacedHRField(
|
|
|
|
view_name="ouvertureport-detail", many=True, read_only=True
|
|
|
|
)
|
2018-06-22 00:48:45 +00:00
|
|
|
|
2018-04-22 00:36:06 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = machines.OuverturePortList
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = (
|
|
|
|
"name",
|
|
|
|
"tcp_ports_in",
|
|
|
|
"udp_ports_in",
|
|
|
|
"tcp_ports_out",
|
|
|
|
"udp_ports_out",
|
|
|
|
"api_url",
|
|
|
|
)
|
2018-04-22 00:36:06 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class OuverturePortSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `machines.models.OuverturePort` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-22 00:36:06 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = machines.OuverturePort
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("begin", "end", "port_list", "protocole", "io", "api_url")
|
2018-04-22 00:36:06 +00:00
|
|
|
|
|
|
|
|
2018-07-08 02:08:01 +00:00
|
|
|
class RoleSerializer(NamespacedHMSerializer):
|
|
|
|
"""Serialize `machines.models.OuverturePort` objects.
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2018-07-08 02:08:01 +00:00
|
|
|
servers = InterfaceSerializer(read_only=True, many=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = machines.Role
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("role_type", "servers", "api_url")
|
2018-07-08 02:08:01 +00:00
|
|
|
|
|
|
|
|
2018-06-17 01:06:58 +00:00
|
|
|
# PREFERENCES
|
2018-04-22 18:28:01 +00:00
|
|
|
|
|
|
|
|
2018-06-16 18:35:08 +00:00
|
|
|
class OptionalUserSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `preferences.models.OptionalUser` objects.
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
|
|
|
tel_mandatory = serializers.BooleanField(source="is_tel_mandatory")
|
2018-10-12 11:05:38 +00:00
|
|
|
shell_default = serializers.StringRelatedField()
|
2018-06-16 18:35:08 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = preferences.OptionalUser
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = (
|
|
|
|
"tel_mandatory",
|
|
|
|
"gpg_fingerprint",
|
|
|
|
"all_can_create_club",
|
|
|
|
"self_adhesion",
|
|
|
|
"shell_default",
|
|
|
|
"self_change_shell",
|
|
|
|
"local_email_accounts_enabled",
|
|
|
|
"local_email_domain",
|
|
|
|
"max_email_address",
|
2018-10-12 11:05:38 +00:00
|
|
|
)
|
2018-06-16 18:35:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
class OptionalMachineSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `preferences.models.OptionalMachine` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-06-16 18:35:08 +00:00
|
|
|
class Meta:
|
|
|
|
model = preferences.OptionalMachine
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = (
|
|
|
|
"password_machine",
|
|
|
|
"max_lambdauser_interfaces",
|
|
|
|
"max_lambdauser_aliases",
|
|
|
|
"ipv6_mode",
|
|
|
|
"create_machine",
|
|
|
|
"ipv6",
|
|
|
|
)
|
2018-06-16 18:35:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
class OptionalTopologieSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `preferences.models.OptionalTopologie` objects.
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2018-09-24 18:01:20 +00:00
|
|
|
switchs_management_interface_ip = serializers.CharField()
|
2018-07-11 22:11:55 +00:00
|
|
|
|
2018-06-16 18:35:08 +00:00
|
|
|
class Meta:
|
|
|
|
model = preferences.OptionalTopologie
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = (
|
|
|
|
"switchs_ip_type",
|
|
|
|
"switchs_web_management",
|
|
|
|
"switchs_web_management_ssl",
|
|
|
|
"switchs_rest_management",
|
|
|
|
"switchs_management_utils",
|
|
|
|
"switchs_management_interface_ip",
|
|
|
|
"provision_switchs_enabled",
|
|
|
|
"switchs_provision",
|
|
|
|
"switchs_management_sftp_creds",
|
|
|
|
)
|
2018-06-16 18:35:08 +00:00
|
|
|
|
|
|
|
|
2019-01-04 11:31:10 +00:00
|
|
|
class RadiusOptionSerializer(NamespacedHMSerializer):
|
|
|
|
"""Serialize `preferences.models.RadiusOption` objects
|
|
|
|
"""
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = preferences.RadiusOption
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = (
|
|
|
|
"radius_general_policy",
|
|
|
|
"unknown_machine",
|
|
|
|
"unknown_machine_vlan",
|
|
|
|
"unknown_port",
|
|
|
|
"unknown_port_vlan",
|
|
|
|
"unknown_room",
|
|
|
|
"unknown_room_vlan",
|
|
|
|
"non_member",
|
|
|
|
"non_member_vlan",
|
|
|
|
"banned",
|
|
|
|
"banned_vlan",
|
|
|
|
"vlan_decision_ok",
|
|
|
|
)
|
2019-01-04 11:31:10 +00:00
|
|
|
|
|
|
|
|
2018-06-16 18:35:08 +00:00
|
|
|
class GeneralOptionSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `preferences.models.GeneralOption` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-06-16 18:35:08 +00:00
|
|
|
class Meta:
|
|
|
|
model = preferences.GeneralOption
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = (
|
|
|
|
"general_message_fr",
|
|
|
|
"general_message_en",
|
|
|
|
"search_display_page",
|
|
|
|
"pagination_number",
|
|
|
|
"pagination_large_number",
|
|
|
|
"req_expire_hrs",
|
|
|
|
"site_name",
|
|
|
|
"main_site_url",
|
|
|
|
"email_from",
|
|
|
|
"GTU_sum_up",
|
|
|
|
"GTU",
|
|
|
|
)
|
|
|
|
|
2018-06-16 18:35:08 +00:00
|
|
|
|
2018-06-22 00:48:45 +00:00
|
|
|
class HomeServiceSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `preferences.models.Service` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-06-16 18:35:08 +00:00
|
|
|
class Meta:
|
|
|
|
model = preferences.Service
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("name", "url", "description", "image", "api_url")
|
|
|
|
extra_kwargs = {"api_url": {"view_name": "homeservice-detail"}}
|
2018-06-16 18:35:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
class AssoOptionSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `preferences.models.AssoOption` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-06-16 18:35:08 +00:00
|
|
|
class Meta:
|
|
|
|
model = preferences.AssoOption
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = (
|
|
|
|
"name",
|
|
|
|
"siret",
|
|
|
|
"adresse1",
|
|
|
|
"adresse2",
|
|
|
|
"contact",
|
|
|
|
"telephone",
|
|
|
|
"pseudo",
|
|
|
|
"utilisateur_asso",
|
|
|
|
"description",
|
|
|
|
)
|
2018-06-16 18:35:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
class HomeOptionSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `preferences.models.HomeOption` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-06-16 18:35:08 +00:00
|
|
|
class Meta:
|
|
|
|
model = preferences.HomeOption
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("facebook_url", "twitter_url", "twitter_account_name")
|
2018-06-16 18:35:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
class MailMessageOptionSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `preferences.models.MailMessageOption` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-06-16 18:35:08 +00:00
|
|
|
class Meta:
|
|
|
|
model = preferences.MailMessageOption
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("welcome_mail_fr", "welcome_mail_en")
|
2018-04-22 18:28:01 +00:00
|
|
|
|
|
|
|
|
2018-06-17 01:06:58 +00:00
|
|
|
# TOPOLOGIE
|
2018-04-24 13:59:18 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class StackSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `topologie.models.Stack` objects
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-24 13:59:18 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = topologie.Stack
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = (
|
|
|
|
"name",
|
|
|
|
"stack_id",
|
|
|
|
"details",
|
|
|
|
"member_id_min",
|
|
|
|
"member_id_max",
|
|
|
|
"api_url",
|
|
|
|
)
|
2018-04-24 13:59:18 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class AccessPointSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `topologie.models.AccessPoint` objects
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-24 13:59:18 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = topologie.AccessPoint
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("user", "name", "active", "location", "api_url")
|
2018-04-24 13:59:18 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class SwitchSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `topologie.models.Switch` objects
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
|
|
|
port_amount = serializers.IntegerField(source="number")
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-24 13:59:18 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = topologie.Switch
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = (
|
|
|
|
"user",
|
|
|
|
"name",
|
|
|
|
"active",
|
|
|
|
"port_amount",
|
|
|
|
"stack",
|
|
|
|
"stack_member_id",
|
|
|
|
"model",
|
|
|
|
"switchbay",
|
|
|
|
"api_url",
|
|
|
|
)
|
2018-04-24 13:59:18 +00:00
|
|
|
|
|
|
|
|
2018-06-20 12:13:23 +00:00
|
|
|
class ServerSerializer(NamespacedHMSerializer):
|
|
|
|
"""Serialize `topologie.models.Server` objects
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-06-20 12:13:23 +00:00
|
|
|
class Meta:
|
|
|
|
model = topologie.Server
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("user", "name", "active", "api_url")
|
2018-06-20 12:13:23 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class ModelSwitchSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `topologie.models.ModelSwitch` objects
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-24 13:59:18 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = topologie.ModelSwitch
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("reference", "constructor", "api_url")
|
2018-04-24 13:59:18 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class ConstructorSwitchSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `topologie.models.ConstructorSwitch` objects
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-24 13:59:18 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = topologie.ConstructorSwitch
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("name", "api_url")
|
2018-04-24 13:59:18 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class SwitchBaySerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `topologie.models.SwitchBay` objects
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-24 13:59:18 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = topologie.SwitchBay
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("name", "building", "info", "api_url")
|
2018-04-24 13:59:18 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class BuildingSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `topologie.models.Building` objects
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-24 13:59:18 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = topologie.Building
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("name", "api_url")
|
2018-04-24 13:59:18 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class SwitchPortSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `topologie.models.Port` objects
|
|
|
|
"""
|
2018-07-02 09:00:32 +00:00
|
|
|
|
2019-11-04 16:55:03 +00:00
|
|
|
get_port_profile = NamespacedHIField(view_name="portprofile-detail", read_only=True)
|
2018-07-02 09:00:32 +00:00
|
|
|
|
2018-04-24 13:59:18 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = topologie.Port
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = (
|
|
|
|
"switch",
|
|
|
|
"port",
|
|
|
|
"room",
|
|
|
|
"machine_interface",
|
|
|
|
"related",
|
|
|
|
"custom_profile",
|
|
|
|
"state",
|
|
|
|
"get_port_profile",
|
|
|
|
"details",
|
|
|
|
"api_url",
|
|
|
|
)
|
2018-04-26 22:44:27 +00:00
|
|
|
extra_kwargs = {
|
2019-11-04 16:55:03 +00:00
|
|
|
"related": {"view_name": "switchport-detail"},
|
|
|
|
"api_url": {"view_name": "switchport-detail"},
|
2018-04-26 22:44:27 +00:00
|
|
|
}
|
2018-04-24 13:59:18 +00:00
|
|
|
|
|
|
|
|
2018-07-02 09:00:32 +00:00
|
|
|
class PortProfileSerializer(NamespacedHMSerializer):
|
|
|
|
"""Serialize `topologie.models.Room` objects
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2018-07-02 09:00:32 +00:00
|
|
|
class Meta:
|
|
|
|
model = topologie.PortProfile
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = (
|
|
|
|
"name",
|
|
|
|
"profil_default",
|
|
|
|
"vlan_untagged",
|
|
|
|
"vlan_tagged",
|
|
|
|
"radius_type",
|
|
|
|
"radius_mode",
|
|
|
|
"speed",
|
|
|
|
"mac_limit",
|
|
|
|
"flow_control",
|
|
|
|
"dhcp_snooping",
|
|
|
|
"dhcpv6_snooping",
|
|
|
|
"dhcpv6_snooping",
|
|
|
|
"arp_protect",
|
|
|
|
"ra_guard",
|
|
|
|
"loop_protect",
|
|
|
|
"api_url",
|
|
|
|
)
|
2018-07-02 09:00:32 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class RoomSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `topologie.models.Room` objects
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-24 13:59:18 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = topologie.Room
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("name", "details", "api_url")
|
2018-04-24 13:59:18 +00:00
|
|
|
|
|
|
|
|
2018-08-04 08:53:34 +00:00
|
|
|
class PortProfileSerializer(NamespacedHMSerializer):
|
|
|
|
vlan_untagged = VlanSerializer(read_only=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = topologie.PortProfile
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = (
|
|
|
|
"name",
|
|
|
|
"profil_default",
|
|
|
|
"vlan_untagged",
|
|
|
|
"vlan_tagged",
|
|
|
|
"radius_type",
|
|
|
|
"radius_mode",
|
|
|
|
"speed",
|
|
|
|
"mac_limit",
|
|
|
|
"flow_control",
|
|
|
|
"dhcp_snooping",
|
|
|
|
"dhcpv6_snooping",
|
|
|
|
"arp_protect",
|
|
|
|
"ra_guard",
|
|
|
|
"loop_protect",
|
|
|
|
"vlan_untagged",
|
|
|
|
"vlan_tagged",
|
|
|
|
)
|
2018-08-04 08:53:34 +00:00
|
|
|
|
|
|
|
|
2018-06-17 01:06:58 +00:00
|
|
|
# USERS
|
2018-04-21 22:36:10 +00:00
|
|
|
|
2018-03-17 17:50:03 +00:00
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class UserSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `users.models.User` objects.
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
|
|
|
access = serializers.BooleanField(source="has_access")
|
|
|
|
uid = serializers.IntegerField(source="uid_number")
|
2018-03-17 17:50:03 +00:00
|
|
|
|
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = users.User
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = (
|
|
|
|
"surname",
|
|
|
|
"pseudo",
|
|
|
|
"email",
|
|
|
|
"local_email_redirect",
|
|
|
|
"local_email_enabled",
|
|
|
|
"school",
|
|
|
|
"shell",
|
|
|
|
"comment",
|
|
|
|
"state",
|
|
|
|
"registered",
|
|
|
|
"telephone",
|
|
|
|
"solde",
|
|
|
|
"access",
|
|
|
|
"end_access",
|
|
|
|
"uid",
|
2019-12-27 16:00:20 +00:00
|
|
|
"class_type",
|
2019-11-04 16:55:03 +00:00
|
|
|
"api_url",
|
|
|
|
)
|
|
|
|
extra_kwargs = {"shell": {"view_name": "shell-detail"}}
|
2018-03-17 17:50:03 +00:00
|
|
|
|
2018-04-14 11:49:39 +00:00
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class ClubSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `users.models.Club` objects.
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
|
|
|
name = serializers.CharField(source="surname")
|
|
|
|
access = serializers.BooleanField(source="has_access")
|
|
|
|
uid = serializers.IntegerField(source="uid_number")
|
2018-03-17 17:57:11 +00:00
|
|
|
|
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = users.Club
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = (
|
|
|
|
"name",
|
|
|
|
"pseudo",
|
|
|
|
"email",
|
|
|
|
"local_email_redirect",
|
|
|
|
"local_email_enabled",
|
|
|
|
"school",
|
|
|
|
"shell",
|
|
|
|
"comment",
|
|
|
|
"state",
|
|
|
|
"registered",
|
|
|
|
"telephone",
|
|
|
|
"solde",
|
|
|
|
"room",
|
|
|
|
"access",
|
|
|
|
"end_access",
|
|
|
|
"administrators",
|
|
|
|
"members",
|
|
|
|
"mailing",
|
|
|
|
"uid",
|
|
|
|
"api_url",
|
|
|
|
)
|
|
|
|
extra_kwargs = {"shell": {"view_name": "shell-detail"}}
|
2018-03-17 17:57:11 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class AdherentSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `users.models.Adherent` objects.
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
|
|
|
access = serializers.BooleanField(source="has_access")
|
|
|
|
uid = serializers.IntegerField(source="uid_number")
|
2018-04-14 11:49:39 +00:00
|
|
|
|
2018-03-17 17:57:11 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = users.Adherent
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = (
|
|
|
|
"name",
|
|
|
|
"surname",
|
|
|
|
"pseudo",
|
|
|
|
"email",
|
|
|
|
"local_email_redirect",
|
|
|
|
"local_email_enabled",
|
|
|
|
"school",
|
|
|
|
"shell",
|
|
|
|
"comment",
|
|
|
|
"state",
|
|
|
|
"registered",
|
|
|
|
"telephone",
|
|
|
|
"room",
|
|
|
|
"solde",
|
|
|
|
"access",
|
|
|
|
"end_access",
|
|
|
|
"uid",
|
|
|
|
"api_url",
|
|
|
|
"gid",
|
|
|
|
)
|
|
|
|
extra_kwargs = {"shell": {"view_name": "shell-detail"}}
|
2018-03-17 18:54:17 +00:00
|
|
|
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-11-17 18:51:37 +00:00
|
|
|
class BasicUserSerializer(NamespacedHMSerializer):
|
|
|
|
"""Serialize 'users.models.User' minimal infos"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
|
|
|
uid = serializers.IntegerField(source="uid_number")
|
|
|
|
gid = serializers.IntegerField(source="gid_number")
|
2018-08-05 15:22:12 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = users.User
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("pseudo", "uid", "gid")
|
2018-03-17 18:54:17 +00:00
|
|
|
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class ServiceUserSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `users.models.ServiceUser` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-03-17 18:54:17 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = users.ServiceUser
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("pseudo", "access_group", "comment", "api_url")
|
2018-03-17 18:54:17 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class SchoolSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `users.models.School` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-03-17 18:54:17 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = users.School
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("name", "api_url")
|
2018-03-17 18:54:17 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class ListRightSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `users.models.ListRight` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-03-17 18:54:17 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = users.ListRight
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("unix_name", "gid", "critical", "details", "api_url")
|
2018-03-17 18:54:17 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class ShellSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `users.models.ListShell` objects.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-03-17 18:54:17 +00:00
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = users.ListShell
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("shell", "api_url")
|
|
|
|
extra_kwargs = {"api_url": {"view_name": "shell-detail"}}
|
2018-03-17 18:54:17 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class BanSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `users.models.Ban` objects.
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
|
|
|
active = serializers.BooleanField(source="is_active")
|
2018-03-17 18:54:17 +00:00
|
|
|
|
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = users.Ban
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = (
|
|
|
|
"user",
|
|
|
|
"raison",
|
|
|
|
"date_start",
|
|
|
|
"date_end",
|
|
|
|
"state",
|
|
|
|
"active",
|
|
|
|
"api_url",
|
|
|
|
)
|
2018-03-17 18:54:17 +00:00
|
|
|
|
|
|
|
|
2018-04-24 15:57:55 +00:00
|
|
|
class WhitelistSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `users.models.Whitelist` objects.
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
|
|
|
active = serializers.BooleanField(source="is_active")
|
2018-03-17 17:50:03 +00:00
|
|
|
|
|
|
|
class Meta:
|
2018-04-24 15:57:55 +00:00
|
|
|
model = users.Whitelist
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("user", "raison", "date_start", "date_end", "active", "api_url")
|
2018-05-24 23:07:23 +00:00
|
|
|
|
|
|
|
|
2018-08-01 11:06:25 +00:00
|
|
|
class EMailAddressSerializer(NamespacedHMSerializer):
|
|
|
|
"""Serialize `users.models.EMailAddress` objects.
|
2018-06-30 13:18:08 +00:00
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
|
|
|
user = serializers.CharField(source="user.pseudo", read_only=True)
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-06-30 13:18:08 +00:00
|
|
|
class Meta:
|
2018-08-01 11:06:25 +00:00
|
|
|
model = users.EMailAddress
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("user", "local_part", "complete_email_address", "api_url")
|
2018-07-15 20:31:42 +00:00
|
|
|
|
|
|
|
|
2018-06-17 01:06:58 +00:00
|
|
|
# SERVICE REGEN
|
2018-05-26 21:08:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ServiceRegenSerializer(NamespacedHMSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize the data about the services to regen.
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
|
|
|
hostname = serializers.CharField(source="server.domain.name", read_only=True)
|
|
|
|
service_name = serializers.CharField(source="service.service_type", read_only=True)
|
2018-06-10 13:41:31 +00:00
|
|
|
need_regen = serializers.BooleanField()
|
2018-05-26 21:08:03 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = machines.Service_link
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("hostname", "service_name", "need_regen", "api_url")
|
|
|
|
extra_kwargs = {"api_url": {"view_name": "serviceregen-detail"}}
|
|
|
|
|
2018-07-15 20:31:42 +00:00
|
|
|
|
2018-07-02 09:00:32 +00:00
|
|
|
# Switches et ports
|
|
|
|
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2018-07-08 02:08:01 +00:00
|
|
|
class InterfaceVlanSerializer(NamespacedHMSerializer):
|
|
|
|
domain = serializers.CharField(read_only=True)
|
|
|
|
ipv4 = serializers.CharField(read_only=True)
|
|
|
|
ipv6 = Ipv6ListSerializer(read_only=True, many=True)
|
2019-11-04 16:55:03 +00:00
|
|
|
vlan_id = serializers.IntegerField(
|
|
|
|
source="machine_type.ip_type.vlan.vlan_id", read_only=True
|
|
|
|
)
|
2018-07-08 02:08:01 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = machines.Interface
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("ipv4", "ipv6", "domain", "vlan_id")
|
|
|
|
|
2018-07-08 02:08:01 +00:00
|
|
|
|
|
|
|
class InterfaceRoleSerializer(NamespacedHMSerializer):
|
2019-11-04 16:55:03 +00:00
|
|
|
interface = InterfaceVlanSerializer(
|
|
|
|
source="machine.interface_set", read_only=True, many=True
|
|
|
|
)
|
2018-07-08 02:08:01 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = machines.Interface
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("interface",)
|
2018-07-08 02:08:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
class RoleSerializer(NamespacedHMSerializer):
|
|
|
|
"""Serialize `machines.models.OuverturePort` objects.
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2018-07-08 02:08:01 +00:00
|
|
|
servers = InterfaceRoleSerializer(read_only=True, many=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = machines.Role
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("role_type", "servers", "specific_role")
|
2018-07-08 02:08:01 +00:00
|
|
|
|
|
|
|
|
2018-07-07 15:06:08 +00:00
|
|
|
class VlanPortSerializer(NamespacedHMSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = machines.Vlan
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("vlan_id", "name")
|
2018-07-07 15:06:08 +00:00
|
|
|
|
|
|
|
|
2018-07-02 09:00:32 +00:00
|
|
|
class ProfilSerializer(NamespacedHMSerializer):
|
2018-07-07 15:06:08 +00:00
|
|
|
vlan_untagged = VlanSerializer(read_only=True)
|
|
|
|
vlan_tagged = VlanPortSerializer(read_only=True, many=True)
|
|
|
|
|
2018-07-02 09:00:32 +00:00
|
|
|
class Meta:
|
|
|
|
model = topologie.PortProfile
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = (
|
|
|
|
"name",
|
|
|
|
"profil_default",
|
|
|
|
"vlan_untagged",
|
|
|
|
"vlan_tagged",
|
|
|
|
"radius_type",
|
|
|
|
"radius_mode",
|
|
|
|
"speed",
|
|
|
|
"mac_limit",
|
|
|
|
"flow_control",
|
|
|
|
"dhcp_snooping",
|
|
|
|
"dhcpv6_snooping",
|
|
|
|
"arp_protect",
|
|
|
|
"ra_guard",
|
|
|
|
"loop_protect",
|
|
|
|
"vlan_untagged",
|
|
|
|
"vlan_tagged",
|
|
|
|
)
|
2018-07-02 09:00:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ModelSwitchSerializer(NamespacedHMSerializer):
|
2018-07-08 22:42:29 +00:00
|
|
|
constructor = serializers.CharField(read_only=True)
|
|
|
|
|
2018-07-02 09:00:32 +00:00
|
|
|
class Meta:
|
|
|
|
model = topologie.ModelSwitch
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("reference", "firmware", "constructor")
|
2018-07-02 09:00:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SwitchBaySerializer(NamespacedHMSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = topologie.SwitchBay
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("name",)
|
2018-07-02 09:00:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PortsSerializer(NamespacedHMSerializer):
|
|
|
|
"""Serialize `machines.models.Ipv6List` objects.
|
|
|
|
"""
|
|
|
|
|
2019-11-04 16:55:03 +00:00
|
|
|
get_port_profile = ProfilSerializer(read_only=True)
|
2018-07-07 15:06:08 +00:00
|
|
|
|
2018-07-02 09:00:32 +00:00
|
|
|
class Meta:
|
|
|
|
model = topologie.Port
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("state", "port", "pretty_name", "get_port_profile")
|
2018-07-02 09:00:32 +00:00
|
|
|
|
2018-07-07 15:06:08 +00:00
|
|
|
|
2018-07-02 09:00:32 +00:00
|
|
|
class SwitchPortSerializer(serializers.ModelSerializer):
|
|
|
|
"""Serialize the data about the switches"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2018-07-02 09:00:32 +00:00
|
|
|
ports = PortsSerializer(many=True, read_only=True)
|
|
|
|
model = ModelSwitchSerializer(read_only=True)
|
|
|
|
switchbay = SwitchBaySerializer(read_only=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = topologie.Switch
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = (
|
|
|
|
"short_name",
|
|
|
|
"model",
|
|
|
|
"switchbay",
|
|
|
|
"ports",
|
|
|
|
"ipv4",
|
|
|
|
"ipv6",
|
|
|
|
"interfaces_subnet",
|
|
|
|
"interfaces6_subnet",
|
|
|
|
"automatic_provision",
|
|
|
|
"rest_enabled",
|
|
|
|
"web_management_enabled",
|
|
|
|
"get_radius_key_value",
|
|
|
|
"get_management_cred_value",
|
|
|
|
"get_radius_servers",
|
|
|
|
"list_modules",
|
|
|
|
)
|
|
|
|
|
2018-07-11 17:46:13 +00:00
|
|
|
|
2018-07-30 15:00:41 +00:00
|
|
|
# LOCAL EMAILS
|
|
|
|
|
|
|
|
|
|
|
|
class LocalEmailUsersSerializer(NamespacedHMSerializer):
|
2019-11-04 16:55:03 +00:00
|
|
|
email_address = EMailAddressSerializer(read_only=True, many=True)
|
2018-07-15 20:31:42 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = users.User
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = (
|
|
|
|
"local_email_enabled",
|
|
|
|
"local_email_redirect",
|
|
|
|
"email_address",
|
|
|
|
"email",
|
|
|
|
)
|
2018-05-26 21:08:03 +00:00
|
|
|
|
|
|
|
|
2018-09-24 17:14:46 +00:00
|
|
|
# Firewall
|
2018-07-13 07:56:15 +00:00
|
|
|
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2018-07-13 07:56:15 +00:00
|
|
|
class FirewallPortListSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = machines.OuverturePort
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("begin", "end", "protocole", "io", "show_port")
|
2018-07-13 07:56:15 +00:00
|
|
|
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-07-13 07:56:15 +00:00
|
|
|
class FirewallOuverturePortListSerializer(serializers.ModelSerializer):
|
|
|
|
tcp_ports_in = FirewallPortListSerializer(many=True, read_only=True)
|
|
|
|
udp_ports_in = FirewallPortListSerializer(many=True, read_only=True)
|
|
|
|
tcp_ports_out = FirewallPortListSerializer(many=True, read_only=True)
|
|
|
|
udp_ports_out = FirewallPortListSerializer(many=True, read_only=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = machines.OuverturePortList
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("tcp_ports_in", "udp_ports_in", "tcp_ports_out", "udp_ports_out")
|
2018-07-13 07:56:15 +00:00
|
|
|
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-07-13 07:56:15 +00:00
|
|
|
class SubnetPortsOpenSerializer(serializers.ModelSerializer):
|
|
|
|
ouverture_ports = FirewallOuverturePortListSerializer(read_only=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = machines.IpType
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = (
|
|
|
|
"name",
|
|
|
|
"domaine_ip_start",
|
|
|
|
"domaine_ip_stop",
|
|
|
|
"complete_prefixv6",
|
|
|
|
"ouverture_ports",
|
|
|
|
)
|
2018-07-13 07:56:15 +00:00
|
|
|
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-08-05 12:36:32 +00:00
|
|
|
class InterfacePortsOpenSerializer(serializers.ModelSerializer):
|
|
|
|
port_lists = FirewallOuverturePortListSerializer(read_only=True, many=True)
|
2019-11-04 16:55:03 +00:00
|
|
|
ipv4 = serializers.CharField(source="ipv4.ipv4", read_only=True)
|
2018-08-05 12:36:32 +00:00
|
|
|
ipv6 = Ipv6ListSerializer(many=True, read_only=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = machines.Interface
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("port_lists", "ipv4", "ipv6")
|
2018-08-05 12:36:32 +00:00
|
|
|
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-05-24 23:07:23 +00:00
|
|
|
# DHCP
|
|
|
|
|
|
|
|
|
|
|
|
class HostMacIpSerializer(serializers.ModelSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize the data about the hostname-ipv4-mac address association
|
|
|
|
to build the DHCP lease files.
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
|
|
|
hostname = serializers.CharField(source="domain.name", read_only=True)
|
|
|
|
extension = serializers.CharField(source="domain.extension.name", read_only=True)
|
2018-05-25 15:36:07 +00:00
|
|
|
mac_address = serializers.CharField(read_only=True)
|
2020-02-04 10:54:17 +00:00
|
|
|
ip_type = serializers.CharField(source="machine_type.ip_type", read_only=True)
|
2019-11-04 16:55:03 +00:00
|
|
|
ipv4 = serializers.CharField(source="ipv4.ipv4", read_only=True)
|
2018-05-24 23:07:23 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = machines.Interface
|
2020-02-04 10:54:17 +00:00
|
|
|
fields = ("hostname", "extension", "mac_address", "ipv4", "ip_type")
|
2018-06-10 00:47:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
# DNS
|
|
|
|
|
|
|
|
|
|
|
|
class SOARecordSerializer(SOASerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `machines.models.SOA` objects with the data needed to
|
|
|
|
generate a SOA DNS record.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-06-10 00:47:25 +00:00
|
|
|
class Meta:
|
|
|
|
model = machines.SOA
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("name", "mail", "refresh", "retry", "expire", "ttl")
|
2018-06-10 00:47:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
class OriginV4RecordSerializer(IpListSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `machines.models.IpList` objects with the data needed to
|
|
|
|
generate an IPv4 Origin DNS record.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-06-10 00:47:25 +00:00
|
|
|
class Meta(IpListSerializer.Meta):
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("ipv4",)
|
2018-06-10 00:47:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
class NSRecordSerializer(NsSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `machines.models.Ns` objects with the data needed to
|
|
|
|
generate a NS DNS record.
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
|
|
|
target = serializers.CharField(source="ns", read_only=True)
|
2018-06-10 00:47:25 +00:00
|
|
|
|
|
|
|
class Meta(NsSerializer.Meta):
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("target",)
|
2018-06-10 00:47:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
class MXRecordSerializer(MxSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `machines.models.Mx` objects with the data needed to
|
|
|
|
generate a MX DNS record.
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
|
|
|
target = serializers.CharField(source="name", read_only=True)
|
2018-06-10 00:47:25 +00:00
|
|
|
|
|
|
|
class Meta(MxSerializer.Meta):
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("target", "priority")
|
2018-06-10 00:47:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TXTRecordSerializer(TxtSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `machines.models.Txt` objects with the data needed to
|
|
|
|
generate a TXT DNS record.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-06-10 00:47:25 +00:00
|
|
|
class Meta(TxtSerializer.Meta):
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("field1", "field2")
|
2018-06-10 00:47:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SRVRecordSerializer(SrvSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `machines.models.Srv` objects with the data needed to
|
|
|
|
generate a SRV DNS record.
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
|
|
|
target = serializers.CharField(source="target.name", read_only=True)
|
2018-06-10 00:47:25 +00:00
|
|
|
|
|
|
|
class Meta(SrvSerializer.Meta):
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("service", "protocole", "ttl", "priority", "weight", "port", "target")
|
2018-06-10 00:47:25 +00:00
|
|
|
|
|
|
|
|
2018-07-29 17:07:40 +00:00
|
|
|
class SSHFPRecordSerializer(SshFpSerializer):
|
|
|
|
"""Serialize `machines.models.SshFp` objects with the data needed to
|
|
|
|
generate a SSHFP DNS record.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-07-29 17:07:40 +00:00
|
|
|
class Meta(SshFpSerializer.Meta):
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("algo_id", "hash")
|
2018-07-29 17:07:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SSHFPInterfaceSerializer(serializers.ModelSerializer):
|
|
|
|
"""Serialize `machines.models.Domain` objects with the data needed to
|
|
|
|
generate a CNAME DNS record.
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
|
|
|
hostname = serializers.CharField(source="domain.name", read_only=True)
|
|
|
|
sshfp = SSHFPRecordSerializer(source="machine.sshfp_set", many=True, read_only=True)
|
2018-07-29 17:07:40 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = machines.Interface
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("hostname", "sshfp")
|
2018-07-29 17:07:40 +00:00
|
|
|
|
|
|
|
|
2018-06-10 00:47:25 +00:00
|
|
|
class ARecordSerializer(serializers.ModelSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `machines.models.Interface` objects with the data needed to
|
|
|
|
generate a A DNS record.
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
|
|
|
hostname = serializers.CharField(source="domain.name", read_only=True)
|
|
|
|
ipv4 = serializers.CharField(source="ipv4.ipv4", read_only=True)
|
2018-06-10 00:47:25 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = machines.Interface
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("hostname", "ipv4")
|
2018-06-10 00:47:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
class AAAARecordSerializer(serializers.ModelSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `machines.models.Interface` objects with the data needed to
|
|
|
|
generate a AAAA DNS record.
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
|
|
|
hostname = serializers.CharField(source="domain.name", read_only=True)
|
2018-06-10 13:41:31 +00:00
|
|
|
ipv6 = Ipv6ListSerializer(many=True, read_only=True)
|
2018-06-10 00:47:25 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = machines.Interface
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("hostname", "ipv6")
|
2018-06-10 00:47:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CNAMERecordSerializer(serializers.ModelSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize `machines.models.Domain` objects with the data needed to
|
|
|
|
generate a CNAME DNS record.
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
|
|
|
alias = serializers.CharField(source="cname", read_only=True)
|
|
|
|
hostname = serializers.CharField(source="name", read_only=True)
|
2018-06-10 00:47:25 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = machines.Domain
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("alias", "hostname")
|
|
|
|
|
2018-06-10 00:47:25 +00:00
|
|
|
|
2018-11-15 15:08:47 +00:00
|
|
|
class DNAMERecordSerializer(serializers.ModelSerializer):
|
|
|
|
"""Serialize `machines.models.Domain` objects with the data needed to
|
|
|
|
generate a DNAME DNS record.
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2018-11-15 15:08:47 +00:00
|
|
|
alias = serializers.CharField(read_only=True)
|
|
|
|
zone = serializers.CharField(read_only=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = machines.DName
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("alias", "zone")
|
2018-11-15 15:08:47 +00:00
|
|
|
|
2018-06-10 00:47:25 +00:00
|
|
|
|
2018-06-10 13:41:31 +00:00
|
|
|
class DNSZonesSerializer(serializers.ModelSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize the data about DNS Zones.
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2018-06-10 00:47:25 +00:00
|
|
|
soa = SOARecordSerializer()
|
2019-11-04 16:55:03 +00:00
|
|
|
ns_records = NSRecordSerializer(many=True, source="ns_set")
|
|
|
|
originv4 = OriginV4RecordSerializer(source="origin")
|
|
|
|
originv6 = serializers.CharField(source="origin_v6")
|
|
|
|
mx_records = MXRecordSerializer(many=True, source="mx_set")
|
|
|
|
txt_records = TXTRecordSerializer(many=True, source="txt_set")
|
|
|
|
srv_records = SRVRecordSerializer(many=True, source="srv_set")
|
|
|
|
a_records = ARecordSerializer(many=True, source="get_associated_a_records")
|
|
|
|
aaaa_records = AAAARecordSerializer(many=True, source="get_associated_aaaa_records")
|
|
|
|
cname_records = CNAMERecordSerializer(
|
|
|
|
many=True, source="get_associated_cname_records"
|
|
|
|
)
|
|
|
|
dname_records = DNAMERecordSerializer(
|
|
|
|
many=True, source="get_associated_dname_records"
|
|
|
|
)
|
|
|
|
sshfp_records = SSHFPInterfaceSerializer(
|
|
|
|
many=True, source="get_associated_sshfp_records"
|
|
|
|
)
|
2018-06-10 00:47:25 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = machines.Extension
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = (
|
|
|
|
"name",
|
|
|
|
"soa",
|
|
|
|
"ns_records",
|
|
|
|
"originv4",
|
|
|
|
"originv6",
|
|
|
|
"mx_records",
|
|
|
|
"txt_records",
|
|
|
|
"srv_records",
|
|
|
|
"a_records",
|
|
|
|
"aaaa_records",
|
|
|
|
"cname_records",
|
|
|
|
"dname_records",
|
|
|
|
"sshfp_records",
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# REMINDER
|
2018-07-03 16:34:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ReminderUsersSerializer(UserSerializer):
|
|
|
|
"""Serialize the data about a mailing member.
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2018-07-03 16:34:10 +00:00
|
|
|
class Meta(UserSerializer.Meta):
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("get_full_name", "get_mail")
|
2018-07-03 16:34:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ReminderSerializer(serializers.ModelSerializer):
|
|
|
|
"""
|
|
|
|
Serialize the data about a reminder
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2018-07-03 16:34:10 +00:00
|
|
|
users_to_remind = ReminderUsersSerializer(many=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = preferences.Reminder
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("days", "message", "users_to_remind")
|
2018-07-03 16:34:10 +00:00
|
|
|
|
2018-06-10 15:12:42 +00:00
|
|
|
|
2018-07-14 08:59:17 +00:00
|
|
|
class DNSReverseZonesSerializer(serializers.ModelSerializer):
|
|
|
|
"""Serialize the data about DNS Zones.
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
|
|
|
soa = SOARecordSerializer(source="extension.soa")
|
|
|
|
extension = serializers.CharField(source="extension.name", read_only=True)
|
|
|
|
cidrs = serializers.ListField(
|
|
|
|
child=serializers.CharField(), source="ip_set_cidrs_as_str", read_only=True
|
|
|
|
)
|
|
|
|
ns_records = NSRecordSerializer(many=True, source="extension.ns_set")
|
|
|
|
mx_records = MXRecordSerializer(many=True, source="extension.mx_set")
|
|
|
|
txt_records = TXTRecordSerializer(many=True, source="extension.txt_set")
|
|
|
|
ptr_records = ARecordSerializer(many=True, source="get_associated_ptr_records")
|
|
|
|
ptr_v6_records = AAAARecordSerializer(
|
|
|
|
many=True, source="get_associated_ptr_v6_records"
|
|
|
|
)
|
2018-07-14 08:59:17 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = machines.IpType
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = (
|
|
|
|
"name",
|
|
|
|
"extension",
|
|
|
|
"soa",
|
|
|
|
"ns_records",
|
|
|
|
"mx_records",
|
|
|
|
"txt_records",
|
|
|
|
"ptr_records",
|
|
|
|
"ptr_v6_records",
|
|
|
|
"cidrs",
|
|
|
|
"prefix_v6",
|
|
|
|
"prefix_v6_length",
|
|
|
|
)
|
2018-07-14 08:59:17 +00:00
|
|
|
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-06-17 01:06:58 +00:00
|
|
|
# MAILING
|
2018-06-10 15:12:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
class MailingMemberSerializer(UserSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize the data about a mailing member.
|
|
|
|
"""
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-06-10 15:12:42 +00:00
|
|
|
class Meta(UserSerializer.Meta):
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("name", "pseudo", "get_mail")
|
2018-06-10 15:12:42 +00:00
|
|
|
|
2018-09-24 17:14:46 +00:00
|
|
|
|
2018-06-10 15:12:42 +00:00
|
|
|
class MailingSerializer(ClubSerializer):
|
2018-06-17 01:06:58 +00:00
|
|
|
"""Serialize the data about a mailing.
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2018-06-10 15:12:42 +00:00
|
|
|
members = MailingMemberSerializer(many=True)
|
2019-11-04 16:55:03 +00:00
|
|
|
admins = MailingMemberSerializer(source="administrators", many=True)
|
2018-06-10 15:12:42 +00:00
|
|
|
|
|
|
|
class Meta(ClubSerializer.Meta):
|
2019-11-04 16:55:03 +00:00
|
|
|
fields = ("name", "members", "admins")
|