From 27d18e034b4740d66986a57cda20a75b95f68838 Mon Sep 17 00:00:00 2001 From: Arthur Grisel-Davy Date: Sun, 5 Aug 2018 17:22:12 +0200 Subject: [PATCH] =?UTF-8?q?serialization=20des=20finfos=20pour=20cr=C3=A9e?= =?UTF-8?q?r=20les=20home?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/serializers.py | 9 +++++++++ api/urls.py | 1 + api/views.py | 5 +++++ users/models.py | 5 +++++ 4 files changed, 20 insertions(+) diff --git a/api/serializers.py b/api/serializers.py index 9c0531ca..6cc020f3 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -552,6 +552,15 @@ class AdherentSerializer(NamespacedHMSerializer): 'shell': {'view_name': 'shell-detail'} } +class HomeCreationSerializer(NamespacedHMSerializer): + """Serialize 'users.models.User' minimal infos to create home + """ + uid = serializers.IntegerField(source='uid_number') + gid = serializers.IntegerField(source='gid_number') + + class Meta: + model = users.User + fields = ('pseudo', 'uid', 'gid') class ServiceUserSerializer(NamespacedHMSerializer): """Serialize `users.models.ServiceUser` objects. diff --git a/api/urls.py b/api/urls.py index 19757c1d..abc466e1 100644 --- a/api/urls.py +++ b/api/urls.py @@ -86,6 +86,7 @@ router.register_viewset(r'topologie/room', views.RoomViewSet) router.register(r'topologie/portprofile', views.PortProfileViewSet) # USERS router.register_viewset(r'users/user', views.UserViewSet) +router.register_viewset(r'users/homecreation', views.HomeCreationViewSet) 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 fae55d1e..0f6301bc 100644 --- a/api/views.py +++ b/api/views.py @@ -418,6 +418,11 @@ class UserViewSet(viewsets.ReadOnlyModelViewSet): queryset = users.User.objects.all() serializer_class = serializers.UserSerializer +class HomeCreationViewSet(viewsets.ReadOnlyModelViewSet): + """Exposes infos of `users.models.Users` objects to create homes. + """ + queryset = users.User.objects.all() + serializer_class = serializers.HomeCreationSerializer class ClubViewSet(viewsets.ReadOnlyModelViewSet): """Exposes list and details of `users.models.Club` objects. diff --git a/users/models.py b/users/models.py index 695a2053..d414af38 100755 --- a/users/models.py +++ b/users/models.py @@ -283,6 +283,11 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser, else: raise NotImplementedError("Type inconnu") + @cached_property + def gid_number(self): + """renvoie le gid par défaut des users""" + return int(LDAP['user_gid']) + @cached_property def is_class_club(self): """ Returns True if the object is a Club (subclassing User) """