From 1e823ad75be4ab77a3bd6d759f5a65f8a2fb1128 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 15 Jul 2018 20:31:42 +0000 Subject: [PATCH] =?UTF-8?q?serialisation=20des=20alias=20mail=20des=20user?= =?UTF-8?q?s=20ayant=20activ=C3=A9=20l'adresse=20interne?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/serializers.py | 14 ++++++++++++++ api/urls.py | 2 ++ api/views.py | 11 +++++++++++ users/models.py | 6 ++++++ 4 files changed, 33 insertions(+) mode change 100644 => 100755 api/serializers.py mode change 100644 => 100755 api/urls.py mode change 100644 => 100755 api/views.py mode change 100644 => 100755 users/models.py diff --git a/api/serializers.py b/api/serializers.py old mode 100644 new mode 100755 index c58a0e1f..e7f6e988 --- a/api/serializers.py +++ b/api/serializers.py @@ -631,6 +631,9 @@ class MailAliasSerializer(NamespacedHMSerializer): fields = ('user', 'valeur', 'complete_mail') + + + # SERVICE REGEN @@ -647,6 +650,17 @@ class ServiceRegenSerializer(NamespacedHMSerializer): extra_kwargs = { 'api_url': {'view_name': 'serviceregen-detail'} } + +# Configuration mail + + +class UserMailAliasSerializer(NamespacedHMSerializer): + get_mail_aliases = MailAliasSerializer(read_only=True, many=True) + + class Meta: + model = users.User + fields = ('pseudo', 'get_mail_aliases') + # Switches et ports diff --git a/api/urls.py b/api/urls.py old mode 100644 new mode 100755 index 83b1108c..24e8920c --- a/api/urls.py +++ b/api/urls.py @@ -102,6 +102,8 @@ router.register_view(r'dhcp/hostmacip', views.HostMacIpView), # Switches config router.register_view(r'switchs/ports-config', views.SwitchPortView), router.register_view(r'switchs/role', views.RoleView), +# Mail config +router.register_view(r'mail/alias', views.UserMailAliasView), # Reminder router.register_view(r'reminder/get-users', views.ReminderView), # DNS diff --git a/api/views.py b/api/views.py old mode 100644 new mode 100755 index 55b4fd6a..bc4aa4d1 --- a/api/views.py +++ b/api/views.py @@ -521,6 +521,17 @@ class RoleView(generics.ListAPIView): serializer_class = serializers.RoleSerializer +# Server mail config + + +class UserMailAliasView(generics.ListAPIView): + """Expose all the aliases of the users that activated the internal address + """ + + queryset = users.User.objects.filter(internal_address=True) + serializer_class = serializers.UserMailAliasSerializer + + # Rappel fin adhésion class ReminderView(generics.ListAPIView): diff --git a/users/models.py b/users/models.py old mode 100644 new mode 100755 index b0e56ad1..c05b63e3 --- a/users/models.py +++ b/users/models.py @@ -682,6 +682,12 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser, else: return str(self.mailalias_set.get(valeur=self.pseudo)) + @cached_property + def get_mail_aliases(self): + if self.internal_address: + return self.mailalias_set.all() + return None + def get_next_domain_name(self): """Look for an available name for a new interface for this user by trying "pseudo0", "pseudo1", "pseudo2", ...