Skip to content

Commit

Permalink
fix(fixtures/django/14_prescribers.json): re-type accepted orgs typed…
Browse files Browse the repository at this point in the history
… Other

refactor(admin): authorization_status is a more reliable field

feat(PrescriberOrganization): CheckConstraint for restricting Other orgs validation

fix: invalidated tests

wording changes

wording change
  • Loading branch information
calummackervoy committed Sep 30, 2024
1 parent 8fc1719 commit 6ed7e17
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 91 deletions.
76 changes: 38 additions & 38 deletions itou/fixtures/django/14_prescribers.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "ML",
"name": "MISSION LOCALE - ARRAS",
"phone": "0311452459",
"post_code": "62005",
Expand Down Expand Up @@ -53,7 +53,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "ML",
"name": "MISSION LOCALE - BETHUNE",
"phone": "+33 5 71 65 67 13",
"post_code": "62400",
Expand Down Expand Up @@ -86,7 +86,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "ML",
"name": "MISSION LOCALE - BOULOGNE-SUR-MER",
"phone": "03 42 73 78 12",
"post_code": "62203",
Expand Down Expand Up @@ -119,7 +119,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "ML",
"name": "MISSION LOCALE - CALAIS",
"phone": "+33 (0)4 76 92 87 19",
"post_code": "62101",
Expand Down Expand Up @@ -152,7 +152,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "ML",
"name": "MISSION LOCALE - HENIN-BEAUMONT",
"phone": "0426751993",
"post_code": "62252",
Expand Down Expand Up @@ -185,7 +185,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "ML",
"name": "MISSION LOCALE - LIEVIN",
"phone": "+33 6 42 26 43 76",
"post_code": "62803",
Expand Down Expand Up @@ -218,7 +218,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "ML",
"name": "MISSION LOCALE - MONTREUIL",
"phone": "+33 (0)4 99 28 11 81",
"post_code": "62170",
Expand Down Expand Up @@ -251,7 +251,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "ML",
"name": "MISSION LOCALE - SAINT-OMER",
"phone": "0803709003",
"post_code": "62503",
Expand Down Expand Up @@ -284,7 +284,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "ML",
"name": "ADEFI",
"phone": "05 41 53 48 90",
"post_code": "62130",
Expand Down Expand Up @@ -317,7 +317,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "ML",
"name": "MISSION LOCALE - HAGUENAU",
"phone": "06 35 88 85 94",
"post_code": "67500",
Expand Down Expand Up @@ -350,7 +350,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "ML",
"name": "MISSION LOCALE - MOLSHEIM",
"phone": "0448777732",
"post_code": "67120",
Expand Down Expand Up @@ -383,7 +383,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "ML",
"name": "MISSION LOCALE - SAVERNE",
"phone": "+33 1 00 72 66 32",
"post_code": "67700",
Expand Down Expand Up @@ -416,7 +416,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "ML",
"name": "MISSION LOCALE - SCHILTIGHEIM",
"phone": "+33 1 22 93 83 85",
"post_code": "67300",
Expand Down Expand Up @@ -449,7 +449,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "ML",
"name": "MISSION LOCALE - SELESTAT",
"phone": "+33 (0)8 08 75 37 68",
"post_code": "67600",
Expand Down Expand Up @@ -482,7 +482,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "ML",
"name": "MISSION LOCALE - STRASBOURG",
"phone": "+33 8 01 92 82 29",
"post_code": "67000",
Expand Down Expand Up @@ -515,7 +515,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "ML",
"name": "MISSION LOCALE - AUBERVILLIERS",
"phone": "0698714866",
"post_code": "93300",
Expand Down Expand Up @@ -548,7 +548,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "ML",
"name": "MISSION LOCALE - AULNAY-SOUS-BOIS",
"phone": "0636387618",
"post_code": "93600",
Expand Down Expand Up @@ -581,7 +581,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "ML",
"name": "MISSION LOCALE - BOBIGNY",
"phone": "01 33 51 31 58",
"post_code": "93000",
Expand Down Expand Up @@ -614,7 +614,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "ML",
"name": "MISSION LOCALE - BONDY",
"phone": "0656754389",
"post_code": "93140",
Expand Down Expand Up @@ -647,7 +647,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "ML",
"name": "MISSION LOCALE - CLICHY-SOUS-BOIS",
"phone": "01 37 15 81 89",
"post_code": "93390",
Expand Down Expand Up @@ -680,7 +680,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "ML",
"name": "MISSION LOCALE - EPINAY-SUR-SEINE",
"phone": "01 15 77 19 46",
"post_code": "93800",
Expand Down Expand Up @@ -713,7 +713,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "ML",
"name": "MISSION LOCALE - LA COURNEUVE",
"phone": "0134219615",
"post_code": "93120",
Expand Down Expand Up @@ -746,7 +746,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "ML",
"name": "MISSION LOCALE - MONTREUIL",
"phone": "+33 6 28 68 52 55",
"post_code": "93100",
Expand Down Expand Up @@ -779,7 +779,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "ML",
"name": "MISSION LOCALE - NOISY-LE-GRAND",
"phone": "+33 (0)3 32 75 11 67",
"post_code": "93160",
Expand Down Expand Up @@ -812,7 +812,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "ML",
"name": "MISSION LOCALE - PANTIN",
"phone": "05 90 06 89 62",
"post_code": "93500",
Expand Down Expand Up @@ -845,7 +845,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "ML",
"name": "MISSION LOCALE - ROSNY-SOUS-BOIS",
"phone": "+33 (0)5 89 96 97 91",
"post_code": "93110",
Expand Down Expand Up @@ -878,7 +878,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "ML",
"name": "MISSION LOCALE - SAINT-DENIS",
"phone": "0216983908",
"post_code": "93200",
Expand Down Expand Up @@ -911,7 +911,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "ML",
"name": "MISSION LOCALE - SEVRAN",
"phone": "+33 4 65 98 67 47",
"post_code": "93270",
Expand Down Expand Up @@ -944,7 +944,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "ML",
"name": "MISSION LOCALE - VILLEMOMBLE",
"phone": "0586491420",
"post_code": "93250",
Expand Down Expand Up @@ -977,7 +977,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "PJJ",
"name": "DIRECTION TERRITORIALE DE LA PROTECTION JUDICIAIRE DE LA JEUNESSE - 67",
"phone": "08 04 60 54 63",
"post_code": "67081",
Expand Down Expand Up @@ -1010,7 +1010,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "PJJ",
"name": "DIRECTION TERRITORIALE DE LA PROTECTION JUDICIAIRE DE LA JEUNESSE - 62",
"phone": "08 04 06 75 34",
"post_code": "62000",
Expand Down Expand Up @@ -1043,7 +1043,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "PJJ",
"name": "DIRECTION TERRITORIALE DE LA PROTECTION JUDICIAIRE DE LA JEUNESSE - 93",
"phone": "+33 5 51 35 28 49",
"post_code": "93692",
Expand Down Expand Up @@ -1076,7 +1076,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "SPIP",
"name": "SERVICE PENITENTIAIRE D'INSERTION ET DE PROBATION - 67",
"phone": "0805057444",
"post_code": "68000",
Expand Down Expand Up @@ -1109,7 +1109,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "SPIP",
"name": "SERVICE PENITENTIAIRE D'INSERTION ET DE PROBATION - 62",
"phone": "+33 2 87 27 48 37",
"post_code": "62031",
Expand Down Expand Up @@ -1142,7 +1142,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "SPIP",
"name": "SERVICE PENITENTIAIRE D'INSERTION ET DE PROBATION - 93",
"phone": "+33 5 03 44 85 44",
"post_code": "93200",
Expand Down Expand Up @@ -1175,7 +1175,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "CAP_EMPLOI",
"name": "CAP EMPLOI - 62",
"phone": "+33 5 43 78 27 45",
"post_code": "62000",
Expand Down Expand Up @@ -1208,7 +1208,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "CAP_EMPLOI",
"name": "CAP EMPLOI - 93",
"phone": "02 77 30 09 63",
"post_code": "93600",
Expand Down Expand Up @@ -1241,7 +1241,7 @@
"is_authorized": true,
"is_brsa": false,
"is_head_office": false,
"kind": "Autre",
"kind": "CAP_EMPLOI",
"name": "CAP EMPLOI - 67",
"phone": "+33 (0)1 68 93 60 86",
"post_code": "68000",
Expand Down
2 changes: 1 addition & 1 deletion itou/prescribers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def response_change(self, request, obj):
if request.user.is_superuser or obj.has_pending_authorization() or obj.has_refused_authorization():
# Organizations typed as "Other" cannot be marked valid
if obj.kind == PrescriberOrganizationKind.OTHER:
msg = "Pour habiliter cette organisation, vous devez sélectionner un type différent de “Autre”"
msg = "Pour habiliter cette organisation, vous devez sélectionner un type différent de “Autre”."
self.message_user(request, msg, messages.ERROR)
return HttpResponseRedirect(request.get_full_path())
obj.is_authorized = True
Expand Down
9 changes: 4 additions & 5 deletions itou/prescribers/admin_forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django import forms

from itou.prescribers.enums import PrescriberOrganizationKind
from itou.prescribers.enums import PrescriberAuthorizationStatus, PrescriberOrganizationKind
from itou.prescribers.models import PrescriberOrganization


Expand All @@ -23,10 +23,9 @@ def clean(self):
cleaned_data = super().clean()
if (
cleaned_data.get("kind") == PrescriberOrganizationKind.OTHER
and self.instance.is_authorized
# TODO(calummackervoy): included to permit cleaning existing rows. We can later remove this
and self.instance.kind != PrescriberOrganizationKind.OTHER
and self.instance.authorization_status == PrescriberAuthorizationStatus.VALIDATED
):
raise forms.ValidationError(
"Cette organisation a été habilitée. Vous devez sélectionner un type différent de “Autre”"
"Cette organisation a été habilitée. Vous devez sélectionner un type différent de “Autre”."
)
return cleaned_data
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 5.0.9 on 2024-09-26 09:53

from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("cities", "0001_initial"),
("prescribers", "0005_alter_prescribermembership_updated_by_and_more"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.AddConstraint(
model_name="prescriberorganization",
constraint=models.CheckConstraint(
check=models.Q(("authorization_status", "VALIDATED"), ("kind", "Autre"), _negated=True),
name="prevent_validated_authorization_if_other",
violation_error_message='Une organisation habilitée ne peut pas être de type "Autre".',
),
),
]
Loading

0 comments on commit 6ed7e17

Please sign in to comment.