diff options
| author | polo <ordipolo@gmx.fr> | 2025-12-23 18:02:00 +0100 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2025-12-23 18:02:00 +0100 |
| commit | 79409bed093890d38cb2c60f8b6af079854cf8d2 (patch) | |
| tree | d30799c43d1566552f000e80d3ee52c3af0806ed | |
| parent | 774437d3196878388e294a3833a73e900000b5e4 (diff) | |
| download | cms-79409bed093890d38cb2c60f8b6af079854cf8d2.tar.gz cms-79409bed093890d38cb2c60f8b6af079854cf8d2.tar.bz2 cms-79409bed093890d38cb2c60f8b6af079854cf8d2.zip | |
choix durée stockage emails sensibles configurables aussi, bug durée emails sensibles
| -rw-r--r-- | public/js/form.js | 5 | ||||
| -rw-r--r-- | src/controller/ContactFormController.php | 2 | ||||
| -rw-r--r-- | src/model/entities/Email.php | 20 | ||||
| -rw-r--r-- | src/view/FormBuilder.php | 8 | ||||
| -rw-r--r-- | src/view/templates/form_admin.php | 9 |
5 files changed, 26 insertions, 18 deletions
diff --git a/public/js/form.js b/public/js/form.js index d8849c8..003cac4 100644 --- a/public/js/form.js +++ b/public/js/form.js | |||
| @@ -58,8 +58,8 @@ function keepEmails(block_id){ | |||
| 58 | console.error('Erreur:', error); | 58 | console.error('Erreur:', error); |
| 59 | }); | 59 | }); |
| 60 | } | 60 | } |
| 61 | function setEmailsRetentionPeriod(block_id){ | 61 | function setEmailsRetentionPeriod(block_id, field_name){ |
| 62 | const form = document.getElementById('retention_period_' + block_id); | 62 | const form = document.getElementById(field_name + '_' + block_id); |
| 63 | if(!form){ | 63 | if(!form){ |
| 64 | return; | 64 | return; |
| 65 | } | 65 | } |
| @@ -71,6 +71,7 @@ function setEmailsRetentionPeriod(block_id){ | |||
| 71 | }, | 71 | }, |
| 72 | body: JSON.stringify({ | 72 | body: JSON.stringify({ |
| 73 | id: block_id, | 73 | id: block_id, |
| 74 | field: field_name, | ||
| 74 | months: form.value | 75 | months: form.value |
| 75 | }) | 76 | }) |
| 76 | }) | 77 | }) |
diff --git a/src/controller/ContactFormController.php b/src/controller/ContactFormController.php index 0724401..468b732 100644 --- a/src/controller/ContactFormController.php +++ b/src/controller/ContactFormController.php | |||
| @@ -19,7 +19,7 @@ class ContactFormController | |||
| 19 | static public function setEmailsRetentionPeriod(EntityManager $entityManager, array $json): void | 19 | static public function setEmailsRetentionPeriod(EntityManager $entityManager, array $json): void |
| 20 | { | 20 | { |
| 21 | $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); | 21 | $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); |
| 22 | $form_data->updateData('retention_period', (int)$json['months']); | 22 | $form_data->updateData($json['field'], (int)$json['months']); |
| 23 | $entityManager->persist($form_data); | 23 | $entityManager->persist($form_data); |
| 24 | $entityManager->flush(); | 24 | $entityManager->flush(); |
| 25 | echo json_encode(['success' => true, 'months' => $json['months']]); | 25 | echo json_encode(['success' => true, 'months' => $json['months']]); |
diff --git a/src/model/entities/Email.php b/src/model/entities/Email.php index d54b3cc..ff76653 100644 --- a/src/model/entities/Email.php +++ b/src/model/entities/Email.php | |||
| @@ -113,23 +113,19 @@ class Email | |||
| 113 | $this->last_contact_date = new \DateTime; | 113 | $this->last_contact_date = new \DateTime; |
| 114 | } | 114 | } |
| 115 | 115 | ||
| 116 | // la durée de conservation $period est propre au bloc formulaire (NodeData) | 116 | public function getDeletionDate(): \DateTime // utilise une durée de conservation $period qui est propre au bloc formulaire (à son NodeData) |
| 117 | // la date de dernier contact | ||
| 118 | public function getDeletionDate(): \DateTime | ||
| 119 | { | 117 | { |
| 120 | // deux tests: | 118 | // tests appliqués: |
| 121 | // => e-mail associé à un formulaire? | 119 | // => e-mail associé à un formulaire? |
| 122 | // => ce formulaire dispose d'une durée de stockage spécifique? | 120 | // => ce formulaire dispose d'une durée de stockage spécifique? |
| 123 | $period = $this->node_data === null ? null : ($this->node_data->getData()['retention_period'] ?? null); | 121 | // => cette donnée est un entier > 0 |
| 122 | $key = $this->is_sensitive ? 'retention_period_sensible' : 'retention_period'; | ||
| 123 | $period = $this->node_data ? (int)($this->node_data->getData()[$key] ?? null) : null; | ||
| 124 | 124 | ||
| 125 | $period = (int)$period; | 125 | $default = $this->is_sensitive ? self::DEFAULT_RETENTION_PERIOD_SENSITIVE : self::DEFAULT_RETENTION_PERIOD; |
| 126 | if($period === null || $period <= 0){ | 126 | $period = ($period === null || $period <= 0) ? $default : $period; |
| 127 | $period = $this->is_sensitive ? self::DEFAULT_RETENTION_PERIOD_SENSITIVE : self::DEFAULT_RETENTION_PERIOD; | ||
| 128 | } | ||
| 129 | |||
| 130 | $date = $this->is_sensitive ? (clone $this->is_sensitive_since) : (clone $this->last_contact_date); // oui durée 5 ans, non durée 3 ans "glissante" | ||
| 131 | // erreur si "sensible" mais sans date disponible (pas censé arriver) | ||
| 132 | 127 | ||
| 128 | $date = clone ($this->is_sensitive ? $this->is_sensitive_since : $this->last_contact_date); // erreur si "sensible" mais sans date disponible (pas censé arriver) | ||
| 133 | return $date->modify('+ ' . (string)$period . ' month'); | 129 | return $date->modify('+ ' . (string)$period . ' month'); |
| 134 | } | 130 | } |
| 135 | } \ No newline at end of file | 131 | } \ No newline at end of file |
diff --git a/src/view/FormBuilder.php b/src/view/FormBuilder.php index e2389b0..7505510 100644 --- a/src/view/FormBuilder.php +++ b/src/view/FormBuilder.php | |||
| @@ -30,7 +30,8 @@ class FormBuilder extends AbstractBuilder | |||
| 30 | $smtp_username = $smtp_username ?? Config::$smtp_username; | 30 | $smtp_username = $smtp_username ?? Config::$smtp_username; |
| 31 | $email_dest = $email_dest ?? Config::$email_dest; | 31 | $email_dest = $email_dest ?? Config::$email_dest; |
| 32 | $keep_emails = (bool)$keep_emails ?? false; // (bool) est inutile mais plus clair | 32 | $keep_emails = (bool)$keep_emails ?? false; // (bool) est inutile mais plus clair |
| 33 | $retention_period = (int)($retention_period ?? App\Entity\Email::DEFAULT_RETENTION_PERIOD); // (int) est nécessaire à cause du stockage JSON | 33 | $retention_period = $this->getRetentionPeriod($retention_period ?? null, App\Entity\Email::DEFAULT_RETENTION_PERIOD); |
| 34 | $retention_period_sensible = $this->getRetentionPeriod($retention_period_sensible ?? null, App\Entity\Email::DEFAULT_RETENTION_PERIOD_SENSITIVE); | ||
| 34 | 35 | ||
| 35 | $admin_content = ''; | 36 | $admin_content = ''; |
| 36 | if($_SESSION['admin']) | 37 | if($_SESSION['admin']) |
| @@ -44,4 +45,9 @@ class FormBuilder extends AbstractBuilder | |||
| 44 | require self::VIEWS_PATH . $node->getName() . '.php'; | 45 | require self::VIEWS_PATH . $node->getName() . '.php'; |
| 45 | $this->html = ob_get_clean(); // pas de concaténation ici, on écrase | 46 | $this->html = ob_get_clean(); // pas de concaténation ici, on écrase |
| 46 | } | 47 | } |
| 48 | |||
| 49 | private function getRetentionPeriod(mixed $period, int $default_period): int | ||
| 50 | { | ||
| 51 | return ($period === null || (int)$period <= 0) ? $default_period : (int)$period; // (int) est nécessaire à cause du stockage JSON | ||
| 52 | } | ||
| 47 | } \ No newline at end of file | 53 | } \ No newline at end of file |
diff --git a/src/view/templates/form_admin.php b/src/view/templates/form_admin.php index 457f770..7156374 100644 --- a/src/view/templates/form_admin.php +++ b/src/view/templates/form_admin.php | |||
| @@ -9,11 +9,16 @@ declare(strict_types=1); | |||
| 9 | <input type="checkbox" id="keep_emails_<?= $node->getNodeData()->getId() ?>" <?= $keep_emails ? 'checked' : '' ?> onclick="keepEmails(<?= $node->getNodeData()->getId() ?>)"> | 9 | <input type="checkbox" id="keep_emails_<?= $node->getNodeData()->getId() ?>" <?= $keep_emails ? 'checked' : '' ?> onclick="keepEmails(<?= $node->getNodeData()->getId() ?>)"> |
| 10 | </p> | 10 | </p> |
| 11 | <p><i>Notez que ces enregistrements sont des données personnelles et sont concernés par le RGPD.</i></p> | 11 | <p><i>Notez que ces enregistrements sont des données personnelles et sont concernés par le RGPD.</i></p> |
| 12 | <p><a href="<?= new URL(['page' => 'emails']) ?>"><button>Consulter les e-mails enregistrés</button></a></p> | ||
| 12 | <p> | 13 | <p> |
| 13 | <label for="retention_period_<?= $node->getNodeData()->getId() ?>">Durée de conservation (en mois)</label> | 14 | <label for="retention_period_<?= $node->getNodeData()->getId() ?>">Durée de conservation (en mois)</label> |
| 14 | <input type="number" id="retention_period_<?= $node->getNodeData()->getId() ?>" min="0" value="<?= $retention_period ?>" size="2" onchange="setEmailsRetentionPeriod(<?= $node->getNodeData()->getId() ?>)"> | 15 | <input type="number" id="retention_period_<?= $node->getNodeData()->getId() ?>" min="0" value="<?= $retention_period ?>" size="2" onchange="setEmailsRetentionPeriod(<?= $node->getNodeData()->getId() ?>, 'retention_period')"> |
| 15 | </p> | 16 | </p> |
| 16 | <p><a href="<?= new URL(['page' => 'emails']) ?>"><button>Consulter les e-mails enregistrés</button></a></p> | 17 | <p> |
| 18 | <label for="retention_period_sensible_<?= $node->getNodeData()->getId() ?>">Durée de conservation des emails sensibles(en mois)</label> | ||
| 19 | <input type="number" id="retention_period_sensible_<?= $node->getNodeData()->getId() ?>" min="0" value="<?= $retention_period_sensible ?>" size="2" onchange="setEmailsRetentionPeriod(<?= $node->getNodeData()->getId() ?>, 'retention_period_sensible')"> | ||
| 20 | </p> | ||
| 21 | |||
| 17 | </div> | 22 | </div> |
| 18 | <div class="admin_form"> | 23 | <div class="admin_form"> |
| 19 | <h3>Paramètres d'envoi</h3> | 24 | <h3>Paramètres d'envoi</h3> |
