Add History Logging for Family Merge and Detach Operations - #790
Add History Logging for Family Merge and Detach Operations#790vahidbazzaz wants to merge 8 commits into
Conversation
There was a problem hiding this comment.
@Vahid I tested this a bit more in depth and would say we need another iteration:
from the functional test:
- the lastModified date in the people table is somehow not updated could you maybe adapt the definition of the
simpleBulkSaveChangeHistoryto do this too?
from the code review
- since we do not show the history messages anywhere, I'm happy how they look like atm, but it would be great if you could move the
fromandtovalues out of thechangemessage into the right bits ofsimpleBulkSaveChangeHistory($table, $records, $changes, $from = [], $to = []) - maybe put "parent_id;" in front in the
changemessage to make clear that the parent_id in the record was changed.
I left comments in the code to make it clearer
| } | ||
| } | ||
| }); | ||
| simpleBulkSaveChangeHistory('people', $ids, 'merged to family (head: '.$oldest.')'); |
There was a problem hiding this comment.
this should maybe be simpleBulkSaveChangeHistory('people', $ids, 'parent_id; merged to family', [], ['int'=> <parent_id>);
There was a problem hiding this comment.
Done in 671650c — now simpleBulkSaveChangeHistory('people', $ids, 'parent_id; merged to family', [], ['int' => $oldest]), so the new family head goes into the to column and the message is prefixed with parent_id;.
| db_query('UPDATE people SET parent_id = NULL WHERE id = :id', ['id' => $id]); | ||
| } | ||
| }); | ||
| simpleBulkSaveChangeHistory('people', $ids, 'detached from family'); |
There was a problem hiding this comment.
this should maybe be simpleBulkSaveChangeHistory('people', $ids, 'parent_id; detached from family', ['int'=> <parent_id>, []);
There was a problem hiding this comment.
Done in 671650c, with one adjustment to your suggestion: instead of a single call with one from value, the beneficiaries are grouped by their previous parent_id and one simpleBulkSaveChangeHistory('people', $beneficiaryIds, 'parent_id; detached from family', ['int' => $parentId], []) call is made per family. A multi-select detach can span more than one family, so a single shared from would mis-attribute the old family for anyone not in the first group. Same grouping was applied to the drag & drop add/remove paths.
- Move parent_id values out of the change message into the from/to columns of simpleBulkSaveChangeHistory, grouping beneficiaries by their old/new parent so multi-family batches log correctly - Prefix history messages with 'parent_id;' to name the changed column - Update modified/modified_by on affected records after history insert, guarded by db_fieldexists so it no-ops on tables without the column - Update Cypress assertions to expect the new message text
|
Thanks @HaGuesto — addressed all three points in 671650c:
Verified locally: |
…mily-history-logging # Conflicts: # library/lib/tools.php
The merge case passed all selected ids (including the oldest/head) to simpleBulkSaveChangeHistory, so the head got a 'parent_id; merged to family' entry with to_int pointing at its own id, even though its parent_id never changed. Filter out the head so only members whose parent_id actually changed are logged. Add a checkHistoryLogAbsent Cypress command and assert the head is not logged while the merged member is, locking in the fix.
|
Follow-up correctness fix in d5f5d3d: while verifying the history rows I noticed the merge path was logging the family head as well as the members. Because the head's Added a |
This PR adds comprehensive history logging for family merge and detach operations in the beneficiary management system. Previously, when families were merged or detached (either via action buttons or drag & drop), no audit trail was created in the history table. This made it impossible to investigate cases where beneficiaries (including small children) were unexpectedly deactivated or moved between families.
Changes Made
1. In Manage Beneficiaries add history log if beneficiary is added to a family via drag & drop
include/people.php:503added to family via drag & drop2. In Manage Beneficiaries add history log if beneficiary is removed from a family via drag & drop
include/people.php:506removed from family via drag & drop3. In Manage Beneficiaries add history log if beneficiaries are merged to a family via selection and action button
include/people.php:442merged to family (head: [id])4. In Manage Beneficiaries add history log if beneficiaries are detached from a family via selection and action button
include/people.php:468detached from family5. Drag & Drop Implementation Details
library/lib/list.php:58-94listBulkMove()to track parent_id changes during drag & drop operations6. Cypress Tests
cypress/support/database.js,cypress/e2e/1_feature_tests/5_3_Manage_Beneficiaries.jscheckHistoryLog()command to verify history entries exist in databasegetBeneficiaryIdFromRow()command to extract beneficiary IDs from DOMlibrary/ajax/testhistorycheck.phpfor test verificationTesting
✅ All Cypress tests passing: