From 299453b5bba5edd7605d33895fbbb3549a8d23bd Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Sat, 30 Jun 2018 15:18:08 +0200 Subject: [PATCH] Serialisation des alias mail --- api/serializers.py | 17 ++++++++++++++++- api/urls.py | 1 + api/views.py | 7 +++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/api/serializers.py b/api/serializers.py index bff1bd9c..8f7c8035 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -485,10 +485,12 @@ class UserSerializer(NamespacedHMSerializer): """ access = serializers.BooleanField(source='has_access') uid = serializers.IntegerField(source='uid_number') + email = serializers.CharField(source='get_mail') class Meta: model = users.User fields = ('name', 'pseudo', 'email', 'school', 'shell', 'comment', + 'external_mail', 'redirection', 'internal_address', 'state', 'registered', 'telephone', 'solde', 'access', 'end_access', 'uid', 'class_name', 'api_url') extra_kwargs = { @@ -502,10 +504,12 @@ class ClubSerializer(NamespacedHMSerializer): name = serializers.CharField(source='surname') access = serializers.BooleanField(source='has_access') uid = serializers.IntegerField(source='uid_number') + email = serializers.CharField(source='get_mail') class Meta: model = users.Club fields = ('name', 'pseudo', 'email', 'school', 'shell', 'comment', + 'external_mail', 'redirection', 'internal_address', 'state', 'registered', 'telephone', 'solde', 'room', 'access', 'end_access', 'administrators', 'members', 'mailing', 'uid', 'api_url') @@ -519,10 +523,12 @@ class AdherentSerializer(NamespacedHMSerializer): """ access = serializers.BooleanField(source='has_access') uid = serializers.IntegerField(source='uid_number') + email = serializers.CharField(source='get_mail') class Meta: model = users.Adherent - fields = ('name', 'surname', 'pseudo', 'email', 'school', 'shell', + fields = ('name', 'surname', 'pseudo', 'email', 'redirection', 'internal_address', + 'external_mail', 'school', 'shell', 'comment', 'state', 'registered', 'telephone', 'room', 'solde', 'access', 'end_access', 'uid', 'api_url') extra_kwargs = { @@ -586,6 +592,15 @@ class WhitelistSerializer(NamespacedHMSerializer): fields = ('user', 'raison', 'date_start', 'date_end', 'active', 'api_url') +class MailAliasSerializer(NamespacedHMSerializer): + """Serialize `users.models.MailAlias` objects. + """ + + class Meta: + model = users.MailAlias + fields = ('user', 'valeur', 'complete_mail') + + # SERVICE REGEN diff --git a/api/urls.py b/api/urls.py index 2947850e..6003284b 100644 --- a/api/urls.py +++ b/api/urls.py @@ -92,6 +92,7 @@ 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/mailalias', views.MailAliasViewSet) # SERVICE REGEN router.register_viewset(r'services/regen', views.ServiceRegenViewSet, base_name='serviceregen') # DHCP diff --git a/api/views.py b/api/views.py index 45e083cc..60be3b46 100644 --- a/api/views.py +++ b/api/views.py @@ -462,6 +462,13 @@ class WhitelistViewSet(viewsets.ReadOnlyModelViewSet): serializer_class = serializers.WhitelistSerializer +class MailAliasViewSet(viewsets.ReadOnlyModelViewSet): + """Exposes list and details of `users.models.MailAlias` objects. + """ + queryset = users.MailAlias.objects.all() + serializer_class = serializers.MailAliasSerializer + + # SERVICE REGEN