Skip to content

Fix bug with review - #1272

Merged
awenig merged 5 commits into
masterfrom
fix-bug-amendment-review
Jul 31, 2026
Merged

Fix bug with review#1272
awenig merged 5 commits into
masterfrom
fix-bug-amendment-review

Conversation

@awenig

@awenig awenig commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 amendmentId from the dashboard table to the review endpoint.
  • Update the Admin controller endpoint to accept amendmentId.
  • Adjust Admin_model to 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.

Comment thread application/views/dashboard/amendements/index.php
Comment thread application/views/dashboard/amendements/index.php
Comment thread application/models/Admin_model.php

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 en string laisse 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/caster amendmentId en 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

  • $amendmentId est 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 renvoyant success. Cast/valider en entier (> 0) permet de rejeter immédiatement les valeurs invalides.
      $amendmentId  = (string)$this->input->post('amendmentId');

Comment thread application/views/dashboard/amendements/index.php

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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')

@awenig
awenig merged commit 8f063cc into master Jul 31, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants