From 93e2424da758cde2c09b6821a0f29b0b8ae61393 Mon Sep 17 00:00:00 2001 From: detraz Date: Sat, 17 Nov 2018 19:51:37 +0100 Subject: [PATCH] Export users basic et critical --- api/serializers.py | 5 ++--- api/urls.py | 2 ++ api/views.py | 14 +++++++++++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/api/serializers.py b/api/serializers.py index f2ff9954..e7b23f32 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -632,9 +632,8 @@ class AdherentSerializer(NamespacedHMSerializer): } -class HomeCreationSerializer(NamespacedHMSerializer): - """Serialize 'users.models.User' minimal infos to create home - """ +class BasicUserSerializer(NamespacedHMSerializer): + """Serialize 'users.models.User' minimal infos""" uid = serializers.IntegerField(source='uid_number') gid = serializers.IntegerField(source='gid_number') diff --git a/api/urls.py b/api/urls.py index e361d732..723ca78c 100644 --- a/api/urls.py +++ b/api/urls.py @@ -88,6 +88,8 @@ 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) diff --git a/api/views.py b/api/views.py index a2a376e9..21f7b438 100644 --- a/api/views.py +++ b/api/views.py @@ -445,7 +445,19 @@ 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)) - serializer_class = serializers.HomeCreationSerializer + 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):