Skip to content

fix: Redact uid field and delete records for retired users from support_historicalusersocialauth#38658

Open
Akanshu-2u wants to merge 19 commits into
openedx:masterfrom
Akanshu-2u:aaich/BOMS-577
Open

fix: Redact uid field and delete records for retired users from support_historicalusersocialauth#38658
Akanshu-2u wants to merge 19 commits into
openedx:masterfrom
Akanshu-2u:aaich/BOMS-577

Conversation

@Akanshu-2u
Copy link
Copy Markdown
Contributor

@Akanshu-2u Akanshu-2u commented May 19, 2026

Description:

This PR strengthens user retirement by ensuring PII stored in django-simple-history snapshots of social auth records is redacted and removed during the retirement workflow.

Changes:

  • Add redact_and_delete_historical_social_auth utility that bulk-updates uid to a safe placeholder redacted-before-delete-{history_id}@safe.com and clears extra_data then deletes the rows.
  • Call the new utility from LMSAccountRetirementView.post() during the retirement workflow.
  • Gracefully skips with a debug log on deployments where the support app is not installed (e.g. non-LMS services).
  • Add LMS tests covering: uid format and UPDATE-before-DELETE ordering (via pre_delete signal), deletion scope (other users' rows untouched), and graceful skip when support app is unavailable.

Private JIRA Link:

BOMS-577

@Akanshu-2u Akanshu-2u requested a review from a team as a code owner May 19, 2026 15:03
@Akanshu-2u Akanshu-2u requested review from Copilot and removed request for a team May 19, 2026 15:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR strengthens user retirement by ensuring PII stored in django-simple-history snapshots of social auth records is redacted and removed during the retirement workflow.

Changes:

  • Call a new retirement utility to redact+delete HistoricalUserSocialAuth rows during user retirement.
  • Add redact_and_delete_historical_social_auth utility that updates uid/extra_data then deletes historical rows.
  • Add LMS tests covering UPDATE-before-DELETE behavior and deletion scope.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
openedx/core/djangoapps/user_api/accounts/views.py Invokes the new historical social auth redaction/deletion step during retirement.
openedx/core/djangoapps/user_api/accounts/utils.py Adds a utility to redact+delete historical social auth snapshots that can retain PII.
openedx/core/djangoapps/user_api/accounts/tests/test_utils.py Adds tests validating query ordering and deletion behavior for historical social auth redaction.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread openedx/core/djangoapps/user_api/accounts/utils.py Outdated
Comment thread openedx/core/djangoapps/user_api/accounts/tests/test_utils.py Outdated
@Akanshu-2u Akanshu-2u requested a review from Copilot May 19, 2026 16:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 2 comments.

Comment thread openedx/core/djangoapps/user_api/accounts/utils.py Outdated
Comment thread openedx/core/djangoapps/user_api/accounts/tests/test_utils.py Outdated
Akanshu-2u and others added 2 commits May 19, 2026 22:19
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@Akanshu-2u Akanshu-2u requested a review from Copilot May 19, 2026 16:53
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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.

Comment thread openedx/core/djangoapps/user_api/accounts/tests/test_utils.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@Akanshu-2u Akanshu-2u requested a review from Copilot May 19, 2026 17:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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.

Comment thread openedx/core/djangoapps/user_api/accounts/utils.py Outdated
@Akanshu-2u Akanshu-2u requested a review from Copilot May 19, 2026 17:54
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 3 comments.

Comment thread openedx/core/djangoapps/user_api/accounts/utils.py Outdated
Comment thread openedx/core/djangoapps/user_api/accounts/tests/test_utils.py Outdated
Comment thread openedx/core/djangoapps/user_api/accounts/tests/test_utils.py Outdated
@Akanshu-2u Akanshu-2u requested a review from Copilot May 19, 2026 18:30
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 2 comments.

Comment thread openedx/core/djangoapps/user_api/accounts/utils.py Outdated
Comment thread openedx/core/djangoapps/user_api/accounts/tests/test_utils.py Outdated
@Akanshu-2u Akanshu-2u requested a review from Copilot May 19, 2026 18:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 3 comments.

Comment thread openedx/core/djangoapps/user_api/accounts/tests/test_utils.py Outdated
Comment thread openedx/core/djangoapps/user_api/accounts/tests/test_utils.py Outdated
Comment thread openedx/core/djangoapps/user_api/accounts/utils.py Outdated
@Akanshu-2u Akanshu-2u requested a review from Copilot May 19, 2026 18:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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.

Comment thread openedx/core/djangoapps/user_api/accounts/utils.py Outdated
@Akanshu-2u Akanshu-2u requested a review from Copilot May 20, 2026 09:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 3 comments.

Comment thread openedx/core/djangoapps/user_api/accounts/tests/test_utils.py Outdated
Comment thread openedx/core/djangoapps/user_api/accounts/tests/test_utils.py
Comment thread openedx/core/djangoapps/user_api/accounts/tests/test_utils.py
@Akanshu-2u Akanshu-2u requested a review from Copilot May 20, 2026 09:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 3 comments.

Comment thread openedx/core/djangoapps/user_api/accounts/utils.py
Comment thread openedx/core/djangoapps/user_api/accounts/tests/test_utils.py Outdated
Comment thread openedx/core/djangoapps/user_api/accounts/views.py
Copy link
Copy Markdown
Contributor

@robrap robrap left a comment

Choose a reason for hiding this comment

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

Thanks.

super().setUp()
self.user = UserFactory.create(username='testuser', email='testuser@example.com')
self.historical_social_auth_model = getattr(getattr(UserSocialAuth, 'history', None), 'model', None)
if self.historical_social_auth_model is None:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can this actually happen?

[query['sql'] for query in ctx],
table=table_name,
)
# since rows are filtered by user_id and history_id is used to build the unique redacted uid.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  • There is a grammatical error in this sentence that makes me unable to understand what you want to get across.
  • I'm not clear if the sentence should be fixed or removed. I'm sort of feel like this whole assertion should be removed.

Comment on lines +233 to +234
HistoricalUserSocialAuth rows are django-simple-history snapshots not covered by the
standard UserSocialAuth retirement step, so they must be explicitly cleaned up.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I replaced this comment. I don't think the original is necessary, and I like this one that was used elsewhere to explain why we are redacting before deleting.

Suggested change
HistoricalUserSocialAuth rows are django-simple-history snapshots not covered by the
standard UserSocialAuth retirement step, so they must be explicitly cleaned up.
Downstream copies of data may use soft-deletes, and redacting before deleting
ensures PII for retired users (or future retirements) is not retained.

HistoricalUserSocialAuth rows are django-simple-history snapshots not covered by the
standard UserSocialAuth retirement step, so they must be explicitly cleaned up.
"""
historical_social_auth_model = getattr(getattr(UserSocialAuth, 'history', None), 'model', None)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this an optional model? Is it behind a feature flag?

Comment on lines +238 to +241
LOGGER.warning(
'redact_and_delete_historical_social_auth: UserSocialAuth has no history model, skipping for user_id=%s',
user_id,
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

At most this would be .debug for local testing, but it probably isn't needed at all. We shouldn't warn for normal behavior.

Comment on lines +265 to +266
# Redact and delete django-simple-history snapshots of social auth records.
redact_and_delete_historical_social_auth(user.id)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm guessing we don't want this here, and only want this when we do the full retirement.

Comment on lines +149 to +150
# Redact and delete django-simple-history snapshots of social auth records.
redact_and_delete_historical_social_auth(user.id)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think we want this here. What do you think? I think this is just adding someone to the queue, where we do minimal retirement to lock them out, but the full retirement happens elsewhere.

Comment on lines +194 to +198
Test that HistoricalUserSocialAuth records are redacted and deleted when retire_user is called.
Covers both single and multiple historical record scenarios.

HistoricalUserSocialAuth rows are django-simple-history snapshots that are not touched
by the live UserSocialAuth retirement step, so they must be explicitly cleaned up.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  • The first line of a docstring is usually a single line (non-wrapped) summary. Add a blank line if you want to add more comments.
  • That said, I'm removing the rest, because I don't think it is needed.
Suggested change
Test that HistoricalUserSocialAuth records are redacted and deleted when retire_user is called.
Covers both single and multiple historical record scenarios.
HistoricalUserSocialAuth rows are django-simple-history snapshots that are not touched
by the live UserSocialAuth retirement step, so they must be explicitly cleaned up.
Test that HistoricalUserSocialAuth records are redacted and deleted when retire_user is called.

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.

5 participants