Commit 04de9db6 authored by root's avatar root Committed by Maël Kervella

serialisation des alias mail des users ayant activé l'adresse interne

parent 5c433acd
...@@ -608,6 +608,9 @@ class MailAliasSerializer(NamespacedHMSerializer): ...@@ -608,6 +608,9 @@ class MailAliasSerializer(NamespacedHMSerializer):
fields = ('user', 'valeur', 'complete_mail') fields = ('user', 'valeur', 'complete_mail')
# SERVICE REGEN # SERVICE REGEN
...@@ -624,6 +627,17 @@ class ServiceRegenSerializer(NamespacedHMSerializer): ...@@ -624,6 +627,17 @@ class ServiceRegenSerializer(NamespacedHMSerializer):
extra_kwargs = { extra_kwargs = {
'api_url': {'view_name': 'serviceregen-detail'} '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')
# DHCP # DHCP
......
...@@ -98,6 +98,8 @@ router.register_viewset(r'users/mailalias', views.MailAliasViewSet) ...@@ -98,6 +98,8 @@ router.register_viewset(r'users/mailalias', views.MailAliasViewSet)
router.register_viewset(r'services/regen', views.ServiceRegenViewSet, base_name='serviceregen') router.register_viewset(r'services/regen', views.ServiceRegenViewSet, base_name='serviceregen')
# DHCP # DHCP
router.register_view(r'dhcp/hostmacip', views.HostMacIpView), router.register_view(r'dhcp/hostmacip', views.HostMacIpView),
# Mail config
router.register_view(r'mail/alias', views.UserMailAliasView),
# DNS # DNS
router.register_view(r'dns/zones', views.DNSZonesView), router.register_view(r'dns/zones', views.DNSZonesView),
# MAILING # MAILING
......
...@@ -496,6 +496,17 @@ class ServiceRegenViewSet(viewsets.ModelViewSet): ...@@ -496,6 +496,17 @@ class ServiceRegenViewSet(viewsets.ModelViewSet):
return queryset return queryset
# 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
# DHCP # DHCP
class HostMacIpView(generics.ListAPIView): class HostMacIpView(generics.ListAPIView):
......
...@@ -684,6 +684,12 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser, ...@@ -684,6 +684,12 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
else: else:
return str(self.mailalias_set.get(valeur=self.pseudo)) 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): def get_next_domain_name(self):
"""Look for an available name for a new interface for """Look for an available name for a new interface for
this user by trying "pseudo0", "pseudo1", "pseudo2", ... this user by trying "pseudo0", "pseudo1", "pseudo2", ...
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment