Add clear_user_series_partner_ids_for_group function and integrate it…#828
Conversation
… into leave_group - Introduced `clear_user_series_partner_ids_for_group` to clear series partner IDs for a user in a specified group. - Updated the `leave_group` function to call the new clearing function upon a user leaving a group. - Added unit tests for the new function to ensure correct behavior when no partners exist and when partners are cleared. - Enhanced existing tests to verify integration with the leave group functionality.
Confidence Score: 4/5This is close, but one group-removal path should be fixed before merging.
pecha_api/plans/groups/groups_repository.py Reviews (3): Last reviewed commit: "Add resolve_accumulator_bookmark_mala_im..." | Re-trigger Greptile |
…ip function - Renamed `clear_user_series_partner_ids_for_group` to `_clear_user_series_partner_ids_for_group` for internal use and created a new `clear_user_series_partner_ids_for_group` function that commits changes after clearing partner IDs. - Added `leave_group_membership` function to encapsulate the logic for removing a user from a group and clearing their series partner IDs. - Updated the `leave_group` function to utilize the new `leave_group_membership` function, simplifying the code. - Enhanced unit tests to cover the new leave group functionality and ensure proper behavior during membership removal and partner ID cleanup.
… image handling - Introduced `resolve_accumulator_bookmark_mala_image_url` to determine the appropriate mala image URL for bookmarks based on accumulator type and linked mantra. - Updated `enrich_accumulator_bookmark` to utilize the new function for retrieving mala image URLs. - Enhanced unit tests to cover the new functionality, ensuring correct behavior for both preset and user accumulators. - Refactored related tests to align with the new image resolution logic.
| def leave_group_membership( | ||
| db: Session, | ||
| user_id: UUID, | ||
| group_id: UUID, | ||
| ) -> None: | ||
| db.execute( | ||
| delete(author_group_joins).where( | ||
| author_group_joins.c.group_id == group_id, | ||
| author_group_joins.c.user_id == user_id, | ||
| ) | ||
| ) | ||
| _clear_user_series_partner_ids_for_group( | ||
| db=db, user_id=user_id, group_id=group_id | ||
| ) | ||
| db.commit() |
There was a problem hiding this comment.
Admin removal keeps partners When an admin removes a member, the code still uses
remove_group_member, which deletes and commits the membership row without clearing that user's UserSeriesEnrollment.series_partner_id values for partners in the group. A user removed through DELETE /{group_id}/members/{author_id} can still have enrollments pointing at partners from a group they no longer belong to. Route that path through the same membership removal and partner cleanup flow, or apply the cleanup there as well.
|



… into leave_group
clear_user_series_partner_ids_for_groupto clear series partner IDs for a user in a specified group.leave_groupfunction to call the new clearing function upon a user leaving a group.