diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-05-31 16:32:49 +0100 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-05-31 16:32:49 +0100 |
commit | 656ceb510d535d0592cda7cc92bbe0e43561ea0c (patch) | |
tree | 4040be410d5c8b758ad96cf6aefe0dd2586d9aa6 | |
parent | 5c8c748c50ac4f6603fccf03c5e8473c47638cf6 (diff) |
added sentinel user
-rw-r--r-- | ctrack/core/views.py | 2 | ||||
-rw-r--r-- | ctrack/organisations/migrations/0011_auto_20200531_1441.py | 19 | ||||
-rw-r--r-- | ctrack/organisations/models.py | 10 | ||||
-rw-r--r-- | ctrack/organisations/tests/test_models.py | 8 |
4 files changed, 29 insertions, 10 deletions
diff --git a/ctrack/core/views.py b/ctrack/core/views.py index 4584612..c9465f1 100644 --- a/ctrack/core/views.py +++ b/ctrack/core/views.py @@ -10,7 +10,7 @@ def home_page(request): org = Organisation.objects.get( name=request.user.stakeholder.person.get_organisation_name() ) - irs = IncidentReport.objects.filter(organisation=org) + irs = IncidentReport.objects.filter(organisation__name=org) systems = org.applicablesystem_set.all() return render( request, diff --git a/ctrack/organisations/migrations/0011_auto_20200531_1441.py b/ctrack/organisations/migrations/0011_auto_20200531_1441.py new file mode 100644 index 0000000..3dced7d --- /dev/null +++ b/ctrack/organisations/migrations/0011_auto_20200531_1441.py @@ -0,0 +1,19 @@ +# Generated by Django 2.2.12 on 2020-05-31 14:41 + +import django.contrib.auth +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('organisations', '0010_auto_20200529_1602'), + ] + + operations = [ + migrations.AlterField( + model_name='incidentreport', + name='reporting_person', + field=models.ForeignKey(on_delete=models.SET(django.contrib.auth.get_user_model), to='organisations.Person', verbose_name='Person reporting the incident'), + ), + ] diff --git a/ctrack/organisations/models.py b/ctrack/organisations/models.py index 75b28df..4a0b17c 100644 --- a/ctrack/organisations/models.py +++ b/ctrack/organisations/models.py @@ -184,6 +184,14 @@ class Stakeholder(models.Model): class IncidentReport(models.Model): + def get_sentinel_user(): # type: ignore + """ + We need this so that we can ensure models.SET() is applied with a callable + to handle when Users are deleted from the system, preventing the Person objects + related to them being deleted also. + """ + return get_user_model().objects.get_or_create(username="DELETED USER")[0] + DFT_HANDLE_STATUS = ( ("QUEUED", "QUEUED"), ("REVIEWING", "REVIEWING"), @@ -212,7 +220,7 @@ class IncidentReport(models.Model): reporting_person = models.ForeignKey( Person, blank=False, - on_delete=models.CASCADE, + on_delete=models.SET(get_user_model), verbose_name="Person " "reporting the incident", ) person_involved = models.CharField( diff --git a/ctrack/organisations/tests/test_models.py b/ctrack/organisations/tests/test_models.py index 6f79cb4..c6314af 100644 --- a/ctrack/organisations/tests/test_models.py +++ b/ctrack/organisations/tests/test_models.py @@ -11,14 +11,6 @@ def test_organisation_get_absolute_url(org): assert org.get_absolute_url() == f"/organisations/{slug}/" -def test_delete_organisation(org_with_people): - orgs = Organisation.objects.all() - assert org_with_people in orgs - Organisation.delete(org_with_people) - # Assert that the record has been deleted - assert Organisation.objects.count() == 0 - - def test_update_organisation(org_with_people): # Change the name of the organisation org_with_people.name = "Tonkers Ltd" |