Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppression du modèle DPO et ses références dans le code #599

Merged
merged 1 commit into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions aidants_connect_habilitation/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ class OrganisationRequestAdmin(VisibleToAdminMetier, ReverseModelAdmin):
MessageInline,
)
inline_type = "stacked"
inline_reverse = (
"manager",
"data_privacy_officer",
)
inline_reverse = ("manager",)


if settings.AC_HABILITATION_FORM_ENABLED:
Expand Down
33 changes: 7 additions & 26 deletions aidants_connect_habilitation/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from aidants_connect_habilitation import models
from aidants_connect_habilitation.models import (
AidantRequest,
DataPrivacyOfficer,
Manager,
OrganisationRequest,
PersonWithResponsibilities,
Expand Down Expand Up @@ -237,11 +236,6 @@ class Meta(PersonWithResponsibilitiesForm.Meta):
model = Manager


class DataPrivacyOfficerForm(PersonWithResponsibilitiesForm):
class Meta(PersonWithResponsibilitiesForm.Meta):
model = DataPrivacyOfficer


class AidantRequestForm(PatchedErrorListForm):
class Meta:
model = AidantRequest
Expand Down Expand Up @@ -276,16 +270,12 @@ def management_form_widget_attrs(self, widget_name: str, attrs: dict):

class PersonnelForm:
MANAGER_FORM_PREFIX = "manager"
DPO_FORM_PREFIX = "dpo"
AIDANTS_FORMSET_PREFIX = "aidants"

@property
def non_field_errors(self):
errors = self.manager_form.non_field_errors().copy()

for error in self.data_privacy_officer_form.non_field_errors():
errors.append(error)

for error in self.aidants_formset.non_form_errors():
errors.append(error)

Expand All @@ -298,16 +288,15 @@ def merge_kwargs(prefix):

form_kwargs_prefixes = {
self.MANAGER_FORM_PREFIX,
self.DPO_FORM_PREFIX,
self.AIDANTS_FORMSET_PREFIX,
}

for k, v in kwargs.items():
"""
Let us dispatch form kwargs to specific forms by using their prefixes.

For instance, PersonnelForm(dpo_instance=some_instance) will
disptach to DataPrivacyOfficerForm(instance=some_instance).
For instance, PersonnelForm(manager_instance=some_instance) will
disptach to ManagerForm(instance=some_instance).
"""
kwarg_prefix = k.split("_")
if len(kwarg_prefix) > 1 and kwarg_prefix[0] in form_kwargs_prefixes:
Expand All @@ -325,9 +314,7 @@ def merge_kwargs(prefix):
}

self.manager_form = ManagerForm(**merge_kwargs(self.MANAGER_FORM_PREFIX))
self.data_privacy_officer_form = DataPrivacyOfficerForm(
**merge_kwargs(self.DPO_FORM_PREFIX)
)

self.aidants_formset = AidantRequestFormSet(
**merge_kwargs(self.AIDANTS_FORMSET_PREFIX)
)
Expand All @@ -340,29 +327,23 @@ def merge_kwargs(prefix):
)

def is_valid(self):
return (
self.manager_form.is_valid()
and self.data_privacy_officer_form.is_valid()
and self.aidants_formset.is_valid()
)
return self.manager_form.is_valid() and self.aidants_formset.is_valid()

def save(
self, organisation: OrganisationRequest, commit=True
) -> Tuple[Manager, DataPrivacyOfficer, List[AidantRequest]]:
) -> Tuple[Manager, List[AidantRequest]]:
for form in self.aidants_formset:
form.instance.organisation = organisation

manager_instance, dpo_instance, aidants_instances = (
manager_instance, aidants_instances = (
self.manager_form.save(commit),
self.data_privacy_officer_form.save(commit),
self.aidants_formset.save(commit),
)

organisation.manager = manager_instance
organisation.data_privacy_officer = dpo_instance
organisation.save()

return manager_instance, dpo_instance, aidants_instances
return manager_instance, aidants_instances

save.alters_data = True

Expand Down
22 changes: 22 additions & 0 deletions aidants_connect_habilitation/migrations/0015_remove_dpo_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('aidants_connect_habilitation', '0014_auto_20220324_1713'),
]

operations = [
migrations.RemoveConstraint(
model_name='organisationrequest',
name='data_privacy_officer_set',
),
migrations.RemoveField(
model_name='organisationrequest',
name='data_privacy_officer',
),
migrations.DeleteModel(
name='DataPrivacyOfficer',
),
]
24 changes: 0 additions & 24 deletions aidants_connect_habilitation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"PersonWithResponsibilities",
"Issuer",
"IssuerEmailConfirmation",
"DataPrivacyOfficer",
"Manager",
"OrganisationRequest",
"AidantRequest",
Expand Down Expand Up @@ -149,12 +148,6 @@ def send(self, request: HttpRequest):
email_confirmation_sent.send(self.__class__, request=request, confirmation=self)


class DataPrivacyOfficer(PersonWithResponsibilities):
class Meta:
verbose_name = "DPO"
verbose_name_plural = "DPOs"


class Manager(PersonWithResponsibilities):
address = models.TextField("Adresse")
zipcode = models.CharField("Code Postal", max_length=10)
Expand Down Expand Up @@ -184,15 +177,6 @@ class OrganisationRequest(models.Model):
null=True,
)

data_privacy_officer = models.OneToOneField(
DataPrivacyOfficer,
on_delete=models.CASCADE,
related_name="organisation",
verbose_name="Délégué à la protection des données",
default=None,
null=True,
)

uuid = models.UUIDField(
"Identifiant de brouillon",
default=_new_uuid,
Expand Down Expand Up @@ -354,14 +338,6 @@ class Meta:
),
name="manager_set",
),
models.CheckConstraint(
check=Q(status=RequestStatusConstants.NEW.name)
| (
~Q(status=RequestStatusConstants.NEW.name)
& Q(data_privacy_officer__isnull=False)
),
name="data_privacy_officer_set",
),
]
verbose_name = "Demande d’habilitation"
verbose_name_plural = "Demandes d’habilitation"
Expand Down
13 changes: 2 additions & 11 deletions aidants_connect_habilitation/static/js/personnel_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,13 @@
this.mutateAddAidantButtonVisibility();
},

"onItsMeBtnClicked": function onItsMeBtnClicked(target) {
"onManagerItsMeBtnClicked": function onManagerItsMeBtnClicked() {
const self = this;
Object.keys(this.issuerDataValue).forEach(function (key) {
target.querySelector("[name$='" + key + "']").value = self.issuerDataValue[key];
self.managerSubformTarget.querySelector("[name$='" + key + "']").value = self.issuerDataValue[key];
});
},

"onManagerItsMeBtnClicked": function onManagerItsMeBtnClicked() {
this.onItsMeBtnClicked(this.managerSubformTarget);
},

"onDpoItsMeBtnClicked": function onDpoItsMeBtnClicked() {
this.onItsMeBtnClicked(this.dpoSubformTarget);
},

"mutateAddAidantButtonVisibility": function mutateAddAidantButtonVisibility() {
if (this.formCountValue >= this.formMaxCountValue) {
this.addAidantButtonContainerTarget.setAttribute("hidden", "hidden");
Expand All @@ -65,7 +57,6 @@
"aidantFormTemplate",
"aidantFormset",
"managerSubform",
"dpoSubform",
];

PersonnelForm.values = {
Expand Down
26 changes: 0 additions & 26 deletions aidants_connect_habilitation/templates/personnel_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,32 +99,6 @@ <h5 class="h3">Contact</h5>
</fieldset>
</section>
</div>
<div class="fr-col-12 fr-col-md-6 fr-col-lg-4">
<section class="shadowed">
<h4 class="h2">Délégué à la protection des données <span class="text-red">— Facultatif</span></h4>
<fieldset
id="dpo-subform"
data-personnel-form-target="dpoSubform"
>
<legend class="sr-only">Délégué à la protection des données - facultatif</legend>
<button
id="its-me-dpo"
class="primary"
type="button"
data-action="personnel-form#onDpoItsMeBtnClicked"
>
<span aria-hidden="true">👋 </span>C’est moi ! Remplir avec mes infos
</button>
<h5 class="h3">Identité</h5>
{% field_as_narrow_fr_grid_row form.data_privacy_officer_form.last_name %}
{% field_as_narrow_fr_grid_row form.data_privacy_officer_form.first_name %}
{% field_as_narrow_fr_grid_row form.data_privacy_officer_form.profession %}
<h5 class="h3">Contact</h5>
{% field_as_narrow_fr_grid_row form.data_privacy_officer_form.phone %}
{% field_as_narrow_fr_grid_row form.data_privacy_officer_form.email %}
</fieldset>
</section>
</div>
</div>


Expand Down
24 changes: 1 addition & 23 deletions aidants_connect_habilitation/templates/validation_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ <h3>Autres informations</h3>
{# Infos générales #}
<h3>Personnes impliquées</h3>
<div class="form-in-3-cols">
{# first row: responsable + dpo #}
{# first row: responsable #}
<div class="fr-grid-row fr-grid-row--gutters">
<div class="fr-col-12 fr-col-md-6 fr-col-lg-4">
<div class="shadowed with-button-box">
Expand All @@ -109,28 +109,6 @@ <h4 class="h2">Responsable de structure</h4>
</div>
</div>
</div>
{% if organisation.data_privacy_officer %}
<div class="fr-col-12 fr-col-md-6 fr-col-lg-4">
<div class="shadowed with-button-box">
<h4 class="h2">Délégué à la protection des données</h4>
<div>
<p>
<strong>{{ organisation.data_privacy_officer.get_full_name }}</strong><br>
{{ organisation.data_privacy_officer.profession }}
</p>
<p>
{{ organisation.data_privacy_officer.email }}<br>{{ organisation.data_privacy_officer.phone }}
</p>
</div>
<div class="button-box">
<a class="button primary"
href="{% url 'habilitation_new_aidants' issuer_id=issuer.issuer_id uuid=organisation.uuid %}">
Éditer
</a>
</div>
</div>
</div>
{% endif %}
</div>
{# 2nd row and more: aidants #}
<div class="fr-grid-row fr-grid-row--gutters">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ <h3>Autres informations</h3>
{# Infos générales #}
<h3>Personnes impliquées</h3>
<div class="form-in-3-cols">
{# first row: responsable + dpo #}
{# first row: responsable #}
<div class="fr-grid-row fr-grid-row--gutters">
<div class="fr-col-12 fr-col-md-6 fr-col-lg-4">
<div class="shadowed with-button-box">
Expand All @@ -93,22 +93,6 @@ <h4 class="h2">Responsable de structure</h4>
</div>
</div>
</div>
{% if organisation.data_privacy_officer %}
<div class="fr-col-12 fr-col-md-6 fr-col-lg-4">
<div class="shadowed with-button-box">
<h4 class="h2">Délégué à la protection des données</h4>
<div>
<p>
<strong>{{ organisation.data_privacy_officer.get_full_name }}</strong><br>
{{ organisation.data_privacy_officer.profession }}
</p>
<p>
{{ organisation.data_privacy_officer.email }}<br>{{ organisation.data_privacy_officer.phone }}
</p>
</div>
</div>
</div>
{% endif %}
</div>
{# 2nd row and more: aidants #}
<div class="fr-grid-row fr-grid-row--gutters">
Expand Down
14 changes: 0 additions & 14 deletions aidants_connect_habilitation/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
)
from aidants_connect_habilitation.models import (
AidantRequest,
DataPrivacyOfficer,
Issuer,
Manager,
OrganisationRequest,
Expand Down Expand Up @@ -53,17 +52,6 @@ class Meta:
model = Issuer


class DataPrivacyOfficerFactory(DjangoModelFactory):
first_name = FactoryFaker("first_name")
last_name = FactoryFaker("last_name")
email = FactoryFaker("email")
profession = FactoryFaker("job")
phone = LazyFunction(_generate_valid_phone)

class Meta:
model = DataPrivacyOfficer


class ManagerFactory(DjangoModelFactory):
first_name = FactoryFaker("first_name")
last_name = FactoryFaker("last_name")
Expand All @@ -84,7 +72,6 @@ class Meta:
class OrganisationRequestFactory(DjangoModelFactory):
issuer = SubFactory(IssuerFactory)
manager = SubFactory(ManagerFactory)
data_privacy_officer = SubFactory(DataPrivacyOfficerFactory)

uuid = LazyFunction(uuid4)

Expand Down Expand Up @@ -130,7 +117,6 @@ class Meta:

class DraftOrganisationRequestFactory(OrganisationRequestFactory):
manager = None
data_privacy_officer = None

status = RequestStatusConstants.NEW.name

Expand Down
Loading