Skip to content

Add clear_user_series_partner_ids_for_group function and integrate it…#828

Merged
tenkus47 merged 3 commits into
developfrom
unjoin_group_fix
Jun 27, 2026
Merged

Add clear_user_series_partner_ids_for_group function and integrate it…#828
tenkus47 merged 3 commits into
developfrom
unjoin_group_fix

Conversation

@tenkus47

Copy link
Copy Markdown
Member

… 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.

… 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.
@tenkus47 tenkus47 requested a review from Tech-lo June 27, 2026 16:04
@greptile-apps

greptile-apps Bot commented Jun 27, 2026

Copy link
Copy Markdown

Confidence Score: 4/5

This is close, but one group-removal path should be fixed before merging.

  • Self-service group leave now keeps membership deletion and partner cleanup in one commit.
  • Admin member removal can still leave enrollments pointing at partners from a group the user no longer belongs to.

pecha_api/plans/groups/groups_repository.py

Reviews (3): Last reviewed commit: "Add resolve_accumulator_bookmark_mala_im..." | Re-trigger Greptile

Comment thread pecha_api/plans/groups/groups_service.py Outdated
tenkus47 added 2 commits June 27, 2026 21:39
…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.
@tenkus47 tenkus47 merged commit 806c49d into develop Jun 27, 2026
4 checks passed
@tenkus47 tenkus47 deleted the unjoin_group_fix branch June 27, 2026 16:50
Comment on lines +167 to +181
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()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 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.

@sonarqubecloud

Copy link
Copy Markdown

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