Fix bug with review - #1272
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the “Reviewed” toggle for dashboard amendements to identify an amendment by amendmentId (instead of (legislature, voteNumero)) when persisting the reviewed state.
Changes:
- Pass
amendmentIdfrom the dashboard table to the review endpoint. - Update the Admin controller endpoint to accept
amendmentId. - Adjust
Admin_modelto persist reviewed state using the new identifier.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| application/views/dashboard/amendements/index.php | Sends amendmentId from the UI and posts it to the review endpoint. |
| application/models/Admin_model.php | Adds amendmentId to the amendements list query and changes reviewed persistence logic. |
| application/controllers/Admin.php | Updates the review endpoint to read amendmentId from POST and call the model accordingly. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
Suppressed comments (2)
application/models/Admin_model.php:343
- Le docblock indique toujours « Crée la ligne dans amendements_ia si elle n'existe pas encore », mais l’implémentation ne fait désormais qu’un
UPDATE. En plus, caster enstringlaisse passer des valeurs invalides (ex:'undefined') et peut mener à un “succès” sans mise à jour. Mettre à jour le docblock pour refléter le comportement réel et valider/casteramendmentIden entier (>0) avant d’exécuter la requête.
/**
* Marque un amendement comme reviewed (ou non).
* Crée la ligne dans amendements_ia si elle n'existe pas encore.
*
* @return bool true si la requête a réussi, false en cas d'erreur SQL
*/
public function set_amendement_reviewed($amendmentId, $reviewed)
{
$amendmentId = (string) $amendmentId;
$reviewed = $reviewed ? 1 : 0;
application/controllers/Admin.php:1024
$amendmentIdest accepté comme chaîne et seulement vérifié pour “non vide”. Avec le bug côté front (ou un client malveillant), des valeurs comme'undefined'passent et conduisent à une requête SQL qui ne met rien à jour, tout en renvoyantsuccess. Cast/valider en entier (> 0) permet de rejeter immédiatement les valeurs invalides.
$amendmentId = (string)$this->input->post('amendmentId');
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (2)
application/models/Admin_model.php:349
- La requête fait uniquement un UPDATE sur amendements_ia. Si aucune ligne n’existe encore pour cet amendementId (cas possible car la liste fait un LEFT JOIN), l’UPDATE réussira mais n’enregistrera rien (0 ligne modifiée) et l’API renverra quand même success=true. Il faut faire un upsert (INSERT … ON DUPLICATE KEY UPDATE) sur amendementId (avec une contrainte UNIQUE côté DB) pour garantir la persistance.
$ok = $this->db->query(
"UPDATE amendements_ia
SET reviewed = ?, updated_at = NOW()
WHERE amendementId = ?",
array($reviewed, $amendmentId)
application/controllers/Admin.php:1028
- Le endpoint lit le champ POST "amendment" mais le message d’erreur dit "amendmentId est requis". Cette incohérence rend l’API plus difficile à consommer/debugger (et complique une éventuelle transition si des clients envoient déjà amendmentId). Accepter les deux noms (amendmentId/amendment) et aligner le message d’erreur.
$amendmentId = (string)$this->input->post('amendment');
$reviewed = filter_var($this->input->post('reviewed'), FILTER_VALIDATE_BOOLEAN);
if (!$amendmentId) {
$this->output->set_status_header(400)->set_content_type('application/json')
No description provided.