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

Merge branch 'cleanup_api' into 'dev'

Clean up of API code

See merge request federez/re2o!309
This commit is contained in:
klafyvel 2018-10-06 11:10:57 +02:00
commit 69d1515aab
9 changed files with 139 additions and 73 deletions

View file

@ -26,8 +26,8 @@ done.
""" """
from django.conf import settings from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import Permission from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentType
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _

View file

@ -26,12 +26,14 @@ import datetime
from django.conf import settings from django.conf import settings
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from rest_framework.authentication import TokenAuthentication
from rest_framework import exceptions from rest_framework import exceptions
from rest_framework.authentication import TokenAuthentication
class ExpiringTokenAuthentication(TokenAuthentication): class ExpiringTokenAuthentication(TokenAuthentication):
"""Authenticate a user if the provided token is valid and not expired. """Authenticate a user if the provided token is valid and not expired.
""" """
def authenticate_credentials(self, key): def authenticate_credentials(self, key):
"""See base class. Add the verification the token is not expired. """See base class. Add the verification the token is not expired.
""" """
@ -46,4 +48,4 @@ class ExpiringTokenAuthentication(TokenAuthentication):
if token.created < utc_now - token_duration: if token.created < utc_now - token_duration:
raise exceptions.AuthenticationFailed(_('Token has expired')) raise exceptions.AuthenticationFailed(_('Token has expired'))
return (token.user, token) return token.user, token

View file

@ -24,8 +24,6 @@
from rest_framework import permissions, exceptions from rest_framework import permissions, exceptions
from re2o.acl import can_create, can_edit, can_delete, can_view_all
from . import acl from . import acl
@ -57,14 +55,14 @@ def _get_param_in_view(view, param_name):
AssertionError: None of the getter function or the attribute are AssertionError: None of the getter function or the attribute are
defined in the view. defined in the view.
""" """
assert hasattr(view, 'get_'+param_name) \ assert hasattr(view, 'get_' + param_name) \
or getattr(view, param_name, None) is not None, ( or getattr(view, param_name, None) is not None, (
'cannot apply {} on a view that does not set ' 'cannot apply {} on a view that does not set '
'`.{}` or have a `.get_{}()` method.' '`.{}` or have a `.get_{}()` method.'
).format(self.__class__.__name__, param_name, param_name) ).format(self.__class__.__name__, param_name, param_name)
if hasattr(view, 'get_'+param_name): if hasattr(view, 'get_' + param_name):
param = getattr(view, 'get_'+param_name)() param = getattr(view, 'get_' + param_name)()
assert param is not None, ( assert param is not None, (
'{}.get_{}() returned None' '{}.get_{}() returned None'
).format(view.__class__.__name__, param_name) ).format(view.__class__.__name__, param_name)
@ -80,7 +78,8 @@ class ACLPermission(permissions.BasePermission):
See the wiki for the syntax of this attribute. See the wiki for the syntax of this attribute.
""" """
def get_required_permissions(self, method, view): @staticmethod
def get_required_permissions(method, view):
"""Build the list of permissions required for the request to be """Build the list of permissions required for the request to be
accepted. accepted.
@ -209,7 +208,8 @@ class AutodetectACLPermission(permissions.BasePermission):
return [perm(obj) for perm in self.perms_obj_map[method]] return [perm(obj) for perm in self.perms_obj_map[method]]
def _queryset(self, view): @staticmethod
def _queryset(view):
return _get_param_in_view(view, 'queryset') return _get_param_in_view(view, 'queryset')
def has_permission(self, request, view): def has_permission(self, request, view):
@ -282,4 +282,3 @@ class AutodetectACLPermission(permissions.BasePermission):
return False return False
return True return True

View file

@ -24,12 +24,12 @@
from collections import OrderedDict from collections import OrderedDict
from django.conf.urls import url, include from django.conf.urls import url
from django.core.urlresolvers import NoReverseMatch from django.core.urlresolvers import NoReverseMatch
from rest_framework import views from rest_framework import views
from rest_framework.routers import DefaultRouter
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.reverse import reverse from rest_framework.reverse import reverse
from rest_framework.routers import DefaultRouter
from rest_framework.schemas import SchemaGenerator from rest_framework.schemas import SchemaGenerator
from rest_framework.settings import api_settings from rest_framework.settings import api_settings
@ -64,7 +64,8 @@ class AllViewsRouter(DefaultRouter):
name = self.get_default_name(pattern) name = self.get_default_name(pattern)
self.view_registry.append((pattern, view, name)) self.view_registry.append((pattern, view, name))
def get_default_name(self, pattern): @staticmethod
def get_default_name(pattern):
"""Returns the name to use for the route if none was specified. """Returns the name to use for the route if none was specified.
Args: Args:
@ -113,7 +114,8 @@ class AllViewsRouter(DefaultRouter):
_ignore_model_permissions = True _ignore_model_permissions = True
renderer_classes = view_renderers renderer_classes = view_renderers
def get(self, request, *args, **kwargs): @staticmethod
def get(request, *args, **kwargs):
if request.accepted_renderer.media_type in schema_media_types: if request.accepted_renderer.media_type in schema_media_types:
# Return a schema response. # Return a schema response.
schema = schema_generator.get_schema(request) schema = schema_generator.get_schema(request)

View file

@ -30,7 +30,6 @@ import preferences.models as preferences
import topologie.models as topologie import topologie.models as topologie
import users.models as users import users.models as users
# The namespace used for the API. It must match the namespace used in the # The namespace used for the API. It must match the namespace used in the
# urlpatterns to include the API URLs. # urlpatterns to include the API URLs.
API_NAMESPACE = 'api' API_NAMESPACE = 'api'
@ -40,6 +39,7 @@ class NamespacedHRField(serializers.HyperlinkedRelatedField):
"""A `rest_framework.serializers.HyperlinkedRelatedField` subclass to """A `rest_framework.serializers.HyperlinkedRelatedField` subclass to
automatically prefix view names with the API namespace. automatically prefix view names with the API namespace.
""" """
def __init__(self, view_name=None, **kwargs): def __init__(self, view_name=None, **kwargs):
if view_name is not None: if view_name is not None:
view_name = '%s:%s' % (API_NAMESPACE, view_name) view_name = '%s:%s' % (API_NAMESPACE, view_name)
@ -50,6 +50,7 @@ class NamespacedHIField(serializers.HyperlinkedIdentityField):
"""A `rest_framework.serializers.HyperlinkedIdentityField` subclass to """A `rest_framework.serializers.HyperlinkedIdentityField` subclass to
automatically prefix view names with teh API namespace. automatically prefix view names with teh API namespace.
""" """
def __init__(self, view_name=None, **kwargs): def __init__(self, view_name=None, **kwargs):
if view_name is not None: if view_name is not None:
view_name = '%s:%s' % (API_NAMESPACE, view_name) view_name = '%s:%s' % (API_NAMESPACE, view_name)
@ -70,6 +71,7 @@ class NamespacedHMSerializer(serializers.HyperlinkedModelSerializer):
class FactureSerializer(NamespacedHMSerializer): class FactureSerializer(NamespacedHMSerializer):
"""Serialize `cotisations.models.Facture` objects. """Serialize `cotisations.models.Facture` objects.
""" """
class Meta: class Meta:
model = cotisations.Facture model = cotisations.Facture
fields = ('user', 'paiement', 'banque', 'cheque', 'date', 'valid', fields = ('user', 'paiement', 'banque', 'cheque', 'date', 'valid',
@ -79,6 +81,7 @@ class FactureSerializer(NamespacedHMSerializer):
class VenteSerializer(NamespacedHMSerializer): class VenteSerializer(NamespacedHMSerializer):
"""Serialize `cotisations.models.Vente` objects. """Serialize `cotisations.models.Vente` objects.
""" """
class Meta: class Meta:
model = cotisations.Vente model = cotisations.Vente
fields = ('facture', 'number', 'name', 'prix', 'duration', fields = ('facture', 'number', 'name', 'prix', 'duration',
@ -88,6 +91,7 @@ class VenteSerializer(NamespacedHMSerializer):
class ArticleSerializer(NamespacedHMSerializer): class ArticleSerializer(NamespacedHMSerializer):
"""Serialize `cotisations.models.Article` objects. """Serialize `cotisations.models.Article` objects.
""" """
class Meta: class Meta:
model = cotisations.Article model = cotisations.Article
fields = ('name', 'prix', 'duration', 'type_user', fields = ('name', 'prix', 'duration', 'type_user',
@ -97,6 +101,7 @@ class ArticleSerializer(NamespacedHMSerializer):
class BanqueSerializer(NamespacedHMSerializer): class BanqueSerializer(NamespacedHMSerializer):
"""Serialize `cotisations.models.Banque` objects. """Serialize `cotisations.models.Banque` objects.
""" """
class Meta: class Meta:
model = cotisations.Banque model = cotisations.Banque
fields = ('name', 'api_url') fields = ('name', 'api_url')
@ -105,6 +110,7 @@ class BanqueSerializer(NamespacedHMSerializer):
class PaiementSerializer(NamespacedHMSerializer): class PaiementSerializer(NamespacedHMSerializer):
"""Serialize `cotisations.models.Paiement` objects. """Serialize `cotisations.models.Paiement` objects.
""" """
class Meta: class Meta:
model = cotisations.Paiement model = cotisations.Paiement
fields = ('moyen', 'type_paiement', 'api_url') fields = ('moyen', 'type_paiement', 'api_url')
@ -113,6 +119,7 @@ class PaiementSerializer(NamespacedHMSerializer):
class CotisationSerializer(NamespacedHMSerializer): class CotisationSerializer(NamespacedHMSerializer):
"""Serialize `cotisations.models.Cotisation` objects. """Serialize `cotisations.models.Cotisation` objects.
""" """
class Meta: class Meta:
model = cotisations.Cotisation model = cotisations.Cotisation
fields = ('vente', 'type_cotisation', 'date_start', 'date_end', fields = ('vente', 'type_cotisation', 'date_start', 'date_end',
@ -125,6 +132,7 @@ class CotisationSerializer(NamespacedHMSerializer):
class MachineSerializer(NamespacedHMSerializer): class MachineSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.Machine` objects. """Serialize `machines.models.Machine` objects.
""" """
class Meta: class Meta:
model = machines.Machine model = machines.Machine
fields = ('user', 'name', 'active', 'api_url') fields = ('user', 'name', 'active', 'api_url')
@ -133,6 +141,7 @@ class MachineSerializer(NamespacedHMSerializer):
class MachineTypeSerializer(NamespacedHMSerializer): class MachineTypeSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.MachineType` objects. """Serialize `machines.models.MachineType` objects.
""" """
class Meta: class Meta:
model = machines.MachineType model = machines.MachineType
fields = ('type', 'ip_type', 'api_url') fields = ('type', 'ip_type', 'api_url')
@ -141,6 +150,7 @@ class MachineTypeSerializer(NamespacedHMSerializer):
class IpTypeSerializer(NamespacedHMSerializer): class IpTypeSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.IpType` objects. """Serialize `machines.models.IpType` objects.
""" """
class Meta: class Meta:
model = machines.IpType model = machines.IpType
fields = ('type', 'extension', 'need_infra', 'domaine_ip_start', fields = ('type', 'extension', 'need_infra', 'domaine_ip_start',
@ -151,6 +161,7 @@ class IpTypeSerializer(NamespacedHMSerializer):
class VlanSerializer(NamespacedHMSerializer): class VlanSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.Vlan` objects. """Serialize `machines.models.Vlan` objects.
""" """
class Meta: class Meta:
model = machines.Vlan model = machines.Vlan
fields = ('vlan_id', 'name', 'comment', 'arp_protect', 'dhcp_snooping', fields = ('vlan_id', 'name', 'comment', 'arp_protect', 'dhcp_snooping',
@ -160,6 +171,7 @@ class VlanSerializer(NamespacedHMSerializer):
class NasSerializer(NamespacedHMSerializer): class NasSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.Nas` objects. """Serialize `machines.models.Nas` objects.
""" """
class Meta: class Meta:
model = machines.Nas model = machines.Nas
fields = ('name', 'nas_type', 'machine_type', 'port_access_mode', fields = ('name', 'nas_type', 'machine_type', 'port_access_mode',
@ -169,6 +181,7 @@ class NasSerializer(NamespacedHMSerializer):
class SOASerializer(NamespacedHMSerializer): class SOASerializer(NamespacedHMSerializer):
"""Serialize `machines.models.SOA` objects. """Serialize `machines.models.SOA` objects.
""" """
class Meta: class Meta:
model = machines.SOA model = machines.SOA
fields = ('name', 'mail', 'refresh', 'retry', 'expire', 'ttl', fields = ('name', 'mail', 'refresh', 'retry', 'expire', 'ttl',
@ -178,6 +191,7 @@ class SOASerializer(NamespacedHMSerializer):
class ExtensionSerializer(NamespacedHMSerializer): class ExtensionSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.Extension` objects. """Serialize `machines.models.Extension` objects.
""" """
class Meta: class Meta:
model = machines.Extension model = machines.Extension
fields = ('name', 'need_infra', 'origin', 'origin_v6', 'soa', fields = ('name', 'need_infra', 'origin', 'origin_v6', 'soa',
@ -187,6 +201,7 @@ class ExtensionSerializer(NamespacedHMSerializer):
class MxSerializer(NamespacedHMSerializer): class MxSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.Mx` objects. """Serialize `machines.models.Mx` objects.
""" """
class Meta: class Meta:
model = machines.Mx model = machines.Mx
fields = ('zone', 'priority', 'name', 'api_url') fields = ('zone', 'priority', 'name', 'api_url')
@ -195,13 +210,16 @@ class MxSerializer(NamespacedHMSerializer):
class DNameSerializer(NamespacedHMSerializer): class DNameSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.DName` objects. """Serialize `machines.models.DName` objects.
""" """
class Meta: class Meta:
model = machines.DName model = machines.DName
fields = ('zone', 'alias', 'api_url') fields = ('zone', 'alias', 'api_url')
class NsSerializer(NamespacedHMSerializer): class NsSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.Ns` objects. """Serialize `machines.models.Ns` objects.
""" """
class Meta: class Meta:
model = machines.Ns model = machines.Ns
fields = ('zone', 'ns', 'api_url') fields = ('zone', 'ns', 'api_url')
@ -210,6 +228,7 @@ class NsSerializer(NamespacedHMSerializer):
class TxtSerializer(NamespacedHMSerializer): class TxtSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.Txt` objects. """Serialize `machines.models.Txt` objects.
""" """
class Meta: class Meta:
model = machines.Txt model = machines.Txt
fields = ('zone', 'field1', 'field2', 'api_url') fields = ('zone', 'field1', 'field2', 'api_url')
@ -218,14 +237,17 @@ class TxtSerializer(NamespacedHMSerializer):
class SrvSerializer(NamespacedHMSerializer): class SrvSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.Srv` objects. """Serialize `machines.models.Srv` objects.
""" """
class Meta: class Meta:
model = machines.Srv model = machines.Srv
fields = ('service', 'protocole', 'extension', 'ttl', 'priority', fields = ('service', 'protocole', 'extension', 'ttl', 'priority',
'weight', 'port', 'target', 'api_url') 'weight', 'port', 'target', 'api_url')
class SshFpSerializer(NamespacedHMSerializer): class SshFpSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.SSHFP` objects. """Serialize `machines.models.SSHFP` objects.
""" """
class Meta: class Meta:
model = machines.SshFp model = machines.SshFp
field = ('machine', 'pub_key_entry', 'algo', 'comment', 'api_url') field = ('machine', 'pub_key_entry', 'algo', 'comment', 'api_url')
@ -246,6 +268,7 @@ class InterfaceSerializer(NamespacedHMSerializer):
class Ipv6ListSerializer(NamespacedHMSerializer): class Ipv6ListSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.Ipv6List` objects. """Serialize `machines.models.Ipv6List` objects.
""" """
class Meta: class Meta:
model = machines.Ipv6List model = machines.Ipv6List
fields = ('ipv6', 'interface', 'slaac_ip', 'api_url') fields = ('ipv6', 'interface', 'slaac_ip', 'api_url')
@ -254,6 +277,7 @@ class Ipv6ListSerializer(NamespacedHMSerializer):
class DomainSerializer(NamespacedHMSerializer): class DomainSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.Domain` objects. """Serialize `machines.models.Domain` objects.
""" """
class Meta: class Meta:
model = machines.Domain model = machines.Domain
fields = ('interface_parent', 'name', 'extension', 'cname', fields = ('interface_parent', 'name', 'extension', 'cname',
@ -263,6 +287,7 @@ class DomainSerializer(NamespacedHMSerializer):
class IpListSerializer(NamespacedHMSerializer): class IpListSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.IpList` objects. """Serialize `machines.models.IpList` objects.
""" """
class Meta: class Meta:
model = machines.IpList model = machines.IpList
fields = ('ipv4', 'ip_type', 'need_infra', 'api_url') fields = ('ipv4', 'ip_type', 'need_infra', 'api_url')
@ -271,6 +296,7 @@ class IpListSerializer(NamespacedHMSerializer):
class ServiceSerializer(NamespacedHMSerializer): class ServiceSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.Service` objects. """Serialize `machines.models.Service` objects.
""" """
class Meta: class Meta:
model = machines.Service model = machines.Service
fields = ('service_type', 'min_time_regen', 'regular_time_regen', fields = ('service_type', 'min_time_regen', 'regular_time_regen',
@ -280,6 +306,7 @@ class ServiceSerializer(NamespacedHMSerializer):
class ServiceLinkSerializer(NamespacedHMSerializer): class ServiceLinkSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.Service_link` objects. """Serialize `machines.models.Service_link` objects.
""" """
class Meta: class Meta:
model = machines.Service_link model = machines.Service_link
fields = ('service', 'server', 'last_regen', 'asked_regen', fields = ('service', 'server', 'last_regen', 'asked_regen',
@ -306,6 +333,7 @@ class OuverturePortListSerializer(NamespacedHMSerializer):
class OuverturePortSerializer(NamespacedHMSerializer): class OuverturePortSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.OuverturePort` objects. """Serialize `machines.models.OuverturePort` objects.
""" """
class Meta: class Meta:
model = machines.OuverturePort model = machines.OuverturePort
fields = ('begin', 'end', 'port_list', 'protocole', 'io', 'api_url') fields = ('begin', 'end', 'port_list', 'protocole', 'io', 'api_url')
@ -339,6 +367,7 @@ class OptionalUserSerializer(NamespacedHMSerializer):
class OptionalMachineSerializer(NamespacedHMSerializer): class OptionalMachineSerializer(NamespacedHMSerializer):
"""Serialize `preferences.models.OptionalMachine` objects. """Serialize `preferences.models.OptionalMachine` objects.
""" """
class Meta: class Meta:
model = preferences.OptionalMachine model = preferences.OptionalMachine
fields = ('password_machine', 'max_lambdauser_interfaces', fields = ('password_machine', 'max_lambdauser_interfaces',
@ -363,6 +392,7 @@ class OptionalTopologieSerializer(NamespacedHMSerializer):
class GeneralOptionSerializer(NamespacedHMSerializer): class GeneralOptionSerializer(NamespacedHMSerializer):
"""Serialize `preferences.models.GeneralOption` objects. """Serialize `preferences.models.GeneralOption` objects.
""" """
class Meta: class Meta:
model = preferences.GeneralOption model = preferences.GeneralOption
fields = ('general_message', 'search_display_page', fields = ('general_message', 'search_display_page',
@ -374,6 +404,7 @@ class GeneralOptionSerializer(NamespacedHMSerializer):
class HomeServiceSerializer(NamespacedHMSerializer): class HomeServiceSerializer(NamespacedHMSerializer):
"""Serialize `preferences.models.Service` objects. """Serialize `preferences.models.Service` objects.
""" """
class Meta: class Meta:
model = preferences.Service model = preferences.Service
fields = ('name', 'url', 'description', 'image', 'api_url') fields = ('name', 'url', 'description', 'image', 'api_url')
@ -385,6 +416,7 @@ class HomeServiceSerializer(NamespacedHMSerializer):
class AssoOptionSerializer(NamespacedHMSerializer): class AssoOptionSerializer(NamespacedHMSerializer):
"""Serialize `preferences.models.AssoOption` objects. """Serialize `preferences.models.AssoOption` objects.
""" """
class Meta: class Meta:
model = preferences.AssoOption model = preferences.AssoOption
fields = ('name', 'siret', 'adresse1', 'adresse2', 'contact', fields = ('name', 'siret', 'adresse1', 'adresse2', 'contact',
@ -395,6 +427,7 @@ class AssoOptionSerializer(NamespacedHMSerializer):
class HomeOptionSerializer(NamespacedHMSerializer): class HomeOptionSerializer(NamespacedHMSerializer):
"""Serialize `preferences.models.HomeOption` objects. """Serialize `preferences.models.HomeOption` objects.
""" """
class Meta: class Meta:
model = preferences.HomeOption model = preferences.HomeOption
fields = ('facebook_url', 'twitter_url', 'twitter_account_name') fields = ('facebook_url', 'twitter_url', 'twitter_account_name')
@ -403,18 +436,19 @@ class HomeOptionSerializer(NamespacedHMSerializer):
class MailMessageOptionSerializer(NamespacedHMSerializer): class MailMessageOptionSerializer(NamespacedHMSerializer):
"""Serialize `preferences.models.MailMessageOption` objects. """Serialize `preferences.models.MailMessageOption` objects.
""" """
class Meta: class Meta:
model = preferences.MailMessageOption model = preferences.MailMessageOption
fields = ('welcome_mail_fr', 'welcome_mail_en') fields = ('welcome_mail_fr', 'welcome_mail_en')
# TOPOLOGIE # TOPOLOGIE
class StackSerializer(NamespacedHMSerializer): class StackSerializer(NamespacedHMSerializer):
"""Serialize `topologie.models.Stack` objects """Serialize `topologie.models.Stack` objects
""" """
class Meta: class Meta:
model = topologie.Stack model = topologie.Stack
fields = ('name', 'stack_id', 'details', 'member_id_min', fields = ('name', 'stack_id', 'details', 'member_id_min',
@ -424,6 +458,7 @@ class StackSerializer(NamespacedHMSerializer):
class AccessPointSerializer(NamespacedHMSerializer): class AccessPointSerializer(NamespacedHMSerializer):
"""Serialize `topologie.models.AccessPoint` objects """Serialize `topologie.models.AccessPoint` objects
""" """
class Meta: class Meta:
model = topologie.AccessPoint model = topologie.AccessPoint
fields = ('user', 'name', 'active', 'location', 'api_url') fields = ('user', 'name', 'active', 'location', 'api_url')
@ -433,6 +468,7 @@ class SwitchSerializer(NamespacedHMSerializer):
"""Serialize `topologie.models.Switch` objects """Serialize `topologie.models.Switch` objects
""" """
port_amount = serializers.IntegerField(source='number') port_amount = serializers.IntegerField(source='number')
class Meta: class Meta:
model = topologie.Switch model = topologie.Switch
fields = ('user', 'name', 'active', 'port_amount', 'stack', fields = ('user', 'name', 'active', 'port_amount', 'stack',
@ -442,6 +478,7 @@ class SwitchSerializer(NamespacedHMSerializer):
class ServerSerializer(NamespacedHMSerializer): class ServerSerializer(NamespacedHMSerializer):
"""Serialize `topologie.models.Server` objects """Serialize `topologie.models.Server` objects
""" """
class Meta: class Meta:
model = topologie.Server model = topologie.Server
fields = ('user', 'name', 'active', 'api_url') fields = ('user', 'name', 'active', 'api_url')
@ -450,6 +487,7 @@ class ServerSerializer(NamespacedHMSerializer):
class ModelSwitchSerializer(NamespacedHMSerializer): class ModelSwitchSerializer(NamespacedHMSerializer):
"""Serialize `topologie.models.ModelSwitch` objects """Serialize `topologie.models.ModelSwitch` objects
""" """
class Meta: class Meta:
model = topologie.ModelSwitch model = topologie.ModelSwitch
fields = ('reference', 'constructor', 'api_url') fields = ('reference', 'constructor', 'api_url')
@ -458,6 +496,7 @@ class ModelSwitchSerializer(NamespacedHMSerializer):
class ConstructorSwitchSerializer(NamespacedHMSerializer): class ConstructorSwitchSerializer(NamespacedHMSerializer):
"""Serialize `topologie.models.ConstructorSwitch` objects """Serialize `topologie.models.ConstructorSwitch` objects
""" """
class Meta: class Meta:
model = topologie.ConstructorSwitch model = topologie.ConstructorSwitch
fields = ('name', 'api_url') fields = ('name', 'api_url')
@ -466,6 +505,7 @@ class ConstructorSwitchSerializer(NamespacedHMSerializer):
class SwitchBaySerializer(NamespacedHMSerializer): class SwitchBaySerializer(NamespacedHMSerializer):
"""Serialize `topologie.models.SwitchBay` objects """Serialize `topologie.models.SwitchBay` objects
""" """
class Meta: class Meta:
model = topologie.SwitchBay model = topologie.SwitchBay
fields = ('name', 'building', 'info', 'api_url') fields = ('name', 'building', 'info', 'api_url')
@ -474,6 +514,7 @@ class SwitchBaySerializer(NamespacedHMSerializer):
class BuildingSerializer(NamespacedHMSerializer): class BuildingSerializer(NamespacedHMSerializer):
"""Serialize `topologie.models.Building` objects """Serialize `topologie.models.Building` objects
""" """
class Meta: class Meta:
model = topologie.Building model = topologie.Building
fields = ('name', 'api_url') fields = ('name', 'api_url')
@ -509,6 +550,7 @@ class PortProfileSerializer(NamespacedHMSerializer):
class RoomSerializer(NamespacedHMSerializer): class RoomSerializer(NamespacedHMSerializer):
"""Serialize `topologie.models.Room` objects """Serialize `topologie.models.Room` objects
""" """
class Meta: class Meta:
model = topologie.Room model = topologie.Room
fields = ('name', 'details', 'api_url') fields = ('name', 'details', 'api_url')
@ -576,11 +618,12 @@ class AdherentSerializer(NamespacedHMSerializer):
fields = ('name', 'surname', 'pseudo', 'email', 'local_email_redirect', fields = ('name', 'surname', 'pseudo', 'email', 'local_email_redirect',
'local_email_enabled', 'school', 'shell', 'comment', 'local_email_enabled', 'school', 'shell', 'comment',
'state', 'registered', 'telephone', 'room', 'solde', 'state', 'registered', 'telephone', 'room', 'solde',
'access', 'end_access', 'uid', 'api_url','gid') 'access', 'end_access', 'uid', 'api_url', 'gid')
extra_kwargs = { extra_kwargs = {
'shell': {'view_name': 'shell-detail'} 'shell': {'view_name': 'shell-detail'}
} }
class HomeCreationSerializer(NamespacedHMSerializer): class HomeCreationSerializer(NamespacedHMSerializer):
"""Serialize 'users.models.User' minimal infos to create home """Serialize 'users.models.User' minimal infos to create home
""" """
@ -591,9 +634,11 @@ class HomeCreationSerializer(NamespacedHMSerializer):
model = users.User model = users.User
fields = ('pseudo', 'uid', 'gid') fields = ('pseudo', 'uid', 'gid')
class ServiceUserSerializer(NamespacedHMSerializer): class ServiceUserSerializer(NamespacedHMSerializer):
"""Serialize `users.models.ServiceUser` objects. """Serialize `users.models.ServiceUser` objects.
""" """
class Meta: class Meta:
model = users.ServiceUser model = users.ServiceUser
fields = ('pseudo', 'access_group', 'comment', 'api_url') fields = ('pseudo', 'access_group', 'comment', 'api_url')
@ -602,6 +647,7 @@ class ServiceUserSerializer(NamespacedHMSerializer):
class SchoolSerializer(NamespacedHMSerializer): class SchoolSerializer(NamespacedHMSerializer):
"""Serialize `users.models.School` objects. """Serialize `users.models.School` objects.
""" """
class Meta: class Meta:
model = users.School model = users.School
fields = ('name', 'api_url') fields = ('name', 'api_url')
@ -610,6 +656,7 @@ class SchoolSerializer(NamespacedHMSerializer):
class ListRightSerializer(NamespacedHMSerializer): class ListRightSerializer(NamespacedHMSerializer):
"""Serialize `users.models.ListRight` objects. """Serialize `users.models.ListRight` objects.
""" """
class Meta: class Meta:
model = users.ListRight model = users.ListRight
fields = ('unix_name', 'gid', 'critical', 'details', 'api_url') fields = ('unix_name', 'gid', 'critical', 'details', 'api_url')
@ -618,6 +665,7 @@ class ListRightSerializer(NamespacedHMSerializer):
class ShellSerializer(NamespacedHMSerializer): class ShellSerializer(NamespacedHMSerializer):
"""Serialize `users.models.ListShell` objects. """Serialize `users.models.ListShell` objects.
""" """
class Meta: class Meta:
model = users.ListShell model = users.ListShell
fields = ('shell', 'api_url') fields = ('shell', 'api_url')
@ -651,6 +699,7 @@ class EMailAddressSerializer(NamespacedHMSerializer):
"""Serialize `users.models.EMailAddress` objects. """Serialize `users.models.EMailAddress` objects.
""" """
user = serializers.CharField(source='user.pseudo', read_only=True) user = serializers.CharField(source='user.pseudo', read_only=True)
class Meta: class Meta:
model = users.EMailAddress model = users.EMailAddress
fields = ('user', 'local_part', 'complete_email_address', 'api_url') fields = ('user', 'local_part', 'complete_email_address', 'api_url')
@ -772,13 +821,14 @@ class LocalEmailUsersSerializer(NamespacedHMSerializer):
'email_address', 'email') 'email_address', 'email')
#Firewall # Firewall
class FirewallPortListSerializer(serializers.ModelSerializer): class FirewallPortListSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = machines.OuverturePort model = machines.OuverturePort
fields = ('begin', 'end', 'protocole', 'io', 'show_port') fields = ('begin', 'end', 'protocole', 'io', 'show_port')
class FirewallOuverturePortListSerializer(serializers.ModelSerializer): class FirewallOuverturePortListSerializer(serializers.ModelSerializer):
tcp_ports_in = FirewallPortListSerializer(many=True, read_only=True) tcp_ports_in = FirewallPortListSerializer(many=True, read_only=True)
udp_ports_in = FirewallPortListSerializer(many=True, read_only=True) udp_ports_in = FirewallPortListSerializer(many=True, read_only=True)
@ -789,6 +839,7 @@ class FirewallOuverturePortListSerializer(serializers.ModelSerializer):
model = machines.OuverturePortList model = machines.OuverturePortList
fields = ('tcp_ports_in', 'udp_ports_in', 'tcp_ports_out', 'udp_ports_out') fields = ('tcp_ports_in', 'udp_ports_in', 'tcp_ports_out', 'udp_ports_out')
class SubnetPortsOpenSerializer(serializers.ModelSerializer): class SubnetPortsOpenSerializer(serializers.ModelSerializer):
ouverture_ports = FirewallOuverturePortListSerializer(read_only=True) ouverture_ports = FirewallOuverturePortListSerializer(read_only=True)
@ -796,6 +847,7 @@ class SubnetPortsOpenSerializer(serializers.ModelSerializer):
model = machines.IpType model = machines.IpType
fields = ('type', 'domaine_ip_start', 'domaine_ip_stop', 'complete_prefixv6', 'ouverture_ports') fields = ('type', 'domaine_ip_start', 'domaine_ip_stop', 'complete_prefixv6', 'ouverture_ports')
class InterfacePortsOpenSerializer(serializers.ModelSerializer): class InterfacePortsOpenSerializer(serializers.ModelSerializer):
port_lists = FirewallOuverturePortListSerializer(read_only=True, many=True) port_lists = FirewallOuverturePortListSerializer(read_only=True, many=True)
ipv4 = serializers.CharField(source='ipv4.ipv4', read_only=True) ipv4 = serializers.CharField(source='ipv4.ipv4', read_only=True)
@ -805,6 +857,7 @@ class InterfacePortsOpenSerializer(serializers.ModelSerializer):
model = machines.Interface model = machines.Interface
fields = ('port_lists', 'ipv4', 'ipv6') fields = ('port_lists', 'ipv4', 'ipv6')
# DHCP # DHCP
@ -829,6 +882,7 @@ class SOARecordSerializer(SOASerializer):
"""Serialize `machines.models.SOA` objects with the data needed to """Serialize `machines.models.SOA` objects with the data needed to
generate a SOA DNS record. generate a SOA DNS record.
""" """
class Meta: class Meta:
model = machines.SOA model = machines.SOA
fields = ('name', 'mail', 'refresh', 'retry', 'expire', 'ttl') fields = ('name', 'mail', 'refresh', 'retry', 'expire', 'ttl')
@ -838,6 +892,7 @@ class OriginV4RecordSerializer(IpListSerializer):
"""Serialize `machines.models.IpList` objects with the data needed to """Serialize `machines.models.IpList` objects with the data needed to
generate an IPv4 Origin DNS record. generate an IPv4 Origin DNS record.
""" """
class Meta(IpListSerializer.Meta): class Meta(IpListSerializer.Meta):
fields = ('ipv4',) fields = ('ipv4',)
@ -866,6 +921,7 @@ class TXTRecordSerializer(TxtSerializer):
"""Serialize `machines.models.Txt` objects with the data needed to """Serialize `machines.models.Txt` objects with the data needed to
generate a TXT DNS record. generate a TXT DNS record.
""" """
class Meta(TxtSerializer.Meta): class Meta(TxtSerializer.Meta):
fields = ('field1', 'field2') fields = ('field1', 'field2')
@ -884,6 +940,7 @@ class SSHFPRecordSerializer(SshFpSerializer):
"""Serialize `machines.models.SshFp` objects with the data needed to """Serialize `machines.models.SshFp` objects with the data needed to
generate a SSHFP DNS record. generate a SSHFP DNS record.
""" """
class Meta(SshFpSerializer.Meta): class Meta(SshFpSerializer.Meta):
fields = ('algo_id', 'hash') fields = ('algo_id', 'hash')
@ -990,22 +1047,24 @@ class DNSReverseZonesSerializer(serializers.ModelSerializer):
ptr_records = ARecordSerializer(many=True, source='get_associated_ptr_records') ptr_records = ARecordSerializer(many=True, source='get_associated_ptr_records')
ptr_v6_records = AAAARecordSerializer(many=True, source='get_associated_ptr_v6_records') ptr_v6_records = AAAARecordSerializer(many=True, source='get_associated_ptr_v6_records')
class Meta: class Meta:
model = machines.IpType model = machines.IpType
fields = ('type', 'extension', 'soa', 'ns_records', 'mx_records', fields = ('type', 'extension', 'soa', 'ns_records', 'mx_records',
'txt_records', 'ptr_records', 'ptr_v6_records', 'cidrs', 'txt_records', 'ptr_records', 'ptr_v6_records', 'cidrs',
'prefix_v6', 'prefix_v6_length') 'prefix_v6', 'prefix_v6_length')
# MAILING # MAILING
class MailingMemberSerializer(UserSerializer): class MailingMemberSerializer(UserSerializer):
"""Serialize the data about a mailing member. """Serialize the data about a mailing member.
""" """
class Meta(UserSerializer.Meta): class Meta(UserSerializer.Meta):
fields = ('name', 'pseudo', 'get_mail') fields = ('name', 'pseudo', 'get_mail')
class MailingSerializer(ClubSerializer): class MailingSerializer(ClubSerializer):
"""Serialize the data about a mailing. """Serialize the data about a mailing.
""" """

View file

@ -21,10 +21,11 @@
"""Defines the test suite for the API """Defines the test suite for the API
""" """
import json
import datetime import datetime
from rest_framework.test import APITestCase import json
from requests import codes from requests import codes
from rest_framework.test import APITestCase
import cotisations.models as cotisations import cotisations.models as cotisations
import machines.models as machines import machines.models as machines
@ -150,8 +151,8 @@ class APIEndpointsTestCase(APITestCase):
# users_club_1) # users_club_1)
'/api/users/club/4/', '/api/users/club/4/',
'/api/users/listright/', '/api/users/listright/',
# TODO: Merge !145 # TODO: Merge !145
# '/api/users/listright/1/', # '/api/users/listright/1/',
'/api/users/school/', '/api/users/school/',
'/api/users/school/1/', '/api/users/school/1/',
'/api/users/serviceuser/', '/api/users/serviceuser/',
@ -363,7 +364,7 @@ class APIEndpointsTestCase(APITestCase):
machine=cls.machines_machine_1, # Dep machines.Machine machine=cls.machines_machine_1, # Dep machines.Machine
type=cls.machines_machinetype_1, # Dep machines.MachineType type=cls.machines_machinetype_1, # Dep machines.MachineType
details="machines Interface 1", details="machines Interface 1",
#port_lists=[cls.machines_ouvertureportlist_1] # Dep machines.OuverturePortList # port_lists=[cls.machines_ouvertureportlist_1] # Dep machines.OuverturePortList
) )
cls.machines_domain_1 = machines.Domain.objects.create( cls.machines_domain_1 = machines.Domain.objects.create(
interface_parent=cls.machines_interface_1, # Dep machines.Interface interface_parent=cls.machines_interface_1, # Dep machines.Interface
@ -525,14 +526,14 @@ class APIEndpointsTestCase(APITestCase):
uid_number=21103, uid_number=21103,
rezo_rez_uid=21103 rezo_rez_uid=21103
) )
# Need merge of MR145 to work # Need merge of MR145 to work
# TODO: Merge !145 # TODO: Merge !145
# cls.users_listright_1 = users.ListRight.objects.create( # cls.users_listright_1 = users.ListRight.objects.create(
# unix_name="userslistright", # unix_name="userslistright",
# gid=601, # gid=601,
# critical=False, # critical=False,
# details="userslistright" # details="userslistright"
# ) # )
cls.users_serviceuser_1 = users.ServiceUser.objects.create( cls.users_serviceuser_1 = users.ServiceUser.objects.create(
password="password", password="password",
last_login=datetime.datetime.now(datetime.timezone.utc), last_login=datetime.datetime.now(datetime.timezone.utc),
@ -676,6 +677,7 @@ class APIEndpointsTestCase(APITestCase):
formats=[None, 'json', 'api'], formats=[None, 'json', 'api'],
assert_more=assert_more) assert_more=assert_more)
class APIPaginationTestCase(APITestCase): class APIPaginationTestCase(APITestCase):
"""Test case to check that the pagination is used on all endpoints that """Test case to check that the pagination is used on all endpoints that
should use it. should use it.
@ -756,7 +758,7 @@ class APIPaginationTestCase(APITestCase):
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
cls.superuser.delete() cls.superuser.delete()
super().tearDownClass() super(APIPaginationTestCase, self).tearDownClass()
def test_pagination(self): def test_pagination(self):
"""Tests that every endpoint is using the pagination correctly. """Tests that every endpoint is using the pagination correctly.
@ -776,4 +778,3 @@ class APIPaginationTestCase(APITestCase):
assert 'previous' in res_json.keys() assert 'previous' in res_json.keys()
assert 'results' in res_json.keys() assert 'results' in res_json.keys()
assert not len('results') > 100 assert not len('results') > 100

View file

@ -32,7 +32,6 @@ from django.conf.urls import url, include
from . import views from . import views
from .routers import AllViewsRouter from .routers import AllViewsRouter
router = AllViewsRouter() router = AllViewsRouter()
# COTISATIONS # COTISATIONS
router.register_viewset(r'cotisations/facture', views.FactureViewSet) router.register_viewset(r'cotisations/facture', views.FactureViewSet)
@ -121,7 +120,6 @@ router.register_view(r'mailing/club', views.ClubMailingView),
# TOKEN AUTHENTICATION # TOKEN AUTHENTICATION
router.register_view(r'token-auth', views.ObtainExpiringAuthToken) router.register_view(r'token-auth', views.ObtainExpiringAuthToken)
urlpatterns = [ urlpatterns = [
url(r'^', include(router.urls)), url(r'^', include(router.urls)),
] ]

View file

@ -30,10 +30,10 @@ import datetime
from django.conf import settings from django.conf import settings
from django.db.models import Q from django.db.models import Q
from rest_framework.authtoken.views import ObtainAuthToken
from rest_framework.authtoken.models import Token
from rest_framework.response import Response
from rest_framework import viewsets, generics, views from rest_framework import viewsets, generics, views
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 machines.models as machines
@ -41,7 +41,6 @@ import preferences.models as preferences
import topologie.models as topologie import topologie.models as topologie
import users.models as users import users.models as users
from re2o.utils import all_active_interfaces, all_has_access from re2o.utils import all_active_interfaces, all_has_access
from . import serializers from . import serializers
from .pagination import PageSizedPagination from .pagination import PageSizedPagination
from .permissions import ACLPermission from .permissions import ACLPermission
@ -164,6 +163,7 @@ class TxtViewSet(viewsets.ReadOnlyModelViewSet):
queryset = machines.Txt.objects.all() queryset = machines.Txt.objects.all()
serializer_class = serializers.TxtSerializer serializer_class = serializers.TxtSerializer
class DNameViewSet(viewsets.ReadOnlyModelViewSet): class DNameViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.DName` objects. """Exposes list and details of `machines.models.DName` objects.
""" """
@ -256,8 +256,8 @@ class RoleViewSet(viewsets.ReadOnlyModelViewSet):
class OptionalUserView(generics.RetrieveAPIView): class OptionalUserView(generics.RetrieveAPIView):
"""Exposes details of `preferences.models.` settings. """Exposes details of `preferences.models.` settings.
""" """
permission_classes = (ACLPermission, ) permission_classes = (ACLPermission,)
perms_map = {'GET' : [preferences.OptionalUser.can_view_all]} perms_map = {'GET': [preferences.OptionalUser.can_view_all]}
serializer_class = serializers.OptionalUserSerializer serializer_class = serializers.OptionalUserSerializer
def get_object(self): def get_object(self):
@ -267,8 +267,8 @@ class OptionalUserView(generics.RetrieveAPIView):
class OptionalMachineView(generics.RetrieveAPIView): class OptionalMachineView(generics.RetrieveAPIView):
"""Exposes details of `preferences.models.OptionalMachine` settings. """Exposes details of `preferences.models.OptionalMachine` settings.
""" """
permission_classes = (ACLPermission, ) permission_classes = (ACLPermission,)
perms_map = {'GET' : [preferences.OptionalMachine.can_view_all]} perms_map = {'GET': [preferences.OptionalMachine.can_view_all]}
serializer_class = serializers.OptionalMachineSerializer serializer_class = serializers.OptionalMachineSerializer
def get_object(self): def get_object(self):
@ -278,8 +278,8 @@ class OptionalMachineView(generics.RetrieveAPIView):
class OptionalTopologieView(generics.RetrieveAPIView): class OptionalTopologieView(generics.RetrieveAPIView):
"""Exposes details of `preferences.models.OptionalTopologie` settings. """Exposes details of `preferences.models.OptionalTopologie` settings.
""" """
permission_classes = (ACLPermission, ) permission_classes = (ACLPermission,)
perms_map = {'GET' : [preferences.OptionalTopologie.can_view_all]} perms_map = {'GET': [preferences.OptionalTopologie.can_view_all]}
serializer_class = serializers.OptionalTopologieSerializer serializer_class = serializers.OptionalTopologieSerializer
def get_object(self): def get_object(self):
@ -289,8 +289,8 @@ class OptionalTopologieView(generics.RetrieveAPIView):
class GeneralOptionView(generics.RetrieveAPIView): class GeneralOptionView(generics.RetrieveAPIView):
"""Exposes details of `preferences.models.GeneralOption` settings. """Exposes details of `preferences.models.GeneralOption` settings.
""" """
permission_classes = (ACLPermission, ) permission_classes = (ACLPermission,)
perms_map = {'GET' : [preferences.GeneralOption.can_view_all]} perms_map = {'GET': [preferences.GeneralOption.can_view_all]}
serializer_class = serializers.GeneralOptionSerializer serializer_class = serializers.GeneralOptionSerializer
def get_object(self): def get_object(self):
@ -307,8 +307,8 @@ class HomeServiceViewSet(viewsets.ReadOnlyModelViewSet):
class AssoOptionView(generics.RetrieveAPIView): class AssoOptionView(generics.RetrieveAPIView):
"""Exposes details of `preferences.models.AssoOption` settings. """Exposes details of `preferences.models.AssoOption` settings.
""" """
permission_classes = (ACLPermission, ) permission_classes = (ACLPermission,)
perms_map = {'GET' : [preferences.AssoOption.can_view_all]} perms_map = {'GET': [preferences.AssoOption.can_view_all]}
serializer_class = serializers.AssoOptionSerializer serializer_class = serializers.AssoOptionSerializer
def get_object(self): def get_object(self):
@ -318,8 +318,8 @@ class AssoOptionView(generics.RetrieveAPIView):
class HomeOptionView(generics.RetrieveAPIView): class HomeOptionView(generics.RetrieveAPIView):
"""Exposes details of `preferences.models.HomeOption` settings. """Exposes details of `preferences.models.HomeOption` settings.
""" """
permission_classes = (ACLPermission, ) permission_classes = (ACLPermission,)
perms_map = {'GET' : [preferences.HomeOption.can_view_all]} perms_map = {'GET': [preferences.HomeOption.can_view_all]}
serializer_class = serializers.HomeOptionSerializer serializer_class = serializers.HomeOptionSerializer
def get_object(self): def get_object(self):
@ -329,8 +329,8 @@ class HomeOptionView(generics.RetrieveAPIView):
class MailMessageOptionView(generics.RetrieveAPIView): class MailMessageOptionView(generics.RetrieveAPIView):
"""Exposes details of `preferences.models.MailMessageOption` settings. """Exposes details of `preferences.models.MailMessageOption` settings.
""" """
permission_classes = (ACLPermission, ) permission_classes = (ACLPermission,)
perms_map = {'GET' : [preferences.MailMessageOption.can_view_all]} perms_map = {'GET': [preferences.MailMessageOption.can_view_all]}
serializer_class = serializers.MailMessageOptionSerializer serializer_class = serializers.MailMessageOptionSerializer
def get_object(self): def get_object(self):
@ -424,6 +424,7 @@ class PortProfileViewSet(viewsets.ReadOnlyModelViewSet):
queryset = topologie.PortProfile.objects.all() queryset = topologie.PortProfile.objects.all()
serializer_class = serializers.PortProfileSerializer serializer_class = serializers.PortProfileSerializer
# USER # USER
@ -433,12 +434,14 @@ class UserViewSet(viewsets.ReadOnlyModelViewSet):
queryset = users.User.objects.all() queryset = users.User.objects.all()
serializer_class = serializers.UserSerializer serializer_class = serializers.UserSerializer
class HomeCreationViewSet(viewsets.ReadOnlyModelViewSet): class HomeCreationViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes infos of `users.models.Users` objects to create homes. """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)) queryset = users.User.objects.exclude(Q(state=users.User.STATE_DISABLED) | Q(state=users.User.STATE_NOT_YET_ACTIVE))
serializer_class = serializers.HomeCreationSerializer serializer_class = serializers.HomeCreationSerializer
class ClubViewSet(viewsets.ReadOnlyModelViewSet): class ClubViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `users.models.Club` objects. """Exposes list and details of `users.models.Club` objects.
""" """
@ -585,16 +588,18 @@ class HostMacIpView(generics.ListAPIView):
serializer_class = serializers.HostMacIpSerializer serializer_class = serializers.HostMacIpSerializer
#Firewall # Firewall
class SubnetPortsOpenView(generics.ListAPIView): class SubnetPortsOpenView(generics.ListAPIView):
queryset = machines.IpType.objects.all() queryset = machines.IpType.objects.all()
serializer_class = serializers.SubnetPortsOpenSerializer serializer_class = serializers.SubnetPortsOpenSerializer
class InterfacePortsOpenView(generics.ListAPIView): class InterfacePortsOpenView(generics.ListAPIView):
queryset = machines.Interface.objects.filter(port_lists__isnull=False).distinct() queryset = machines.Interface.objects.filter(port_lists__isnull=False).distinct()
serializer_class = serializers.InterfacePortsOpenSerializer serializer_class = serializers.InterfacePortsOpenSerializer
# DNS # DNS
@ -612,6 +617,7 @@ class DNSZonesView(generics.ListAPIView):
.all()) .all())
serializer_class = serializers.DNSZonesSerializer serializer_class = serializers.DNSZonesSerializer
class DNSReverseZonesView(generics.ListAPIView): class DNSReverseZonesView(generics.ListAPIView):
"""Exposes the detailed information about each extension (hostnames, """Exposes the detailed information about each extension (hostnames,
IPs, DNS records, etc.) in order to build the DNS zone files. IPs, DNS records, etc.) in order to build the DNS zone files.
@ -620,8 +626,6 @@ class DNSReverseZonesView(generics.ListAPIView):
serializer_class = serializers.DNSReverseZonesSerializer serializer_class = serializers.DNSReverseZonesSerializer
# MAILING # MAILING
@ -630,8 +634,8 @@ class StandardMailingView(views.APIView):
order to building the corresponding mailing lists. order to building the corresponding mailing lists.
""" """
pagination_class = PageSizedPagination pagination_class = PageSizedPagination
permission_classes = (ACLPermission, ) permission_classes = (ACLPermission,)
perms_map = {'GET' : [users.User.can_view_all]} perms_map = {'GET': [users.User.can_view_all]}
def get(self, request, format=None): def get(self, request, format=None):
adherents_data = serializers.MailingMemberSerializer(all_has_access(), many=True).data adherents_data = serializers.MailingMemberSerializer(all_has_access(), many=True).data
@ -659,6 +663,7 @@ class ObtainExpiringAuthToken(ObtainAuthToken):
`rest_framework.auth_token.views.ObtainAuthToken` view except that the `rest_framework.auth_token.views.ObtainAuthToken` view except that the
expiration time is send along with the token as an addtional information. expiration time is send along with the token as an addtional information.
""" """
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
serializer = self.serializer_class(data=request.data) serializer = self.serializer_class(data=request.data)
serializer.is_valid(raise_exception=True) serializer.is_valid(raise_exception=True)