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
|
|
|
|
|
2019-01-29 15:33:26 +00:00
|
|
|
from re2o.serializers import NamespacedHRField, NamespacedHIField, NamespacedHMSerializer
|
2018-04-24 15:57:55 +00:00
|
|
|
|
2019-01-29 15:33:26 +00:00
|
|
|
from machines.api.serializers import (
|
|
|
|
VlanSerializer,
|
|
|
|
Ipv6ListSerializer,
|
|
|
|
SOASerializer,
|
|
|
|
IpListSerializer,
|
|
|
|
NsSerializer,
|
|
|
|
MxSerializer,
|
|
|
|
TxtSerializer,
|
|
|
|
SrvSerializer,
|
|
|
|
SshFpSerializer,
|
|
|
|
)
|
2018-04-24 15:57:55 +00:00
|
|
|
|
2019-01-29 15:33:26 +00:00
|
|
|
from users.api.serializers import (
|
|
|
|
UserSerializer,
|
|
|
|
ClubSerializer,
|
|
|
|
EMailAddressSerializer
|
|
|
|
)
|
2018-04-24 13:59:18 +00:00
|
|
|
|
|
|
|
|
2019-01-29 15:33:26 +00:00
|
|
|
# CONF SWITCH
|
2018-07-02 09:00:32 +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)
|
|
|
|
vlan_id = serializers.IntegerField(source='type.ip_type.vlan.vlan_id', read_only=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = machines.Interface
|
|
|
|
fields = ('ipv4', 'ipv6', 'domain', 'vlan_id')
|
|
|
|
|
|
|
|
class InterfaceRoleSerializer(NamespacedHMSerializer):
|
|
|
|
interface = InterfaceVlanSerializer(source='machine.interface_set', read_only=True, many=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = machines.Interface
|
|
|
|
fields = ('interface',)
|
|
|
|
|
|
|
|
|
|
|
|
class RoleSerializer(NamespacedHMSerializer):
|
|
|
|
"""Serialize `machines.models.OuverturePort` objects.
|
|
|
|
"""
|
|
|
|
servers = InterfaceRoleSerializer(read_only=True, many=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = machines.Role
|
2018-07-11 17:46:13 +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
|
2018-09-24 17:14:46 +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
|
2018-07-07 15:06:08 +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
|
2018-07-08 22:42:29 +00:00
|
|
|
fields = ('reference', 'firmware', 'constructor')
|
2018-07-02 09:00:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SwitchBaySerializer(NamespacedHMSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = topologie.SwitchBay
|
|
|
|
fields = ('name',)
|
|
|
|
|
|
|
|
|
|
|
|
class PortsSerializer(NamespacedHMSerializer):
|
|
|
|
"""Serialize `machines.models.Ipv6List` objects.
|
|
|
|
"""
|
2018-10-03 20:24:17 +00:00
|
|
|
get_port_profile = ProfilSerializer(read_only=True)
|
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 Meta:
|
|
|
|
model = topologie.Port
|
2018-10-03 20:24:17 +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"""
|
|
|
|
ports = PortsSerializer(many=True, read_only=True)
|
|
|
|
model = ModelSwitchSerializer(read_only=True)
|
|
|
|
switchbay = SwitchBaySerializer(read_only=True)
|
|
|
|
|
2018-07-07 15:06:08 +00:00
|
|
|
|
2018-07-02 09:00:32 +00:00
|
|
|
class Meta:
|
|
|
|
model = topologie.Switch
|
2018-07-09 20:59:47 +00:00
|
|
|
fields = ('short_name', 'model', 'switchbay', 'ports', 'ipv4', 'ipv6',
|
2018-07-11 23:12:46 +00:00
|
|
|
'interfaces_subnet', 'interfaces6_subnet', 'automatic_provision', 'rest_enabled',
|
2018-12-30 18:22:43 +00:00
|
|
|
'web_management_enabled', 'get_radius_key_value', 'get_management_cred_value',
|
|
|
|
'list_modules')
|
2018-07-11 17:46:13 +00:00
|
|
|
|
2019-01-29 15:33:26 +00:00
|
|
|
# SERVICE REGEN
|
2018-07-30 15:00:41 +00:00
|
|
|
|
|
|
|
|
2019-01-29 15:33:26 +00:00
|
|
|
class ServiceRegenSerializer(NamespacedHMSerializer):
|
|
|
|
"""Serialize the data about the services to regen.
|
|
|
|
"""
|
|
|
|
hostname = serializers.CharField(source='server.domain.name', read_only=True)
|
|
|
|
service_name = serializers.CharField(source='service.service_type', read_only=True)
|
|
|
|
need_regen = serializers.BooleanField()
|
2018-07-15 20:31:42 +00:00
|
|
|
|
|
|
|
class Meta:
|
2019-01-29 15:33:26 +00:00
|
|
|
model = machines.Service_link
|
|
|
|
fields = ('hostname', 'service_name', 'need_regen', 'api_url')
|
|
|
|
extra_kwargs = {
|
|
|
|
'api_url': {'view_name': 'serviceregen-detail'}
|
|
|
|
}
|
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
|
|
|
|
|
|
|
class FirewallPortListSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = machines.OuverturePort
|
2018-08-05 09:18:53 +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
|
|
|
|
fields = ('tcp_ports_in', 'udp_ports_in', 'tcp_ports_out', 'udp_ports_out')
|
|
|
|
|
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
|
2018-08-05 09:14:19 +00:00
|
|
|
fields = ('type', '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)
|
|
|
|
ipv4 = serializers.CharField(source='ipv4.ipv4', read_only=True)
|
|
|
|
ipv6 = Ipv6ListSerializer(many=True, read_only=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = machines.Interface
|
|
|
|
fields = ('port_lists', 'ipv4', 'ipv6')
|
|
|
|
|
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.
|
|
|
|
"""
|
2018-05-24 23:07:23 +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)
|
2018-05-24 23:07:23 +00:00
|
|
|
ipv4 = serializers.CharField(source='ipv4.ipv4', read_only=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = machines.Interface
|
|
|
|
fields = ('hostname', 'extension', 'mac_address', 'ipv4')
|
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
|
|
|
|
fields = ('name', 'mail', 'refresh', 'retry', 'expire', 'ttl')
|
|
|
|
|
|
|
|
|
|
|
|
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):
|
|
|
|
fields = ('ipv4',)
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
"""
|
2018-08-07 08:30:23 +00:00
|
|
|
target = serializers.CharField(source='ns', read_only=True)
|
2018-06-10 00:47:25 +00:00
|
|
|
|
|
|
|
class Meta(NsSerializer.Meta):
|
|
|
|
fields = ('target',)
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
"""
|
2018-08-07 08:30:23 +00:00
|
|
|
target = serializers.CharField(source='name', read_only=True)
|
2018-06-10 00:47:25 +00:00
|
|
|
|
|
|
|
class Meta(MxSerializer.Meta):
|
|
|
|
fields = ('target', 'priority')
|
|
|
|
|
|
|
|
|
|
|
|
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):
|
|
|
|
fields = ('field1', 'field2')
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
"""
|
2018-06-10 00:47:25 +00:00
|
|
|
target = serializers.CharField(source='target.name', read_only=True)
|
|
|
|
|
|
|
|
class Meta(SrvSerializer.Meta):
|
|
|
|
fields = ('service', 'protocole', 'ttl', 'priority', 'weight', 'port', 'target')
|
|
|
|
|
|
|
|
|
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):
|
|
|
|
fields = ('algo_id', 'hash')
|
|
|
|
|
|
|
|
|
|
|
|
class SSHFPInterfaceSerializer(serializers.ModelSerializer):
|
|
|
|
"""Serialize `machines.models.Domain` objects with the data needed to
|
|
|
|
generate a CNAME DNS record.
|
|
|
|
"""
|
|
|
|
hostname = serializers.CharField(source='domain.name', read_only=True)
|
|
|
|
sshfp = SSHFPRecordSerializer(source='machine.sshfp_set', many=True, read_only=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = machines.Interface
|
|
|
|
fields = ('hostname', 'sshfp')
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
"""
|
2018-06-10 00:47:25 +00:00
|
|
|
hostname = serializers.CharField(source='domain.name', read_only=True)
|
|
|
|
ipv4 = serializers.CharField(source='ipv4.ipv4', read_only=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = machines.Interface
|
|
|
|
fields = ('hostname', 'ipv4')
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
"""
|
2018-06-10 00:47:25 +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
|
|
|
|
fields = ('hostname', 'ipv6')
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
"""
|
2018-08-08 10:07:31 +00:00
|
|
|
alias = serializers.CharField(source='cname', read_only=True)
|
2018-06-10 00:47:25 +00:00
|
|
|
hostname = serializers.CharField(source='name', read_only=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = machines.Domain
|
2018-08-08 10:07:31 +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.
|
|
|
|
"""
|
|
|
|
alias = serializers.CharField(read_only=True)
|
|
|
|
zone = serializers.CharField(read_only=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = machines.DName
|
|
|
|
fields = ('alias', 'zone')
|
|
|
|
|
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.
|
|
|
|
"""
|
2018-06-10 00:47:25 +00:00
|
|
|
soa = SOARecordSerializer()
|
|
|
|
ns_records = NSRecordSerializer(many=True, source='ns_set')
|
|
|
|
originv4 = OriginV4RecordSerializer(source='origin')
|
2018-06-22 00:48:45 +00:00
|
|
|
originv6 = serializers.CharField(source='origin_v6')
|
2018-06-10 00:47:25 +00:00
|
|
|
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')
|
2018-11-15 15:08:47 +00:00
|
|
|
dname_records = DNAMERecordSerializer(many=True, source='get_associated_dname_records')
|
2018-07-29 17:07:40 +00:00
|
|
|
sshfp_records = SSHFPInterfaceSerializer(many=True, source='get_associated_sshfp_records')
|
2018-06-10 00:47:25 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = machines.Extension
|
|
|
|
fields = ('name', 'soa', 'ns_records', 'originv4', 'originv6',
|
|
|
|
'mx_records', 'txt_records', 'srv_records', 'a_records',
|
2018-11-15 15:08:47 +00:00
|
|
|
'aaaa_records', 'cname_records', 'dname_records', 'sshfp_records')
|
2018-07-03 16:34:10 +00:00
|
|
|
#REMINDER
|
|
|
|
|
|
|
|
|
|
|
|
class ReminderUsersSerializer(UserSerializer):
|
|
|
|
"""Serialize the data about a mailing member.
|
|
|
|
"""
|
|
|
|
class Meta(UserSerializer.Meta):
|
2018-10-31 19:16:06 +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
|
|
|
|
"""
|
|
|
|
users_to_remind = ReminderUsersSerializer(many=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = preferences.Reminder
|
|
|
|
fields = ('days','message','users_to_remind')
|
|
|
|
|
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.
|
|
|
|
"""
|
|
|
|
soa = SOARecordSerializer(source='extension.soa')
|
|
|
|
extension = serializers.CharField(source='extension.name', read_only=True)
|
2018-07-16 08:53:44 +00:00
|
|
|
cidrs = serializers.ListField(child=serializers.CharField(), source='ip_set_cidrs_as_str', read_only=True)
|
2018-07-14 08:59:17 +00:00
|
|
|
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')
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = machines.IpType
|
|
|
|
fields = ('type', 'extension', 'soa', 'ns_records', 'mx_records',
|
2018-07-16 18:09:02 +00:00
|
|
|
'txt_records', 'ptr_records', 'ptr_v6_records', 'cidrs',
|
2018-08-07 07:24:21 +00:00
|
|
|
'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):
|
2018-08-16 09:53:24 +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.
|
|
|
|
"""
|
2018-06-10 15:12:42 +00:00
|
|
|
members = MailingMemberSerializer(many=True)
|
|
|
|
admins = MailingMemberSerializer(source='administrators', many=True)
|
|
|
|
|
|
|
|
class Meta(ClubSerializer.Meta):
|
|
|
|
fields = ('name', 'members', 'admins')
|
2019-01-29 15:33:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
# LOCAL EMAILS
|
|
|
|
|
|
|
|
|
|
|
|
class LocalEmailUsersSerializer(NamespacedHMSerializer):
|
|
|
|
email_address = EMailAddressSerializer(
|
|
|
|
read_only=True,
|
|
|
|
many=True
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = users.User
|
|
|
|
fields = ('local_email_enabled', 'local_email_redirect',
|
|
|
|
'email_address', 'email')
|