aboutsummaryrefslogtreecommitdiffstats
path: root/ctrack
diff options
context:
space:
mode:
authorMatthew Lemon <matt@matthewlemon.com>2020-10-18 16:33:07 +0100
committerMatthew Lemon <matt@matthewlemon.com>2020-10-18 16:33:07 +0100
commitdbc2cf0662323abadd08b0d7eb6746905466017d (patch)
tree0161f6a0d23e145806086b3ad964d9f0416582a9 /ctrack
parentd6a3d976e0a7bd2bde93a5ea5543e9e68922520d (diff)
basic inclusion of single datetime events in org detail page - no formatting and passing tests
Diffstat (limited to '')
-rw-r--r--ctrack/organisations/models.py29
-rw-r--r--ctrack/organisations/templates/organisations/organisation_detail.html8
-rw-r--r--ctrack/organisations/tests/test_models.py9
-rw-r--r--ctrack/organisations/tests/test_views.py32
-rw-r--r--ctrack/organisations/views.py6
-rw-r--r--ctrack/register/tests/test_views.py2
6 files changed, 73 insertions, 13 deletions
diff --git a/ctrack/organisations/models.py b/ctrack/organisations/models.py
index c7394e4..9baf672 100644
--- a/ctrack/organisations/models.py
+++ b/ctrack/organisations/models.py
@@ -93,6 +93,10 @@ class Person(models.Model):
def get_full_name(self):
return " ".join([self.first_name, self.last_name])
+ def get_single_datetime_events(self):
+ from ctrack.register.models import SingleDateTimeEvent
+ return SingleDateTimeEvent.objects.filter(participants__id=self.pk)
+
class Meta:
verbose_name_plural = "People"
@@ -136,8 +140,20 @@ class Organisation(models.Model):
designation_type = models.IntegerField(choices=DESIGNATION_TYPE, default=1)
registered_company_name = models.CharField(max_length=255, blank=True)
registered_company_number = models.CharField(max_length=100, blank=True)
- lead_inspector = models.ForeignKey("users.User", blank=False, null=True, on_delete=models.SET(get_sentinel_user), related_name="lead_inspector")
- deputy_lead_inspector = models.ForeignKey("users.User", blank=False, null=True, on_delete=models.SET(get_sentinel_user), related_name="deputy_inspector")
+ lead_inspector = models.ForeignKey(
+ "users.User",
+ blank=False,
+ null=True,
+ on_delete=models.SET(get_sentinel_user),
+ related_name="lead_inspector",
+ )
+ deputy_lead_inspector = models.ForeignKey(
+ "users.User",
+ blank=False,
+ null=True,
+ on_delete=models.SET(get_sentinel_user),
+ related_name="deputy_inspector",
+ )
date_updated = models.DateField(auto_now=True)
# updated_by = models.ForeignKey(
# get_user_model(), on_delete=models.SET(get_sentinel_user)
@@ -260,7 +276,8 @@ class IncidentReport(models.Model):
email = models.EmailField(blank=False)
internal_incident_number = models.CharField(max_length=30, blank=True)
date_time_incident_detected = models.DateTimeField(
- verbose_name="Date/Time incident detected", auto_now=False,
+ verbose_name="Date/Time incident detected",
+ auto_now=False,
)
date_time_incident_reported = models.DateTimeField(
verbose_name="Date/Time incident reported", auto_now=True
@@ -272,17 +289,17 @@ class IncidentReport(models.Model):
incident_stage = models.CharField(choices=INCIDENT_STAGE, max_length=20)
summary = models.TextField(
help_text="Please provide a summary of your understanding of the incident, including"
- " any impact to services and/or users."
+ " any impact to services and/or users."
)
mitigations = models.TextField(
verbose_name="Investigations or mitigations",
help_text="What investigations and/or mitigations have you or a third"
- " party performed or plan to perform?",
+ " party performed or plan to perform?",
)
others_informed = models.TextField(
verbose_name="Others parties informed",
help_text="Who else has been informed about this incident?"
- "(CSIRT, NCSC, NCA, etc)",
+ "(CSIRT, NCSC, NCA, etc)",
)
next_steps = models.TextField(
verbose_name="Planned next steps", help_text="What are your planned next steps?"
diff --git a/ctrack/organisations/templates/organisations/organisation_detail.html b/ctrack/organisations/templates/organisations/organisation_detail.html
index 5a510ee..d6f99a8 100644
--- a/ctrack/organisations/templates/organisations/organisation_detail.html
+++ b/ctrack/organisations/templates/organisations/organisation_detail.html
@@ -263,9 +263,15 @@
d="M5 10.5a.5.5 0 0 1 .5-.5h2a.5.5 0 0 1 0 1h-2a.5.5 0 0 1-.5-.5zm0-2a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5zm0-2a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5zm0-2a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5z"/>
</svg>
<a href="{% url "register:event_create_simple_event_from_org_with_type" object.slug 'NOTE' %}">New note</a>
-
</div>
+ <div>
+ {% for event in single_datetime_events %}
+ {{ event }} {{ event.short_description }}
+ {% endfor %}
+
+ </div>
+
<div class="table table-responsive">
<table class="table table-sm table-striped table-bordered">
<thead>
diff --git a/ctrack/organisations/tests/test_models.py b/ctrack/organisations/tests/test_models.py
index e4caeb5..141f518 100644
--- a/ctrack/organisations/tests/test_models.py
+++ b/ctrack/organisations/tests/test_models.py
@@ -7,7 +7,7 @@ from ctrack.caf.models import CAF, Grading
from ctrack.caf.models import EssentialService
from ctrack.caf.tests.factories import ApplicableSystemFactory
from ctrack.core.utils import fnames
-from ctrack.organisations.tests.factories import PersonFactory
+from ctrack.organisations.tests.factories import PersonFactory, SingleDateTimeEventFactory
pytestmark = pytest.mark.django_db
@@ -28,6 +28,13 @@ def test_organisation_get_absolute_url(org):
assert org.get_absolute_url() == f"/organisations/{slug}/"
+def test_can_get_all_single_datetime_events_involving_person(person):
+ e = SingleDateTimeEventFactory.create(type_descriptor="MEETING", short_description="No desc")
+ e.participants.add(person)
+ events_involving_person = person.get_single_datetime_events()
+ assert events_involving_person.first().short_description == "No desc"
+
+
def test_update_organisation(org_with_people):
# Change the name of the organisation
org_with_people.name = "Tonkers Ltd"
diff --git a/ctrack/organisations/tests/test_views.py b/ctrack/organisations/tests/test_views.py
index 6ae9ff8..dbd717f 100644
--- a/ctrack/organisations/tests/test_views.py
+++ b/ctrack/organisations/tests/test_views.py
@@ -5,7 +5,10 @@ from django.test import RequestFactory
from django.urls import reverse
from ctrack.caf.tests.factories import PersonFactory
-from ctrack.organisations.tests.factories import OrganisationFactory
+from ctrack.organisations.tests.factories import (
+ OrganisationFactory,
+ SingleDateTimeEventFactory,
+)
from ctrack.organisations.views import IncidentReportCreateView
from ..views import OrganisationListView
@@ -13,9 +16,30 @@ from ..views import OrganisationListView
pytestmark = pytest.mark.django_db
-# TODO - come back to this
-def test_meetings_in_organisation_detail_view(user, client):
- pass
+def test_meetings_in_organisation_detail_view(user, client, org_with_people):
+ org_list_permission = Permission.objects.get(name="Can view organisation")
+ assert user.user_permissions.count() == 0
+ user.user_permissions.add(org_list_permission)
+ assert user.has_perm("organisations.view_organisation")
+ user.save()
+ person = org_with_people.person_set.first()
+ e1 = SingleDateTimeEventFactory.create(
+ type_descriptor="MEETING", short_description="First Meeting"
+ )
+ e2 = SingleDateTimeEventFactory.create(
+ type_descriptor="MEETING", short_description="Second Meeting"
+ )
+ e1.participants.add(person)
+ e1.save()
+ e2.participants.add(person)
+ e2.save()
+ client.force_login(user)
+ response = client.get(
+ reverse("organisations:detail", kwargs={"slug": org_with_people.slug})
+ )
+ assert response.status_code == 200
+ html = response.content.decode("utf-8")
+ assert "First Meeting" in html
# https://docs.djangoproject.com/en/3.0/topics/testing/advanced/#example
diff --git a/ctrack/organisations/views.py b/ctrack/organisations/views.py
index adb3b81..ea6aa14 100644
--- a/ctrack/organisations/views.py
+++ b/ctrack/organisations/views.py
@@ -1,3 +1,4 @@
+import itertools
from typing import Any
from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
@@ -85,6 +86,10 @@ class OrganisationDetailView(PermissionRequiredMixin, DetailView):
peoples = org.person_set.all()
cafs = org.caf_set.all()
+ # simple datetime events for org
+ _sdes = [person.get_single_datetime_events() for person in peoples]
+ flat_sdes = list(itertools.chain.from_iterable(_sdes))
+
# Some events will not involve a participant, which is what ties an event to an organisation.
# Because we want to list events to an organisation here we must related it via the CAF object too...
engagement_events = EngagementEvent.objects.filter(Q(participants__in=peoples) | Q(related_caf__in=cafs)).order_by("-date")
@@ -106,6 +111,7 @@ class OrganisationDetailView(PermissionRequiredMixin, DetailView):
context["engagement_events"] = engagement_events
context["essential_services"] = essential_services
context["cafs"] = cafs
+ context["single_datetime_events"] = flat_sdes
return context
diff --git a/ctrack/register/tests/test_views.py b/ctrack/register/tests/test_views.py
index 306cec5..30cc0d5 100644
--- a/ctrack/register/tests/test_views.py
+++ b/ctrack/register/tests/test_views.py
@@ -122,7 +122,7 @@ class TestSingleDateTimeEvent:
response = client.get(url)
html = response.content.decode("utf-8")
assert response.status_code == 200
- test_case.assertInHTML(f"Create a new simple event involving {org.name}", html)
+ test_case.assertInHTML("Create a new simple event involving {org.name}", html)
def test_org_passed_as_kwarg(self, user, org, request_factory):
slug = org.slug