8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-21 19:03:11 +00:00

First draft of moving api functions into each apps

This commit is contained in:
chapeau 2020-04-20 20:43:11 +02:00 committed by Gabriel Detraz
parent 334537e475
commit 0b58365c87
23 changed files with 2513 additions and 2185 deletions

File diff suppressed because it is too large Load diff

View file

@ -31,111 +31,34 @@ from django.conf.urls import url, include
from . import views
from .routers import AllViewsRouter
from cotisations.api.urls import urls_viewset as urls_viewset_cotisations
from cotisations.api.urls import urls_view as urls_view_cotisations
from machines.api.urls import urls_viewset as urls_viewset_machines
from machines.api.urls import urls_view as urls_view_machines
from preferences.api.urls import urls_viewset as urls_viewset_preferences
from preferences.api.urls import urls_view as urls_view_preferences
from topologie.api.urls import urls_viewset as urls_viewset_topologie
from topologie.api.urls import urls_view as urls_view_topologie
from users.api.urls import urls_viewset as urls_viewset_users
from users.api.urls import urls_view as urls_view_users
urls_viewset = urls_viewset_cotisations + urls_viewset_machines + urls_viewset_preferences + urls_viewset_topologie + urls_viewset_users
urls_view = urls_view_cotisations + urls_view_machines + urls_view_preferences + urls_view_topologie + urls_view_users
router = AllViewsRouter()
# COTISATIONS
router.register_viewset(r"cotisations/facture", views.FactureViewSet)
router.register_viewset(r"cotisations/vente", views.VenteViewSet)
router.register_viewset(r"cotisations/article", views.ArticleViewSet)
router.register_viewset(r"cotisations/banque", views.BanqueViewSet)
router.register_viewset(r"cotisations/paiement", views.PaiementViewSet)
router.register_viewset(r"cotisations/cotisation", views.CotisationViewSet)
# MACHINES
router.register_viewset(r"machines/machine", views.MachineViewSet)
router.register_viewset(r"machines/machinetype", views.MachineTypeViewSet)
router.register_viewset(r"machines/iptype", views.IpTypeViewSet)
router.register_viewset(r"machines/vlan", views.VlanViewSet)
router.register_viewset(r"machines/nas", views.NasViewSet)
router.register_viewset(r"machines/soa", views.SOAViewSet)
router.register_viewset(r"machines/extension", views.ExtensionViewSet)
router.register_viewset(r"machines/mx", views.MxViewSet)
router.register_viewset(r"machines/ns", views.NsViewSet)
router.register_viewset(r"machines/txt", views.TxtViewSet)
router.register_viewset(r"machines/dname", views.DNameViewSet)
router.register_viewset(r"machines/srv", views.SrvViewSet)
router.register_viewset(r"machines/sshfp", views.SshFpViewSet)
router.register_viewset(r"machines/interface", views.InterfaceViewSet)
router.register_viewset(r"machines/ipv6list", views.Ipv6ListViewSet)
router.register_viewset(r"machines/domain", views.DomainViewSet)
router.register_viewset(r"machines/iplist", views.IpListViewSet)
router.register_viewset(r"machines/service", views.ServiceViewSet)
router.register_viewset(
r"machines/servicelink", views.ServiceLinkViewSet, base_name="servicelink"
)
router.register_viewset(r"machines/ouvertureportlist", views.OuverturePortListViewSet)
router.register_viewset(r"machines/ouvertureport", views.OuverturePortViewSet)
router.register_viewset(r"machines/role", views.RoleViewSet)
# PREFERENCES
router.register_view(r"preferences/optionaluser", views.OptionalUserView),
router.register_view(r"preferences/optionalmachine", views.OptionalMachineView),
router.register_view(r"preferences/optionaltopologie", views.OptionalTopologieView),
router.register_view(r"preferences/radiusoption", views.RadiusOptionView),
router.register_view(r"preferences/generaloption", views.GeneralOptionView),
router.register_viewset(
r"preferences/service", views.HomeServiceViewSet, base_name="homeservice"
),
router.register_view(r"preferences/assooption", views.AssoOptionView),
router.register_view(r"preferences/homeoption", views.HomeOptionView),
router.register_view(r"preferences/mailmessageoption", views.MailMessageOptionView),
# TOPOLOGIE
router.register_viewset(r"topologie/stack", views.StackViewSet)
router.register_viewset(r"topologie/acesspoint", views.AccessPointViewSet)
router.register_viewset(r"topologie/switch", views.SwitchViewSet)
router.register_viewset(r"topologie/server", views.ServerViewSet)
router.register_viewset(r"topologie/modelswitch", views.ModelSwitchViewSet)
router.register_viewset(r"topologie/constructorswitch", views.ConstructorSwitchViewSet)
router.register_viewset(r"topologie/switchbay", views.SwitchBayViewSet)
router.register_viewset(r"topologie/building", views.BuildingViewSet)
router.register_viewset(
r"topologie/switchport", views.SwitchPortViewSet, base_name="switchport"
)
router.register_viewset(
r"topologie/portprofile", views.PortProfileViewSet, base_name="portprofile"
)
router.register_viewset(r"topologie/room", views.RoomViewSet)
router.register(r"topologie/portprofile", views.PortProfileViewSet)
# USERS
router.register_viewset(r"users/user", views.UserViewSet, base_name="user")
router.register_viewset(
r"users/homecreation", views.HomeCreationViewSet, base_name="homecreation"
)
router.register_viewset(
r"users/normaluser", views.NormalUserViewSet, base_name="normaluser"
)
router.register_viewset(
r"users/criticaluser", views.CriticalUserViewSet, base_name="criticaluser"
)
router.register_viewset(r"users/club", views.ClubViewSet)
router.register_viewset(r"users/adherent", views.AdherentViewSet)
router.register_viewset(r"users/serviceuser", views.ServiceUserViewSet)
router.register_viewset(r"users/school", views.SchoolViewSet)
router.register_viewset(r"users/listright", views.ListRightViewSet)
router.register_viewset(r"users/shell", views.ShellViewSet, base_name="shell")
router.register_viewset(r"users/ban", views.BanViewSet)
router.register_viewset(r"users/whitelist", views.WhitelistViewSet)
router.register_viewset(r"users/emailaddress", views.EMailAddressViewSet)
# SERVICE REGEN
router.register_viewset(
r"services/regen", views.ServiceRegenViewSet, base_name="serviceregen"
)
# DHCP
router.register_view(r"dhcp/hostmacip", views.HostMacIpView),
# LOCAL EMAILS
router.register_view(r"localemail/users", views.LocalEmailUsersView),
# Firewall
router.register_view(r"firewall/subnet-ports", views.SubnetPortsOpenView),
router.register_view(r"firewall/interface-ports", views.InterfacePortsOpenView),
# Switches config
router.register_view(r"switchs/ports-config", views.SwitchPortView),
router.register_view(r"switchs/role", views.RoleView),
for _url, viewset, name in urls_viewset:
if name == None:
router.register_viewset(_url, viewset)
else:
router.register_viewset(_url, viewset, basename=name)
for _url, view in urls_view:
router.register_view(_url, view)
# Reminder
router.register_view(r"reminder/get-users", views.ReminderView),
# DNS
router.register_view(r"dns/zones", views.DNSZonesView),
router.register_view(r"dns/reverse-zones", views.DNSReverseZonesView),
# MAILING
router.register_view(r"mailing/standard", views.StandardMailingView),
router.register_view(r"mailing/club", views.ClubMailingView),
# TOKEN AUTHENTICATION
router.register_view(r"token-auth", views.ObtainExpiringAuthToken)

View file

@ -36,7 +36,7 @@ from rest_framework.authtoken.models import Token
from rest_framework.authtoken.views import ObtainAuthToken
from rest_framework.response import Response
import cotisations.models as cotisations
# import cotisations.models as cotisations
import machines.models as machines
import preferences.models as preferences
import topologie.models as topologie
@ -47,611 +47,6 @@ from .pagination import PageSizedPagination
from .permissions import ACLPermission
# COTISATIONS
class FactureViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `cotisations.models.Facture` objects.
"""
queryset = cotisations.Facture.objects.all()
serializer_class = serializers.FactureSerializer
class FactureViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `cotisations.models.Facture` objects.
"""
queryset = cotisations.BaseInvoice.objects.all()
serializer_class = serializers.BaseInvoiceSerializer
class VenteViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `cotisations.models.Vente` objects.
"""
queryset = cotisations.Vente.objects.all()
serializer_class = serializers.VenteSerializer
class ArticleViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `cotisations.models.Article` objects.
"""
queryset = cotisations.Article.objects.all()
serializer_class = serializers.ArticleSerializer
class BanqueViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `cotisations.models.Banque` objects.
"""
queryset = cotisations.Banque.objects.all()
serializer_class = serializers.BanqueSerializer
class PaiementViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `cotisations.models.Paiement` objects.
"""
queryset = cotisations.Paiement.objects.all()
serializer_class = serializers.PaiementSerializer
class CotisationViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `cotisations.models.Cotisation` objects.
"""
queryset = cotisations.Cotisation.objects.all()
serializer_class = serializers.CotisationSerializer
# MACHINES
class MachineViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.Machine` objects.
"""
queryset = machines.Machine.objects.all()
serializer_class = serializers.MachineSerializer
class MachineTypeViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.MachineType` objects.
"""
queryset = machines.MachineType.objects.all()
serializer_class = serializers.MachineTypeSerializer
class IpTypeViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.IpType` objects.
"""
queryset = machines.IpType.objects.all()
serializer_class = serializers.IpTypeSerializer
class VlanViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.Vlan` objects.
"""
queryset = machines.Vlan.objects.all()
serializer_class = serializers.VlanSerializer
class NasViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.Nas` objects.
"""
queryset = machines.Nas.objects.all()
serializer_class = serializers.NasSerializer
class SOAViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.SOA` objects.
"""
queryset = machines.SOA.objects.all()
serializer_class = serializers.SOASerializer
class ExtensionViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.Extension` objects.
"""
queryset = machines.Extension.objects.all()
serializer_class = serializers.ExtensionSerializer
class MxViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.Mx` objects.
"""
queryset = machines.Mx.objects.all()
serializer_class = serializers.MxSerializer
class NsViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.Ns` objects.
"""
queryset = machines.Ns.objects.all()
serializer_class = serializers.NsSerializer
class TxtViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.Txt` objects.
"""
queryset = machines.Txt.objects.all()
serializer_class = serializers.TxtSerializer
class DNameViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.DName` objects.
"""
queryset = machines.DName.objects.all()
serializer_class = serializers.DNameSerializer
class SrvViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.Srv` objects.
"""
queryset = machines.Srv.objects.all()
serializer_class = serializers.SrvSerializer
class SshFpViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.SshFp` objects.
"""
queryset = machines.SshFp.objects.all()
serializer_class = serializers.SshFpSerializer
class InterfaceViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.Interface` objects.
"""
queryset = machines.Interface.objects.all()
serializer_class = serializers.InterfaceSerializer
class Ipv6ListViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.Ipv6List` objects.
"""
queryset = machines.Ipv6List.objects.all()
serializer_class = serializers.Ipv6ListSerializer
class DomainViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.Domain` objects.
"""
queryset = machines.Domain.objects.all()
serializer_class = serializers.DomainSerializer
class IpListViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.IpList` objects.
"""
queryset = machines.IpList.objects.all()
serializer_class = serializers.IpListSerializer
class ServiceViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.Service` objects.
"""
queryset = machines.Service.objects.all()
serializer_class = serializers.ServiceSerializer
class ServiceLinkViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.Service_link` objects.
"""
queryset = machines.Service_link.objects.all()
serializer_class = serializers.ServiceLinkSerializer
class OuverturePortListViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.OuverturePortList`
objects.
"""
queryset = machines.OuverturePortList.objects.all()
serializer_class = serializers.OuverturePortListSerializer
class OuverturePortViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.OuverturePort` objects.
"""
queryset = machines.OuverturePort.objects.all()
serializer_class = serializers.OuverturePortSerializer
class RoleViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.Machine` objects.
"""
queryset = machines.Role.objects.all()
serializer_class = serializers.RoleSerializer
# PREFERENCES
# Those views differ a bit because there is only one object
# to display, so we don't bother with the listing part
class OptionalUserView(generics.RetrieveAPIView):
"""Exposes details of `preferences.models.` settings.
"""
permission_classes = (ACLPermission,)
perms_map = {"GET": [preferences.OptionalUser.can_view_all]}
serializer_class = serializers.OptionalUserSerializer
def get_object(self):
return preferences.OptionalUser.objects.first()
class OptionalMachineView(generics.RetrieveAPIView):
"""Exposes details of `preferences.models.OptionalMachine` settings.
"""
permission_classes = (ACLPermission,)
perms_map = {"GET": [preferences.OptionalMachine.can_view_all]}
serializer_class = serializers.OptionalMachineSerializer
def get_object(self):
return preferences.OptionalMachine.objects.first()
class OptionalTopologieView(generics.RetrieveAPIView):
"""Exposes details of `preferences.models.OptionalTopologie` settings.
"""
permission_classes = (ACLPermission,)
perms_map = {"GET": [preferences.OptionalTopologie.can_view_all]}
serializer_class = serializers.OptionalTopologieSerializer
def get_object(self):
return preferences.OptionalTopologie.objects.first()
class RadiusOptionView(generics.RetrieveAPIView):
"""Exposes details of `preferences.models.OptionalTopologie` settings.
"""
permission_classes = (ACLPermission,)
perms_map = {"GET": [preferences.RadiusOption.can_view_all]}
serializer_class = serializers.RadiusOptionSerializer
def get_object(self):
return preferences.RadiusOption.objects.first()
class GeneralOptionView(generics.RetrieveAPIView):
"""Exposes details of `preferences.models.GeneralOption` settings.
"""
permission_classes = (ACLPermission,)
perms_map = {"GET": [preferences.GeneralOption.can_view_all]}
serializer_class = serializers.GeneralOptionSerializer
def get_object(self):
return preferences.GeneralOption.objects.first()
class HomeServiceViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `preferences.models.Service` objects.
"""
queryset = preferences.Service.objects.all()
serializer_class = serializers.HomeServiceSerializer
class AssoOptionView(generics.RetrieveAPIView):
"""Exposes details of `preferences.models.AssoOption` settings.
"""
permission_classes = (ACLPermission,)
perms_map = {"GET": [preferences.AssoOption.can_view_all]}
serializer_class = serializers.AssoOptionSerializer
def get_object(self):
return preferences.AssoOption.objects.first()
class HomeOptionView(generics.RetrieveAPIView):
"""Exposes details of `preferences.models.HomeOption` settings.
"""
permission_classes = (ACLPermission,)
perms_map = {"GET": [preferences.HomeOption.can_view_all]}
serializer_class = serializers.HomeOptionSerializer
def get_object(self):
return preferences.HomeOption.objects.first()
class MailMessageOptionView(generics.RetrieveAPIView):
"""Exposes details of `preferences.models.MailMessageOption` settings.
"""
permission_classes = (ACLPermission,)
perms_map = {"GET": [preferences.MailMessageOption.can_view_all]}
serializer_class = serializers.MailMessageOptionSerializer
def get_object(self):
return preferences.MailMessageOption.objects.first()
# TOPOLOGIE
class StackViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `topologie.models.Stack` objects.
"""
queryset = topologie.Stack.objects.all()
serializer_class = serializers.StackSerializer
class AccessPointViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `topologie.models.AccessPoint` objects.
"""
queryset = topologie.AccessPoint.objects.all()
serializer_class = serializers.AccessPointSerializer
class SwitchViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `topologie.models.Switch` objects.
"""
queryset = topologie.Switch.objects.all()
serializer_class = serializers.SwitchSerializer
class ServerViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `topologie.models.Server` objects.
"""
queryset = topologie.Server.objects.all()
serializer_class = serializers.ServerSerializer
class ModelSwitchViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `topologie.models.ModelSwitch` objects.
"""
queryset = topologie.ModelSwitch.objects.all()
serializer_class = serializers.ModelSwitchSerializer
class ConstructorSwitchViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `topologie.models.ConstructorSwitch`
objects.
"""
queryset = topologie.ConstructorSwitch.objects.all()
serializer_class = serializers.ConstructorSwitchSerializer
class SwitchBayViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `topologie.models.SwitchBay` objects.
"""
queryset = topologie.SwitchBay.objects.all()
serializer_class = serializers.SwitchBaySerializer
class BuildingViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `topologie.models.Building` objects.
"""
queryset = topologie.Building.objects.all()
serializer_class = serializers.BuildingSerializer
class SwitchPortViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `topologie.models.Port` objects.
"""
queryset = topologie.Port.objects.all()
serializer_class = serializers.SwitchPortSerializer
class PortProfileViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `topologie.models.PortProfile` objects.
"""
queryset = topologie.PortProfile.objects.all()
serializer_class = serializers.PortProfileSerializer
class RoomViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `topologie.models.Room` objects.
"""
queryset = topologie.Room.objects.all()
serializer_class = serializers.RoomSerializer
class PortProfileViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `topologie.models.PortProfile` objects.
"""
queryset = topologie.PortProfile.objects.all()
serializer_class = serializers.PortProfileSerializer
# USER
class UserViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `users.models.Users` objects.
"""
queryset = users.User.objects.all()
serializer_class = serializers.UserSerializer
class HomeCreationViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes infos of `users.models.Users` objects to create homes.
"""
queryset = users.User.objects.exclude(
Q(state=users.User.STATE_DISABLED)
| Q(state=users.User.STATE_NOT_YET_ACTIVE)
| Q(state=users.User.STATE_FULL_ARCHIVE)
)
serializer_class = serializers.BasicUserSerializer
class NormalUserViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes infos of `users.models.Users`without specific rights objects."""
queryset = users.User.objects.exclude(groups__listright__critical=True).distinct()
serializer_class = serializers.BasicUserSerializer
class CriticalUserViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes infos of `users.models.Users`without specific rights objects."""
queryset = users.User.objects.filter(groups__listright__critical=True).distinct()
serializer_class = serializers.BasicUserSerializer
class ClubViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `users.models.Club` objects.
"""
queryset = users.Club.objects.all()
serializer_class = serializers.ClubSerializer
class AdherentViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `users.models.Adherent` objects.
"""
queryset = users.Adherent.objects.all()
serializer_class = serializers.AdherentSerializer
class ServiceUserViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `users.models.ServiceUser` objects.
"""
queryset = users.ServiceUser.objects.all()
serializer_class = serializers.ServiceUserSerializer
class SchoolViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `users.models.School` objects.
"""
queryset = users.School.objects.all()
serializer_class = serializers.SchoolSerializer
class ListRightViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `users.models.ListRight` objects.
"""
queryset = users.ListRight.objects.all()
serializer_class = serializers.ListRightSerializer
class ShellViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `users.models.ListShell` objects.
"""
queryset = users.ListShell.objects.all()
serializer_class = serializers.ShellSerializer
class BanViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `users.models.Ban` objects.
"""
queryset = users.Ban.objects.all()
serializer_class = serializers.BanSerializer
class WhitelistViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `users.models.Whitelist` objects.
"""
queryset = users.Whitelist.objects.all()
serializer_class = serializers.WhitelistSerializer
class EMailAddressViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `users.models.EMailAddress` objects.
"""
serializer_class = serializers.EMailAddressSerializer
queryset = users.EMailAddress.objects.none()
def get_queryset(self):
if preferences.OptionalUser.get_cached_value("local_email_accounts_enabled"):
return users.EMailAddress.objects.filter(user__local_email_enabled=True)
else:
return users.EMailAddress.objects.none()
# SERVICE REGEN
class ServiceRegenViewSet(viewsets.ModelViewSet):
"""Exposes list and details of the services to regen
"""
serializer_class = serializers.ServiceRegenSerializer
def get_queryset(self):
queryset = machines.Service_link.objects.select_related(
"server__domain"
).select_related("service")
if "hostname" in self.request.GET:
hostname = self.request.GET["hostname"]
queryset = queryset.filter(server__domain__name__iexact=hostname)
return queryset
# Config des switches
class SwitchPortView(generics.ListAPIView):
"""Output each port of a switch, to be serialized with
additionnal informations (profiles etc)
"""
queryset = (
topologie.Switch.objects.all()
.select_related("switchbay")
.select_related("model__constructor")
.prefetch_related("ports__custom_profile__vlan_tagged")
.prefetch_related("ports__custom_profile__vlan_untagged")
.prefetch_related("ports__machine_interface__domain__extension")
.prefetch_related("ports__room")
)
serializer_class = serializers.SwitchPortSerializer
# Rappel fin adhésion
class ReminderView(generics.ListAPIView):
"""Output for users to remind an end of their subscription.
@ -660,132 +55,6 @@ class ReminderView(generics.ListAPIView):
queryset = preferences.Reminder.objects.all()
serializer_class = serializers.ReminderSerializer
class RoleView(generics.ListAPIView):
"""Output of roles for each server
"""
queryset = machines.Role.objects.all().prefetch_related("servers")
serializer_class = serializers.RoleSerializer
# LOCAL EMAILS
class LocalEmailUsersView(generics.ListAPIView):
"""Exposes all the aliases of the users that activated the internal address
"""
serializer_class = serializers.LocalEmailUsersSerializer
def get_queryset(self):
if preferences.OptionalUser.get_cached_value("local_email_accounts_enabled"):
return users.User.objects.filter(local_email_enabled=True)
else:
return users.User.objects.none()
# DHCP
class HostMacIpView(generics.ListAPIView):
"""Exposes the associations between hostname, mac address and IPv4 in
order to build the DHCP lease files.
"""
serializer_class = serializers.HostMacIpSerializer
def get_queryset(self):
return all_active_interfaces()
# Firewall
class SubnetPortsOpenView(generics.ListAPIView):
queryset = machines.IpType.objects.all()
serializer_class = serializers.SubnetPortsOpenSerializer
class InterfacePortsOpenView(generics.ListAPIView):
queryset = machines.Interface.objects.filter(port_lists__isnull=False).distinct()
serializer_class = serializers.InterfacePortsOpenSerializer
# DNS
class DNSZonesView(generics.ListAPIView):
"""Exposes the detailed information about each extension (hostnames,
IPs, DNS records, etc.) in order to build the DNS zone files.
"""
queryset = (
machines.Extension.objects.prefetch_related("soa")
.prefetch_related("ns_set")
.prefetch_related("ns_set__ns")
.prefetch_related("origin")
.prefetch_related("mx_set")
.prefetch_related("mx_set__name")
.prefetch_related("txt_set")
.prefetch_related("srv_set")
.prefetch_related("srv_set__target")
.all()
)
serializer_class = serializers.DNSZonesSerializer
class DNSReverseZonesView(generics.ListAPIView):
"""Exposes the detailed information about each extension (hostnames,
IPs, DNS records, etc.) in order to build the DNS zone files.
"""
queryset = machines.IpType.objects.all()
serializer_class = serializers.DNSReverseZonesSerializer
# MAILING
class StandardMailingView(views.APIView):
"""Exposes list and details of standard mailings (name and members) in
order to building the corresponding mailing lists.
"""
pagination_class = PageSizedPagination
permission_classes = (ACLPermission,)
perms_map = {"GET": [users.User.can_view_all]}
def get(self, request, format=None):
adherents_data = serializers.MailingMemberSerializer(
all_has_access(), many=True
).data
data = [{"name": "adherents", "members": adherents_data}]
groups = Group.objects.all()
for group in groups:
group_data = serializers.MailingMemberSerializer(
group.user_set.all(), many=True
).data
data.append({"name": group.name, "members": group_data})
paginator = self.pagination_class()
paginator.paginate_queryset(data, request)
return paginator.get_paginated_response(data)
class ClubMailingView(generics.ListAPIView):
"""Exposes list and details of club mailings (name, members and admins) in
order to build the corresponding mailing lists.
"""
queryset = users.Club.objects.all()
serializer_class = serializers.MailingSerializer
# TOKEN AUTHENTICATION
class ObtainExpiringAuthToken(ObtainAuthToken):
"""Exposes a view to obtain a authentication token.

View file

View file

@ -0,0 +1,105 @@
# -*- mode: python; coding: utf-8 -*-
# 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.
#
# Copyright © 2018 Maël Kervella
#
# 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.
from rest_framework import serializers
import cotisations.models as cotisations
from api.serializers import NamespacedHRField, NamespacedHIField, NamespacedHMSerializer
class FactureSerializer(NamespacedHMSerializer):
"""Serialize `cotisations.models.Facture` objects.
"""
class Meta:
model = cotisations.Facture
fields = (
"user",
"paiement",
"banque",
"cheque",
"date",
"valid",
"control",
"prix_total",
"name",
"api_url",
)
class BaseInvoiceSerializer(NamespacedHMSerializer):
class Meta:
model = cotisations.BaseInvoice
fields = "__all__"
class VenteSerializer(NamespacedHMSerializer):
"""Serialize `cotisations.models.Vente` objects.
"""
class Meta:
model = cotisations.Vente
fields = (
"facture",
"number",
"name",
"prix",
"duration",
"type_cotisation",
"prix_total",
"api_url",
)
class ArticleSerializer(NamespacedHMSerializer):
"""Serialize `cotisations.models.Article` objects.
"""
class Meta:
model = cotisations.Article
fields = ("name", "prix", "duration", "type_user", "type_cotisation", "api_url")
class BanqueSerializer(NamespacedHMSerializer):
"""Serialize `cotisations.models.Banque` objects.
"""
class Meta:
model = cotisations.Banque
fields = ("name", "api_url")
class PaiementSerializer(NamespacedHMSerializer):
"""Serialize `cotisations.models.Paiement` objects.
"""
class Meta:
model = cotisations.Paiement
fields = ("moyen", "api_url")
class CotisationSerializer(NamespacedHMSerializer):
"""Serialize `cotisations.models.Cotisation` objects.
"""
class Meta:
model = cotisations.Cotisation
fields = ("vente", "type_cotisation", "date_start", "date_end", "api_url")

35
cotisations/api/urls.py Normal file
View file

@ -0,0 +1,35 @@
# -*- mode: python; coding: utf-8 -*-
# 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.
#
# Copyright © 2018 Maël Kervella
#
# 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.
from . import views
urls_viewset = [
(r"cotisations/facture", views.FactureViewSet, None),
(r"cotisations/vente", views.VenteViewSet, None),
(r"cotisations/article", views.ArticleViewSet, None),
(r"cotisations/banque", views.BanqueViewSet, None),
(r"cotisations/paiement", views.PaiementViewSet, None),
(r"cotisations/cotisation", views.CotisationViewSet, None)
]
urls_view = [
# (r"reminder/get-users", views.ReminderView),
]

80
cotisations/api/views.py Normal file
View file

@ -0,0 +1,80 @@
# -*- mode: python; coding: utf-8 -*-
# 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.
#
# Copyright © 2018 Maël Kervella
#
# 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.
from rest_framework import viewsets, generics
from . import serializers
import cotisations.models as cotisations
class FactureViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `cotisations.models.Facture` objects.
"""
queryset = cotisations.Facture.objects.all()
serializer_class = serializers.FactureSerializer
class FactureViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `cotisations.models.Facture` objects.
"""
queryset = cotisations.BaseInvoice.objects.all()
serializer_class = serializers.BaseInvoiceSerializer
class VenteViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `cotisations.models.Vente` objects.
"""
queryset = cotisations.Vente.objects.all()
serializer_class = serializers.VenteSerializer
class ArticleViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `cotisations.models.Article` objects.
"""
queryset = cotisations.Article.objects.all()
serializer_class = serializers.ArticleSerializer
class BanqueViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `cotisations.models.Banque` objects.
"""
queryset = cotisations.Banque.objects.all()
serializer_class = serializers.BanqueSerializer
class PaiementViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `cotisations.models.Paiement` objects.
"""
queryset = cotisations.Paiement.objects.all()
serializer_class = serializers.PaiementSerializer
class CotisationViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `cotisations.models.Cotisation` objects.
"""
queryset = cotisations.Cotisation.objects.all()
serializer_class = serializers.CotisationSerializer

0
machines/api/__init__.py Normal file
View file

592
machines/api/serializers.py Normal file
View file

@ -0,0 +1,592 @@
# -*- mode: python; coding: utf-8 -*-
# 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.
#
# Copyright © 2018 Maël Kervella
#
# 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.
from rest_framework import serializers
import machines.models as machines
from api.serializers import NamespacedHRField, NamespacedHIField, NamespacedHMSerializer
class MachineSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.Machine` objects.
"""
class Meta:
model = machines.Machine
fields = ("user", "name", "active", "api_url")
class MachineTypeSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.MachineType` objects.
"""
class Meta:
model = machines.MachineType
fields = ("name", "ip_type", "api_url")
class IpTypeSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.IpType` objects.
"""
class Meta:
model = machines.IpType
fields = (
"name",
"extension",
"need_infra",
"domaine_ip_start",
"domaine_ip_stop",
"prefix_v6",
"vlan",
"ouverture_ports",
"api_url",
)
class VlanSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.Vlan` objects.
"""
class Meta:
model = machines.Vlan
fields = (
"vlan_id",
"name",
"comment",
"arp_protect",
"dhcp_snooping",
"dhcpv6_snooping",
"igmp",
"mld",
"api_url",
)
class NasSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.Nas` objects.
"""
class Meta:
model = machines.Nas
fields = (
"name",
"nas_type",
"machine_type",
"port_access_mode",
"autocapture_mac",
"api_url",
)
class SOASerializer(NamespacedHMSerializer):
"""Serialize `machines.models.SOA` objects.
"""
class Meta:
model = machines.SOA
fields = ("name", "mail", "refresh", "retry", "expire", "ttl", "api_url")
class ExtensionSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.Extension` objects.
"""
class Meta:
model = machines.Domain
fields = ("interface_parent", "name", "extension", "cname", "api_url", "ttl")
class MxSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.Mx` objects.
"""
class Meta:
model = machines.Mx
fields = ("zone", "priority", "name", "api_url")
class DNameSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.DName` objects.
"""
class Meta:
model = machines.DName
fields = ("zone", "alias", "api_url")
class NsSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.Ns` objects.
"""
class Meta:
model = machines.Ns
fields = ("zone", "ns", "api_url")
class TxtSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.Txt` objects.
"""
class Meta:
model = machines.Txt
fields = ("zone", "field1", "field2", "api_url")
class SrvSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.Srv` objects.
"""
class Meta:
model = machines.Srv
fields = (
"service",
"protocole",
"extension",
"ttl",
"priority",
"weight",
"port",
"target",
"api_url",
)
class SshFpSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.SSHFP` objects.
"""
class Meta:
model = machines.SshFp
field = ("machine", "pub_key_entry", "algo", "comment", "api_url")
class InterfaceSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.Interface` objects.
"""
mac_address = serializers.CharField()
active = serializers.BooleanField(source="is_active")
class Meta:
model = machines.Interface
fields = (
"ipv4",
"mac_address",
"machine",
"machine_type",
"details",
"port_lists",
"active",
"api_url",
)
class Ipv6ListSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.Ipv6List` objects.
"""
class Meta:
model = machines.Ipv6List
fields = ("ipv6", "interface", "slaac_ip", "api_url")
class DomainSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.Domain` objects.
"""
class Meta:
model = machines.Domain
fields = ("interface_parent", "name", "extension", "cname", "api_url")
class IpListSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.IpList` objects.
"""
class Meta:
model = machines.IpList
fields = ("ipv4", "ip_type", "need_infra", "api_url")
class ServiceSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.Service` objects.
"""
class Meta:
model = machines.Service
fields = (
"service_type",
"min_time_regen",
"regular_time_regen",
"servers",
"api_url",
)
class ServiceLinkSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.Service_link` objects.
"""
class Meta:
model = machines.Service_link
fields = (
"service",
"server",
"last_regen",
"asked_regen",
"need_regen",
"api_url",
)
extra_kwargs = {"api_url": {"view_name": "servicelink-detail"}}
class OuverturePortListSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.OuverturePortList` objects.
"""
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
)
class Meta:
model = machines.OuverturePortList
fields = (
"name",
"tcp_ports_in",
"udp_ports_in",
"tcp_ports_out",
"udp_ports_out",
"api_url",
)
class OuverturePortSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.OuverturePort` objects.
"""
class Meta:
model = machines.OuverturePort
fields = ("begin", "end", "port_list", "protocole", "io", "api_url")
class RoleSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.OuverturePort` objects.
"""
servers = InterfaceSerializer(read_only=True, many=True)
class Meta:
model = machines.Role
fields = ("role_type", "servers", "api_url")
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()
class Meta:
model = machines.Service_link
fields = ("hostname", "service_name", "need_regen", "api_url")
extra_kwargs = {"api_url": {"view_name": "serviceregen-detail"}}
class HostMacIpSerializer(serializers.ModelSerializer):
"""Serialize the data about the hostname-ipv4-mac address association
to build the DHCP lease files.
"""
hostname = serializers.CharField(source="domain.name", read_only=True)
extension = serializers.CharField(source="domain.extension.name", read_only=True)
mac_address = serializers.CharField(read_only=True)
ip_type = serializers.CharField(source="machine_type.ip_type", read_only=True)
ipv4 = serializers.CharField(source="ipv4.ipv4", read_only=True)
class Meta:
model = machines.Interface
fields = ("hostname", "extension", "mac_address", "ipv4", "ip_type")
class FirewallPortListSerializer(serializers.ModelSerializer):
class Meta:
model = machines.OuverturePort
fields = ("begin", "end", "protocole", "io", "show_port")
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")
class SubnetPortsOpenSerializer(serializers.ModelSerializer):
ouverture_ports = FirewallOuverturePortListSerializer(read_only=True)
class Meta:
model = machines.IpType
fields = (
"name",
"domaine_ip_start",
"domaine_ip_stop",
"complete_prefixv6",
"ouverture_ports",
)
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")
class SOARecordSerializer(SOASerializer):
"""Serialize `machines.models.SOA` objects with the data needed to
generate a SOA DNS record.
"""
class Meta:
model = machines.SOA
fields = ("name", "mail", "refresh", "retry", "expire", "ttl")
class OriginV4RecordSerializer(IpListSerializer):
"""Serialize `machines.models.IpList` objects with the data needed to
generate an IPv4 Origin DNS record.
"""
class Meta(IpListSerializer.Meta):
fields = ("ipv4",)
class NSRecordSerializer(NsSerializer):
"""Serialize `machines.models.Ns` objects with the data needed to
generate a NS DNS record.
"""
target = serializers.CharField(source="ns", read_only=True)
class Meta(NsSerializer.Meta):
fields = ("target", "ttl")
class MXRecordSerializer(MxSerializer):
"""Serialize `machines.models.Mx` objects with the data needed to
generate a MX DNS record.
"""
target = serializers.CharField(source="name", read_only=True)
class Meta(MxSerializer.Meta):
fields = ("target", "priority", "ttl")
class TXTRecordSerializer(TxtSerializer):
"""Serialize `machines.models.Txt` objects with the data needed to
generate a TXT DNS record.
"""
class Meta(TxtSerializer.Meta):
fields = ("field1", "field2", "ttl")
class SRVRecordSerializer(SrvSerializer):
"""Serialize `machines.models.Srv` objects with the data needed to
generate a SRV DNS record.
"""
target = serializers.CharField(source="target.name", read_only=True)
class Meta(SrvSerializer.Meta):
fields = ("service", "protocole", "ttl", "priority", "weight", "port", "target")
class SSHFPRecordSerializer(SshFpSerializer):
"""Serialize `machines.models.SshFp` objects with the data needed to
generate a SSHFP DNS record.
"""
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")
class ARecordSerializer(serializers.ModelSerializer):
"""Serialize `machines.models.Interface` objects with the data needed to
generate a A DNS record.
"""
hostname = serializers.CharField(source="domain.name", read_only=True)
ipv4 = serializers.CharField(source="ipv4.ipv4", read_only=True)
ttl = serializers.IntegerField(source="domain.ttl", read_only=True)
class Meta:
model = machines.Interface
fields = ("hostname", "ipv4", "ttl")
class AAAARecordSerializer(serializers.ModelSerializer):
"""Serialize `machines.models.Interface` objects with the data needed to
generate a AAAA DNS record.
"""
hostname = serializers.CharField(source="domain.name", read_only=True)
ipv6 = Ipv6ListSerializer(many=True, read_only=True)
ttl = serializers.IntegerField(source="domain.ttl", read_only=True)
class Meta:
model = machines.Interface
fields = ("hostname", "ipv6", "ttl")
class CNAMERecordSerializer(serializers.ModelSerializer):
"""Serialize `machines.models.Domain` objects with the data needed to
generate a CNAME DNS record.
"""
alias = serializers.CharField(source="cname", read_only=True)
hostname = serializers.CharField(source="name", read_only=True)
class Meta:
model = machines.Domain
fields = ("alias", "hostname", "ttl")
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", "ttl")
class DNSZonesSerializer(serializers.ModelSerializer):
"""Serialize the data about DNS Zones.
"""
soa = SOARecordSerializer()
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"
)
class Meta:
model = machines.Extension
fields = (
"name",
"soa",
"ns_records",
"originv4",
"originv6",
"mx_records",
"txt_records",
"srv_records",
"a_records",
"aaaa_records",
"cname_records",
"dname_records",
"sshfp_records",
)
class DNSReverseZonesSerializer(serializers.ModelSerializer):
"""Serialize the data about DNS Zones.
"""
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"
)
class Meta:
model = machines.IpType
fields = (
"name",
"extension",
"soa",
"ns_records",
"mx_records",
"txt_records",
"ptr_records",
"ptr_v6_records",
"cidrs",
"prefix_v6",
"prefix_v6_length",
)

66
machines/api/urls.py Normal file
View file

@ -0,0 +1,66 @@
# -*- mode: python; coding: utf-8 -*-
# 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.
#
# Copyright © 2018 Maël Kervella
#
# 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.
from . import views
urls_viewset = [
(r"machines/machine", views.MachineViewSet, None),
(r"machines/machinetype", views.MachineTypeViewSet, None),
(r"machines/iptype", views.IpTypeViewSet, None),
(r"machines/vlan", views.VlanViewSet, None),
(r"machines/nas", views.NasViewSet, None),
(r"machines/soa", views.SOAViewSet, None),
(r"machines/extension", views.ExtensionViewSet, None),
(r"machines/mx", views.MxViewSet, None),
(r"machines/ns", views.NsViewSet, None),
(r"machines/txt", views.TxtViewSet, None),
(r"machines/dname", views.DNameViewSet, None),
(r"machines/srv", views.SrvViewSet, None),
(r"machines/sshfp", views.SshFpViewSet, None),
(r"machines/interface", views.InterfaceViewSet, None),
(r"machines/ipv6list", views.Ipv6ListViewSet, None),
(r"machines/domain", views.DomainViewSet, None),
(r"machines/iplist", views.IpListViewSet, None),
(r"machines/service", views.ServiceViewSet, None),
(r"machines/servicelink", views.ServiceLinkViewSet, "servicelink"),
(r"machines/ouvertureportlist", views.OuverturePortListViewSet, None),
(r"machines/ouvertureport", views.OuverturePortViewSet, None),
(r"machines/role", views.RoleViewSet, None),
(r"machines/services-regen", views.ServiceRegenViewSet, "serviceregen"),
# Deprecated
(r"services/regen", views.ServiceRegenViewSet, "serviceregen")
]
urls_view = [
(r"machines/hostmacip", views.HostMacIpView),
(r"machines/firewall-subnet-ports", views.SubnetPortsOpenView),
(r"machines/firewall-interface-ports", views.InterfacePortsOpenView),
(r"machines/dns-zones", views.DNSZonesView),
(r"machines/dns-reverse-zones", views.DNSReverseZonesView),
# Deprecated
(r"dhcp/hostmacip", views.HostMacIpView),
(r"firewall/subnet-ports", views.SubnetPortsOpenView),
(r"firewall/interface-ports", views.InterfacePortsOpenView),
(r"dns/zones", views.DNSZonesView),
(r"dns/reverse-zones", views.DNSReverseZonesView),
]

267
machines/api/views.py Normal file
View file

@ -0,0 +1,267 @@
# -*- mode: python; coding: utf-8 -*-
# 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.
#
# Copyright © 2018 Maël Kervella
#
# 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.
from rest_framework import viewsets, generics
from . import serializers
import machines.models as machines
from re2o.utils import all_active_interfaces
class MachineViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.Machine` objects.
"""
queryset = machines.Machine.objects.all()
serializer_class = serializers.MachineSerializer
class MachineTypeViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.MachineType` objects.
"""
queryset = machines.MachineType.objects.all()
serializer_class = serializers.MachineTypeSerializer
class IpTypeViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.IpType` objects.
"""
queryset = machines.IpType.objects.all()
serializer_class = serializers.IpTypeSerializer
class VlanViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.Vlan` objects.
"""
queryset = machines.Vlan.objects.all()
serializer_class = serializers.VlanSerializer
class NasViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.Nas` objects.
"""
queryset = machines.Nas.objects.all()
serializer_class = serializers.NasSerializer
class SOAViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.SOA` objects.
"""
queryset = machines.SOA.objects.all()
serializer_class = serializers.SOASerializer
class ExtensionViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.Extension` objects.
"""
queryset = machines.Extension.objects.all()
serializer_class = serializers.ExtensionSerializer
class MxViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.Mx` objects.
"""
queryset = machines.Mx.objects.all()
serializer_class = serializers.MxSerializer
class NsViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.Ns` objects.
"""
queryset = machines.Ns.objects.all()
serializer_class = serializers.NsSerializer
class TxtViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.Txt` objects.
"""
queryset = machines.Txt.objects.all()
serializer_class = serializers.TxtSerializer
class DNameViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.DName` objects.
"""
queryset = machines.DName.objects.all()
serializer_class = serializers.DNameSerializer
class SrvViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.Srv` objects.
"""
queryset = machines.Srv.objects.all()
serializer_class = serializers.SrvSerializer
class SshFpViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.SshFp` objects.
"""
queryset = machines.SshFp.objects.all()
serializer_class = serializers.SshFpSerializer
class InterfaceViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.Interface` objects.
"""
queryset = machines.Interface.objects.all()
serializer_class = serializers.InterfaceSerializer
class Ipv6ListViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.Ipv6List` objects.
"""
queryset = machines.Ipv6List.objects.all()
serializer_class = serializers.Ipv6ListSerializer
class DomainViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.Domain` objects.
"""
queryset = machines.Domain.objects.all()
serializer_class = serializers.DomainSerializer
class IpListViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.IpList` objects.
"""
queryset = machines.IpList.objects.all()
serializer_class = serializers.IpListSerializer
class ServiceViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.Service` objects.
"""
queryset = machines.Service.objects.all()
serializer_class = serializers.ServiceSerializer
class ServiceLinkViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.Service_link` objects.
"""
queryset = machines.Service_link.objects.all()
serializer_class = serializers.ServiceLinkSerializer
class OuverturePortListViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.OuverturePortList`
objects.
"""
queryset = machines.OuverturePortList.objects.all()
serializer_class = serializers.OuverturePortListSerializer
class OuverturePortViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.OuverturePort` objects.
"""
queryset = machines.OuverturePort.objects.all()
serializer_class = serializers.OuverturePortSerializer
class RoleViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.Machine` objects.
"""
queryset = machines.Role.objects.all()
serializer_class = serializers.RoleSerializer
class ServiceRegenViewSet(viewsets.ModelViewSet):
"""Exposes list and details of the services to regen
"""
serializer_class = serializers.ServiceRegenSerializer
def get_queryset(self):
queryset = machines.Service_link.objects.select_related(
"server__domain"
).select_related("service")
if "hostname" in self.request.GET:
hostname = self.request.GET["hostname"]
queryset = queryset.filter(server__domain__name__iexact=hostname)
return queryset
class HostMacIpView(generics.ListAPIView):
"""Exposes the associations between hostname, mac address and IPv4 in
order to build the DHCP lease files.
"""
serializer_class = serializers.HostMacIpSerializer
def get_queryset(self):
return all_active_interfaces()
class SubnetPortsOpenView(generics.ListAPIView):
queryset = machines.IpType.objects.all()
serializer_class = serializers.SubnetPortsOpenSerializer
class InterfacePortsOpenView(generics.ListAPIView):
queryset = machines.Interface.objects.filter(port_lists__isnull=False).distinct()
serializer_class = serializers.InterfacePortsOpenSerializer
class DNSZonesView(generics.ListAPIView):
"""Exposes the detailed information about each extension (hostnames,
IPs, DNS records, etc.) in order to build the DNS zone files.
"""
queryset = (
machines.Extension.objects.prefetch_related("soa")
.prefetch_related("ns_set")
.prefetch_related("ns_set__ns")
.prefetch_related("origin")
.prefetch_related("mx_set")
.prefetch_related("mx_set__name")
.prefetch_related("txt_set")
.prefetch_related("srv_set")
.prefetch_related("srv_set__target")
.all()
)
serializer_class = serializers.DNSZonesSerializer
class DNSReverseZonesView(generics.ListAPIView):
"""Exposes the detailed information about each extension (hostnames,
IPs, DNS records, etc.) in order to build the DNS zone files.
"""
queryset = machines.IpType.objects.all()
serializer_class = serializers.DNSReverseZonesSerializer

View file

View file

@ -0,0 +1,174 @@
# -*- mode: python; coding: utf-8 -*-
# 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.
#
# Copyright © 2018 Maël Kervella
#
# 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.
from rest_framework import serializers
import preferences.models as preferences
from api.serializers import NamespacedHRField, NamespacedHIField, NamespacedHMSerializer
class OptionalUserSerializer(NamespacedHMSerializer):
"""Serialize `preferences.models.OptionalUser` objects.
"""
tel_mandatory = serializers.BooleanField(source="is_tel_mandatory")
shell_default = serializers.StringRelatedField()
class Meta:
model = preferences.OptionalUser
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",
)
class OptionalMachineSerializer(NamespacedHMSerializer):
"""Serialize `preferences.models.OptionalMachine` objects.
"""
class Meta:
model = preferences.OptionalMachine
fields = (
"password_machine",
"max_lambdauser_interfaces",
"max_lambdauser_aliases",
"ipv6_mode",
"create_machine",
"ipv6",
"default_dns_ttl"
)
class OptionalTopologieSerializer(NamespacedHMSerializer):
"""Serialize `preferences.models.OptionalTopologie` objects.
"""
switchs_management_interface_ip = serializers.CharField()
class Meta:
model = preferences.OptionalTopologie
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",
)
class RadiusOptionSerializer(NamespacedHMSerializer):
"""Serialize `preferences.models.RadiusOption` objects
"""
class Meta:
model = preferences.RadiusOption
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",
)
class GeneralOptionSerializer(NamespacedHMSerializer):
"""Serialize `preferences.models.GeneralOption` objects.
"""
class Meta:
model = preferences.GeneralOption
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",
)
class HomeServiceSerializer(NamespacedHMSerializer):
"""Serialize `preferences.models.Service` objects.
"""
class Meta:
model = preferences.Service
fields = ("name", "url", "description", "image", "api_url")
extra_kwargs = {"api_url": {"view_name": "homeservice-detail"}}
class AssoOptionSerializer(NamespacedHMSerializer):
"""Serialize `preferences.models.AssoOption` objects.
"""
class Meta:
model = preferences.AssoOption
fields = (
"name",
"siret",
"adresse1",
"adresse2",
"contact",
"telephone",
"pseudo",
"utilisateur_asso",
"description",
)
class HomeOptionSerializer(NamespacedHMSerializer):
"""Serialize `preferences.models.HomeOption` objects.
"""
class Meta:
model = preferences.HomeOption
fields = ("facebook_url", "twitter_url", "twitter_account_name")
class MailMessageOptionSerializer(NamespacedHMSerializer):
"""Serialize `preferences.models.MailMessageOption` objects.
"""
class Meta:
model = preferences.MailMessageOption
fields = ("welcome_mail_fr", "welcome_mail_en")

37
preferences/api/urls.py Normal file
View file

@ -0,0 +1,37 @@
# -*- mode: python; coding: utf-8 -*-
# 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.
#
# Copyright © 2018 Maël Kervella
#
# 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.
from . import views
urls_viewset = [
(r"preferences/service", views.HomeServiceViewSet, "homeservice")
]
urls_view = [
(r"preferences/optionaluser", views.OptionalUserView),
(r"preferences/optionalmachine", views.OptionalMachineView),
(r"preferences/optionaltopologie", views.OptionalTopologieView),
(r"preferences/radiusoption", views.RadiusOptionView),
(r"preferences/generaloption", views.GeneralOptionView),
(r"preferences/assooption", views.AssoOptionView),
(r"preferences/homeoption", views.HomeOptionView),
(r"preferences/mailmessageoption", views.MailMessageOptionView)
]

130
preferences/api/views.py Normal file
View file

@ -0,0 +1,130 @@
# -*- mode: python; coding: utf-8 -*-
# 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.
#
# Copyright © 2018 Maël Kervella
#
# 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.
from rest_framework import viewsets, generics
from . import serializers
import preferences.models as preferences
from api.permissions import ACLPermission
class OptionalUserView(generics.RetrieveAPIView):
"""Exposes details of `preferences.models.` settings.
"""
permission_classes = (ACLPermission,)
perms_map = {"GET": [preferences.OptionalUser.can_view_all]}
serializer_class = serializers.OptionalUserSerializer
def get_object(self):
return preferences.OptionalUser.objects.first()
class OptionalMachineView(generics.RetrieveAPIView):
"""Exposes details of `preferences.models.OptionalMachine` settings.
"""
permission_classes = (ACLPermission,)
perms_map = {"GET": [preferences.OptionalMachine.can_view_all]}
serializer_class = serializers.OptionalMachineSerializer
def get_object(self):
return preferences.OptionalMachine.objects.first()
class OptionalTopologieView(generics.RetrieveAPIView):
"""Exposes details of `preferences.models.OptionalTopologie` settings.
"""
permission_classes = (ACLPermission,)
perms_map = {"GET": [preferences.OptionalTopologie.can_view_all]}
serializer_class = serializers.OptionalTopologieSerializer
def get_object(self):
return preferences.OptionalTopologie.objects.first()
class RadiusOptionView(generics.RetrieveAPIView):
"""Exposes details of `preferences.models.OptionalTopologie` settings.
"""
permission_classes = (ACLPermission,)
perms_map = {"GET": [preferences.RadiusOption.can_view_all]}
serializer_class = serializers.RadiusOptionSerializer
def get_object(self):
return preferences.RadiusOption.objects.first()
class GeneralOptionView(generics.RetrieveAPIView):
"""Exposes details of `preferences.models.GeneralOption` settings.
"""
permission_classes = (ACLPermission,)
perms_map = {"GET": [preferences.GeneralOption.can_view_all]}
serializer_class = serializers.GeneralOptionSerializer
def get_object(self):
return preferences.GeneralOption.objects.first()
class HomeServiceViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `preferences.models.Service` objects.
"""
queryset = preferences.Service.objects.all()
serializer_class = serializers.HomeServiceSerializer
class AssoOptionView(generics.RetrieveAPIView):
"""Exposes details of `preferences.models.AssoOption` settings.
"""
permission_classes = (ACLPermission,)
perms_map = {"GET": [preferences.AssoOption.can_view_all]}
serializer_class = serializers.AssoOptionSerializer
def get_object(self):
return preferences.AssoOption.objects.first()
class HomeOptionView(generics.RetrieveAPIView):
"""Exposes details of `preferences.models.HomeOption` settings.
"""
permission_classes = (ACLPermission,)
perms_map = {"GET": [preferences.HomeOption.can_view_all]}
serializer_class = serializers.HomeOptionSerializer
def get_object(self):
return preferences.HomeOption.objects.first()
class MailMessageOptionView(generics.RetrieveAPIView):
"""Exposes details of `preferences.models.MailMessageOption` settings.
"""
permission_classes = (ACLPermission,)
perms_map = {"GET": [preferences.MailMessageOption.can_view_all]}
serializer_class = serializers.MailMessageOptionSerializer
def get_object(self):
return preferences.MailMessageOption.objects.first()

View file

View file

@ -0,0 +1,323 @@
# -*- mode: python; coding: utf-8 -*-
# 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.
#
# Copyright © 2018 Maël Kervella
#
# 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.
from rest_framework import serializers
import topologie.models as topologie
import machines.models as machines
from machines.api.serializers import VlanSerializer, Ipv6ListSerializer
from api.serializers import NamespacedHRField, NamespacedHIField, NamespacedHMSerializer
class StackSerializer(NamespacedHMSerializer):
"""Serialize `topologie.models.Stack` objects
"""
class Meta:
model = topologie.Stack
fields = (
"name",
"stack_id",
"details",
"member_id_min",
"member_id_max",
"api_url",
)
class AccessPointSerializer(NamespacedHMSerializer):
"""Serialize `topologie.models.AccessPoint` objects
"""
class Meta:
model = topologie.AccessPoint
fields = ("user", "name", "active", "location", "api_url")
class SwitchSerializer(NamespacedHMSerializer):
"""Serialize `topologie.models.Switch` objects
"""
port_amount = serializers.IntegerField(source="number")
class Meta:
model = topologie.Switch
fields = (
"user",
"name",
"active",
"port_amount",
"stack",
"stack_member_id",
"model",
"switchbay",
"api_url",
)
class ServerSerializer(NamespacedHMSerializer):
"""Serialize `topologie.models.Server` objects
"""
class Meta:
model = topologie.Server
fields = ("user", "name", "active", "api_url")
class ModelSwitchSerializer(NamespacedHMSerializer):
"""Serialize `topologie.models.ModelSwitch` objects
"""
class Meta:
model = topologie.ModelSwitch
fields = ("reference", "constructor", "api_url")
class ConstructorSwitchSerializer(NamespacedHMSerializer):
"""Serialize `topologie.models.ConstructorSwitch` objects
"""
class Meta:
model = topologie.ConstructorSwitch
fields = ("name", "api_url")
class SwitchBaySerializer(NamespacedHMSerializer):
"""Serialize `topologie.models.SwitchBay` objects
"""
class Meta:
model = topologie.SwitchBay
fields = ("name", "building", "info", "api_url")
class BuildingSerializer(NamespacedHMSerializer):
"""Serialize `topologie.models.Building` objects
"""
class Meta:
model = topologie.Building
fields = ("name", "api_url")
class SwitchPortSerializer(NamespacedHMSerializer):
"""Serialize `topologie.models.Port` objects
"""
get_port_profile = NamespacedHIField(view_name="portprofile-detail", read_only=True)
class Meta:
model = topologie.Port
fields = (
"switch",
"port",
"room",
"machine_interface",
"related",
"custom_profile",
"state",
"get_port_profile",
"details",
"api_url",
)
extra_kwargs = {
"related": {"view_name": "switchport-detail"},
"api_url": {"view_name": "switchport-detail"},
}
class PortProfileSerializer(NamespacedHMSerializer):
"""Serialize `topologie.models.Room` objects
"""
class Meta:
model = topologie.PortProfile
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",
)
class RoomSerializer(NamespacedHMSerializer):
"""Serialize `topologie.models.Room` objects
"""
class Meta:
model = topologie.Room
fields = ("name", "details", "api_url")
class PortProfileSerializer(NamespacedHMSerializer):
vlan_untagged = VlanSerializer(read_only=True)
class Meta:
model = topologie.PortProfile
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",
)
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="machine_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
fields = ("role_type", "servers", "specific_role")
class VlanPortSerializer(NamespacedHMSerializer):
class Meta:
model = machines.Vlan
fields = ("vlan_id", "name")
class ProfilSerializer(NamespacedHMSerializer):
vlan_untagged = VlanSerializer(read_only=True)
vlan_tagged = VlanPortSerializer(read_only=True, many=True)
class Meta:
model = topologie.PortProfile
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",
)
class ModelSwitchSerializer(NamespacedHMSerializer):
constructor = serializers.CharField(read_only=True)
class Meta:
model = topologie.ModelSwitch
fields = ("reference", "firmware", "constructor")
class SwitchBaySerializer(NamespacedHMSerializer):
class Meta:
model = topologie.SwitchBay
fields = ("name",)
class PortsSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.Ipv6List` objects.
"""
get_port_profile = ProfilSerializer(read_only=True)
class Meta:
model = topologie.Port
fields = ("state", "port", "pretty_name", "get_port_profile")
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)
class Meta:
model = topologie.Switch
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",
)

46
topologie/api/urls.py Normal file
View file

@ -0,0 +1,46 @@
# -*- mode: python; coding: utf-8 -*-
# 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.
#
# Copyright © 2018 Maël Kervella
#
# 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.
from . import views
urls_viewset = [
(r"topologie/stack", views.StackViewSet, None),
(r"topologie/acesspoint", views.AccessPointViewSet, None),
(r"topologie/switch", views.SwitchViewSet, None),
(r"topologie/server", views.ServerViewSet, None),
(r"topologie/modelswitch", views.ModelSwitchViewSet, None),
(r"topologie/constructorswitch", views.ConstructorSwitchViewSet, None),
(r"topologie/switchbay", views.SwitchBayViewSet, None),
(r"topologie/building", views.BuildingViewSet, None),
(r"topologie/switchport", views.SwitchPortViewSet, "switchport"),
(r"topologie/portprofile", views.PortProfileViewSet, "portprofile"),
(r"topologie/room", views.RoomViewSet, None)
]
urls_view = [
# (r"topologie/portprofile", views.PortProfileViewSet)
(r"topologie/switchs-ports-config", views.SwitchPortView),
(r"topologie/switchs-role", views.RoleView),
# Deprecated
(r"switchs/ports-config", views.SwitchPortView),
(r"switchs/role", views.RoleView),
]

149
topologie/api/views.py Normal file
View file

@ -0,0 +1,149 @@
# -*- mode: python; coding: utf-8 -*-
# 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.
#
# Copyright © 2018 Maël Kervella
#
# 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.
from rest_framework import viewsets, generics
from . import serializers
import topologie.models as topologie
import machines.models as machines
class StackViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `topologie.models.Stack` objects.
"""
queryset = topologie.Stack.objects.all()
serializer_class = serializers.StackSerializer
class AccessPointViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `topologie.models.AccessPoint` objects.
"""
queryset = topologie.AccessPoint.objects.all()
serializer_class = serializers.AccessPointSerializer
class SwitchViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `topologie.models.Switch` objects.
"""
queryset = topologie.Switch.objects.all()
serializer_class = serializers.SwitchSerializer
class ServerViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `topologie.models.Server` objects.
"""
queryset = topologie.Server.objects.all()
serializer_class = serializers.ServerSerializer
class ModelSwitchViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `topologie.models.ModelSwitch` objects.
"""
queryset = topologie.ModelSwitch.objects.all()
serializer_class = serializers.ModelSwitchSerializer
class ConstructorSwitchViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `topologie.models.ConstructorSwitch`
objects.
"""
queryset = topologie.ConstructorSwitch.objects.all()
serializer_class = serializers.ConstructorSwitchSerializer
class SwitchBayViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `topologie.models.SwitchBay` objects.
"""
queryset = topologie.SwitchBay.objects.all()
serializer_class = serializers.SwitchBaySerializer
class BuildingViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `topologie.models.Building` objects.
"""
queryset = topologie.Building.objects.all()
serializer_class = serializers.BuildingSerializer
class SwitchPortViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `topologie.models.Port` objects.
"""
queryset = topologie.Port.objects.all()
serializer_class = serializers.SwitchPortSerializer
class PortProfileViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `topologie.models.PortProfile` objects.
"""
queryset = topologie.PortProfile.objects.all()
serializer_class = serializers.PortProfileSerializer
class RoomViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `topologie.models.Room` objects.
"""
queryset = topologie.Room.objects.all()
serializer_class = serializers.RoomSerializer
class PortProfileViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `topologie.models.PortProfile` objects.
"""
queryset = topologie.PortProfile.objects.all()
serializer_class = serializers.PortProfileSerializer
class SwitchPortView(generics.ListAPIView):
"""Output each port of a switch, to be serialized with
additionnal informations (profiles etc)
"""
queryset = (
topologie.Switch.objects.all()
.select_related("switchbay")
.select_related("model__constructor")
.prefetch_related("ports__custom_profile__vlan_tagged")
.prefetch_related("ports__custom_profile__vlan_untagged")
.prefetch_related("ports__machine_interface__domain__extension")
.prefetch_related("ports__room")
)
serializer_class = serializers.SwitchPortSerializer
class RoleView(generics.ListAPIView):
"""Output of roles for each server
"""
queryset = machines.Role.objects.all().prefetch_related("servers")
serializer_class = serializers.RoleSerializer

0
users/api/__init__.py Normal file
View file

244
users/api/serializers.py Normal file
View file

@ -0,0 +1,244 @@
# -*- mode: python; coding: utf-8 -*-
# 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.
#
# Copyright © 2018 Maël Kervella
#
# 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.
from rest_framework import serializers
import users.models as users
from api.serializers import NamespacedHRField, NamespacedHIField, NamespacedHMSerializer
class UserSerializer(NamespacedHMSerializer):
"""Serialize `users.models.User` objects.
"""
access = serializers.BooleanField(source="has_access")
uid = serializers.IntegerField(source="uid_number")
class Meta:
model = users.User
fields = (
"surname",
"pseudo",
"email",
"local_email_redirect",
"local_email_enabled",
"school",
"shell",
"comment",
"state",
"registered",
"telephone",
"solde",
"access",
"end_access",
"uid",
"class_type",
"api_url",
)
extra_kwargs = {"shell": {"view_name": "shell-detail"}}
class ClubSerializer(NamespacedHMSerializer):
"""Serialize `users.models.Club` objects.
"""
name = serializers.CharField(source="surname")
access = serializers.BooleanField(source="has_access")
uid = serializers.IntegerField(source="uid_number")
class Meta:
model = users.Club
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"}}
class AdherentSerializer(NamespacedHMSerializer):
"""Serialize `users.models.Adherent` objects.
"""
access = serializers.BooleanField(source="has_access")
uid = serializers.IntegerField(source="uid_number")
class Meta:
model = users.Adherent
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"}}
class BasicUserSerializer(NamespacedHMSerializer):
"""Serialize 'users.models.User' minimal infos"""
uid = serializers.IntegerField(source="uid_number")
gid = serializers.IntegerField(source="gid_number")
class Meta:
model = users.User
fields = ("pseudo", "uid", "gid")
class ServiceUserSerializer(NamespacedHMSerializer):
"""Serialize `users.models.ServiceUser` objects.
"""
class Meta:
model = users.ServiceUser
fields = ("pseudo", "access_group", "comment", "api_url")
class SchoolSerializer(NamespacedHMSerializer):
"""Serialize `users.models.School` objects.
"""
class Meta:
model = users.School
fields = ("name", "api_url")
class ListRightSerializer(NamespacedHMSerializer):
"""Serialize `users.models.ListRight` objects.
"""
class Meta:
model = users.ListRight
fields = ("unix_name", "gid", "critical", "details", "api_url")
class ShellSerializer(NamespacedHMSerializer):
"""Serialize `users.models.ListShell` objects.
"""
class Meta:
model = users.ListShell
fields = ("shell", "api_url")
extra_kwargs = {"api_url": {"view_name": "shell-detail"}}
class BanSerializer(NamespacedHMSerializer):
"""Serialize `users.models.Ban` objects.
"""
active = serializers.BooleanField(source="is_active")
class Meta:
model = users.Ban
fields = (
"user",
"raison",
"date_start",
"date_end",
"state",
"active",
"api_url",
)
class WhitelistSerializer(NamespacedHMSerializer):
"""Serialize `users.models.Whitelist` objects.
"""
active = serializers.BooleanField(source="is_active")
class Meta:
model = users.Whitelist
fields = ("user", "raison", "date_start", "date_end", "active", "api_url")
class EMailAddressSerializer(NamespacedHMSerializer):
"""Serialize `users.models.EMailAddress` objects.
"""
user = serializers.CharField(source="user.pseudo", read_only=True)
class Meta:
model = users.EMailAddress
fields = ("user", "local_part", "complete_email_address", "api_url")
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",
)
class MailingMemberSerializer(UserSerializer):
"""Serialize the data about a mailing member.
"""
class Meta(UserSerializer.Meta):
fields = ("name", "pseudo", "get_mail")
class MailingSerializer(ClubSerializer):
"""Serialize the data about a mailing.
"""
members = MailingMemberSerializer(many=True)
admins = MailingMemberSerializer(source="administrators", many=True)
class Meta(ClubSerializer.Meta):
fields = ("name", "members", "admins")

49
users/api/urls.py Normal file
View file

@ -0,0 +1,49 @@
# -*- mode: python; coding: utf-8 -*-
# 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.
#
# Copyright © 2018 Maël Kervella
#
# 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.
from . import views
urls_viewset = [
(r"users/user", views.UserViewSet, "user"),
(r"users/homecreation", views.HomeCreationViewSet, "homecreation"),
(r"users/normaluser", views.NormalUserViewSet, "normaluser"),
(r"users/criticaluser", views.CriticalUserViewSet, "criticaluser"),
(r"users/club", views.ClubViewSet, None),
(r"users/adherent", views.AdherentViewSet, None),
(r"users/serviceuser", views.ServiceUserViewSet, None),
(r"users/school", views.SchoolViewSet, None),
(r"users/listright", views.ListRightViewSet, None),
(r"users/shell", views.ShellViewSet, None),
(r"users/ban", views.BanViewSet, None),
(r"users/whitelist", views.WhitelistViewSet, None),
(r"users/emailaddress", views.EMailAddressViewSet, None)
]
urls_view = [
(r"users/localemail", views.LocalEmailUsersView),
(r"users/mailing-standard", views.StandardMailingView),
(r"users/mailing-club", views.ClubMailingView),
# Deprecated
(r"localemail/users", views.LocalEmailUsersView),
(r"mailing/standard", views.StandardMailingView),
(r"mailing/club", views.ClubMailingView),
]

191
users/api/views.py Normal file
View file

@ -0,0 +1,191 @@
# -*- mode: python; coding: utf-8 -*-
# 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.
#
# Copyright © 2018 Maël Kervella
#
# 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.
from rest_framework import viewsets, generics, views
from django.db.models import Q
from . import serializers
from api.pagination import PageSizedPagination
from api.permissions import ACLPermission
from re2o.utils import all_has_access
import users.models as users
import preferences.models as preferences
class UserViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `users.models.Users` objects.
"""
queryset = users.User.objects.all()
serializer_class = serializers.UserSerializer
class HomeCreationViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes infos of `users.models.Users` objects to create homes.
"""
queryset = users.User.objects.exclude(
Q(state=users.User.STATE_DISABLED)
| Q(state=users.User.STATE_NOT_YET_ACTIVE)
| Q(state=users.User.STATE_FULL_ARCHIVE)
)
serializer_class = serializers.BasicUserSerializer
class NormalUserViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes infos of `users.models.Users`without specific rights objects."""
queryset = users.User.objects.exclude(groups__listright__critical=True).distinct()
serializer_class = serializers.BasicUserSerializer
class CriticalUserViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes infos of `users.models.Users`without specific rights objects."""
queryset = users.User.objects.filter(groups__listright__critical=True).distinct()
serializer_class = serializers.BasicUserSerializer
class ClubViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `users.models.Club` objects.
"""
queryset = users.Club.objects.all()
serializer_class = serializers.ClubSerializer
class AdherentViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `users.models.Adherent` objects.
"""
queryset = users.Adherent.objects.all()
serializer_class = serializers.AdherentSerializer
class ServiceUserViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `users.models.ServiceUser` objects.
"""
queryset = users.ServiceUser.objects.all()
serializer_class = serializers.ServiceUserSerializer
class SchoolViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `users.models.School` objects.
"""
queryset = users.School.objects.all()
serializer_class = serializers.SchoolSerializer
class ListRightViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `users.models.ListRight` objects.
"""
queryset = users.ListRight.objects.all()
serializer_class = serializers.ListRightSerializer
class ShellViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `users.models.ListShell` objects.
"""
queryset = users.ListShell.objects.all()
serializer_class = serializers.ShellSerializer
class BanViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `users.models.Ban` objects.
"""
queryset = users.Ban.objects.all()
serializer_class = serializers.BanSerializer
class WhitelistViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `users.models.Whitelist` objects.
"""
queryset = users.Whitelist.objects.all()
serializer_class = serializers.WhitelistSerializer
class EMailAddressViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `users.models.EMailAddress` objects.
"""
serializer_class = serializers.EMailAddressSerializer
queryset = users.EMailAddress.objects.none()
def get_queryset(self):
if preferences.OptionalUser.get_cached_value("local_email_accounts_enabled"):
return users.EMailAddress.objects.filter(user__local_email_enabled=True)
else:
return users.EMailAddress.objects.none()
class LocalEmailUsersView(generics.ListAPIView):
"""Exposes all the aliases of the users that activated the internal address
"""
serializer_class = serializers.LocalEmailUsersSerializer
def get_queryset(self):
if preferences.OptionalUser.get_cached_value("local_email_accounts_enabled"):
return users.User.objects.filter(local_email_enabled=True)
else:
return users.User.objects.none()
class StandardMailingView(views.APIView):
"""Exposes list and details of standard mailings (name and members) in
order to building the corresponding mailing lists.
"""
pagination_class = PageSizedPagination
permission_classes = (ACLPermission,)
perms_map = {"GET": [users.User.can_view_all]}
def get(self, request, format=None):
adherents_data = serializers.MailingMemberSerializer(
all_has_access(), many=True
).data
data = [{"name": "adherents", "members": adherents_data}]
groups = Group.objects.all()
for group in groups:
group_data = serializers.MailingMemberSerializer(
group.user_set.all(), many=True
).data
data.append({"name": group.name, "members": group_data})
paginator = self.pagination_class()
paginator.paginate_queryset(data, request)
return paginator.get_paginated_response(data)
class ClubMailingView(generics.ListAPIView):
"""Exposes list and details of club mailings (name, members and admins) in
order to build the corresponding mailing lists.
"""
queryset = users.Club.objects.all()
serializer_class = serializers.MailingSerializer