From 63748168f22f6202e1323dbf8e325e0103f7cfff Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Sun, 5 Aug 2018 11:14:19 +0200 Subject: [PATCH 1/4] Export complet du prefix v6 --- api/serializers.py | 2 +- machines/models.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/api/serializers.py b/api/serializers.py index a4fa57bc..ba14dde5 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -673,7 +673,7 @@ class SubnetPortsOpenSerializer(serializers.ModelSerializer): class Meta: model = machines.IpType - fields = ('type', 'domaine_ip_start', 'domaine_ip_stop', 'prefix_v6', 'ouverture_ports') + fields = ('type', 'domaine_ip_start', 'domaine_ip_stop', 'complete_prefixv6', 'ouverture_ports') # DHCP diff --git a/machines/models.py b/machines/models.py index 2f5a6a62..007317e6 100644 --- a/machines/models.py +++ b/machines/models.py @@ -336,6 +336,11 @@ class IpType(RevMixin, AclMixin, models.Model): else: return None + @cached_property + def complete_prefixv6(self): + """Return the complete prefix v6 as cidr""" + return str(self.prefix_v6) + "/" + str(self.prefix_v6_length) + def ip_objects(self): """ Renvoie tous les objets ipv4 relié à ce type""" return IpList.objects.filter(ip_type=self) From cd7cf1cac45454abae2c869188e82de99badfdc0 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Sun, 5 Aug 2018 11:18:53 +0200 Subject: [PATCH 2/4] Affichage intelligent des ports ouverts dans la serialisation --- api/serializers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/serializers.py b/api/serializers.py index ba14dde5..05075606 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -656,7 +656,7 @@ class LocalEmailUsersSerializer(NamespacedHMSerializer): class FirewallPortListSerializer(serializers.ModelSerializer): class Meta: model = machines.OuverturePort - fields = ('begin', 'end', 'protocole', 'io') + fields = ('begin', 'end', 'protocole', 'io', 'show_port') class FirewallOuverturePortListSerializer(serializers.ModelSerializer): tcp_ports_in = FirewallPortListSerializer(many=True, read_only=True) From dc8cf8dbccaebe6d9da81c63e3669012a835cb44 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Sun, 5 Aug 2018 14:36:32 +0200 Subject: [PATCH 3/4] Serialisation des ouvertures de ports individuelles --- api/serializers.py | 9 +++++++++ api/urls.py | 1 + api/views.py | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/api/serializers.py b/api/serializers.py index 05075606..9c0531ca 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -675,6 +675,15 @@ class SubnetPortsOpenSerializer(serializers.ModelSerializer): model = machines.IpType fields = ('type', 'domaine_ip_start', 'domaine_ip_stop', 'complete_prefixv6', 'ouverture_ports') +class InterfacePortsOpenSerializer(serializers.ModelSerializer): + port_lists = FirewallOuverturePortListSerializer(read_only=True, many=True) + ipv4 = serializers.CharField(source='ipv4.ipv4', read_only=True) + ipv6 = Ipv6ListSerializer(many=True, read_only=True) + + class Meta: + model = machines.Interface + fields = ('port_lists', 'ipv4', 'ipv6') + # DHCP diff --git a/api/urls.py b/api/urls.py index 3bcaee0e..19757c1d 100644 --- a/api/urls.py +++ b/api/urls.py @@ -103,6 +103,7 @@ router.register_view(r'dhcp/hostmacip', views.HostMacIpView), router.register_view(r'localemail/users', views.LocalEmailUsersView), # Firewall router.register_view(r'firewall/subnet-ports', views.SubnetPortsOpenView), +router.register_view(r'firewall/interface-ports', views.InterfacePortsOpenView), # DNS router.register_view(r'dns/zones', views.DNSZonesView), router.register_view(r'dns/reverse-zones', views.DNSReverseZonesView), diff --git a/api/views.py b/api/views.py index f284abbe..fae55d1e 100644 --- a/api/views.py +++ b/api/views.py @@ -544,6 +544,10 @@ class SubnetPortsOpenView(generics.ListAPIView): queryset = machines.IpType.objects.all() serializer_class = serializers.SubnetPortsOpenSerializer +class InterfacePortsOpenView(generics.ListAPIView): + queryset = machines.Interface.objects.filter(port_lists__isnull=False).distinct() + serializer_class = serializers.InterfacePortsOpenSerializer + # DNS From 27d18e034b4740d66986a57cda20a75b95f68838 Mon Sep 17 00:00:00 2001 From: Arthur Grisel-Davy Date: Sun, 5 Aug 2018 17:22:12 +0200 Subject: [PATCH 4/4] =?UTF-8?q?serialization=20des=20finfos=20pour=20cr?= =?UTF-8?q?=C3=A9er=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) """