# HG changeset patch # User Branko Majic # Date 2013-07-14 22:26:05 # Node ID 87d2821ecdfd93eb08f7e873f4fee71b54650293 # Parent 5c7da7c67a3edf4521f36224b262a804a7bff437 CONNT-9: Reworked the entity details view to be more consistent with the other views. Move implicit queries from template to view. diff --git a/conntrackt/templates/conntrackt/entity_detail.html b/conntrackt/templates/conntrackt/entity_detail.html --- a/conntrackt/templates/conntrackt/entity_detail.html +++ b/conntrackt/templates/conntrackt/entity_detail.html @@ -4,8 +4,6 @@ {% load conntrackt_tags %} {% block content %} -{# Use a bit shorter variable names. #} -{% with project=entity.project location=entity.location %} {% if entity %}
@@ -20,27 +18,88 @@

{% endif %} +
{% html_link "Edit" "entity_update" entity.id class="btn btn-primary" %} {% html_link "Remove" "entity_delete" entity.id class="btn btn-primary" %} + {% html_link "Get Iptables" 'entity_iptables' entity.id class="btn btn-primary" %} +
+
+ +
+ +
+ +
+
+ + + + + + + + + + +
General information
Project{% html_link project.name 'project' project.id %}
Location{{location}}
+
+
+ +
+
+ + + + + + {% for interface in interfaces %} + + {% endfor %} + +
Interfaces
{{interface.name}} ({{interface.address}}/{{interface.netmask}})
+
-
-
-
Project
{% html_link project.name 'project' project.id %}
-
Location
{{location.name}}
-
Incoming communications
    {% for interface in entity.interface_set.all %} - {% for communication in interface.destination_set.all %} -
  • {{communication.source}} - {{communication.protocol}}: {{communication.port}}
  • - {% endfor %}{% endfor %}
-
Outgoing communications
    {% for interface in entity.interface_set.all %} - {% for communication in interface.source_set.all %} -
  • {{communication.destination}} - {{communication.protocol}}: {{communication.port}}
  • -{% endfor %}{% endfor %}
-
iptables rules
{{ entity_iptables }}
{% html_link 'Download' 'entity_iptables' entity.id class="btn btn-primary input-small" %}
-
+ +
+
+
+ + + + + {% for comm in incoming_communications %} + + {% endfor %} +
Incoming communications
{{comm.source}} - {{comm.protocol}}: {{comm.port}}
+
+
+ +
+
+ + + + + {% for comm in outgoing_communications %} + + {% endfor %} + + +
Outgoing communications
{{comm.destination}} - {{comm.protocol}}: {{comm.port}}
+
+
+ +
+
+

Iptables rules

+
{{ entity_iptables }}
+
+
+ +
{% endif %} -{% endwith %} {% endblock %} diff --git a/conntrackt/tests/test_views.py b/conntrackt/tests/test_views.py --- a/conntrackt/tests/test_views.py +++ b/conntrackt/tests/test_views.py @@ -157,7 +157,7 @@ class ProjectViewTest(ViewTest): self.assertContains(response, "Test Location 2") -class EntityView(ViewTest): +class EntityViewTest(ViewTest): def test_permission_denied(self): """ @@ -190,6 +190,19 @@ class EntityView(ViewTest): response = self.client.get(reverse("entity", args=(1,))) + expected_incoming_communications = [" Test Entity 1 (TCP:22)>", + " Test Entity 1 (ICMP:8)>", + " Test Entity 1 (TCP:3306)>", + " Test Entity 1 (TCP:22)>",] + + expected_outgoing_communications = [" Test Entity 2 (UDP:123)>", + " Test Entity 3 (UDP:53)>"] + + expected_interfaces = [""] + + self.assertQuerysetEqual(response.context["interfaces"], expected_interfaces) + self.assertQuerysetEqual(response.context["incoming_communications"], expected_incoming_communications) + self.assertQuerysetEqual(response.context["outgoing_communications"], expected_outgoing_communications) self.assertEqual(str(response.context["entity"]), "Test Entity 1 (Test Project 1 - Test Location 1)") self.assertContains(response, "Test Entity 1") self.assertContains(response, ":INPUT") diff --git a/conntrackt/views.py b/conntrackt/views.py --- a/conntrackt/views.py +++ b/conntrackt/views.py @@ -131,6 +131,17 @@ class EntityView(MultiplePermissionsRequ # Add the rendered iptables rules to the context. context['entity_iptables'] = generate_entity_iptables(self.object) + # Add the incoming and outgoing commmunication to the context. + context["incoming_communications"] = self.object.incoming_communications() + context["outgoing_communications"] = self.object.outgoing_communications() + + # Add the interfaces to the context. + context["interfaces"] = self.object.interface_set.all().order_by("name") + + # Add project/location to the context. + context["project"] = self.object.project + context["location"] = self.object.location + return context