Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Adds user retirement sink #63

Merged
merged 6 commits into from
Dec 7, 2023
Merged

Adds user retirement sink #63

merged 6 commits into from
Dec 7, 2023

Conversation

pomegranited
Copy link
Contributor

@pomegranited pomegranited commented Dec 4, 2023

Description:

Adds an event sink for "user retirement" events.

On receipt of a USER_RETIRE_LMS_MISC Django signal for a given user, the sink will delete all records from the PII tables for that user, currently:

  • event_sink.user_profile
  • event_sink.external_id

ISSUE: openedx/tutor-contrib-aspects#449

Relates to: openedx/tutor-contrib-aspects#529

This PR should be merged/tagged first.

Merge deadline: none

Installation instructions:

To install this temporary branch on your local Tutor Aspects stack:

  1. Install the Aspects plugin from User PII dictionary table openedx/tutor-contrib-aspects#529
  2. Install the user retirement plugin, following instructions on https://github.com/hastexo/tutor-contrib-retirement
  3. Add this repo/branch to the LMS requirements:
    echo "git+https://github.com/openedx/openedx-event-sink-clickhouse.git@jill/retire-user#egg=openedx-event-sink-clickhouse==0.5.0" >> "$(tutor config printroot)/env/build/openedx/requirements/private.txt"
  4. Enable Aspects PII:
    tutor config save -s ASPECTS_ENABLE_PII=True
  5. (optional) Shorten the lifetime of the user_pii dict to 10s to make testing data changes easier:
    tutor config save -s ASPECTS_PII_CACHE_LIFETIME=10
  6. (optional) Remove the cooling off period to make it easier to process user retirements:
    tutor config save -s RETIREMENT_COOL_OFF_DAYS=0
  7. Rebuild image:
    tutor images build openedx --no-cache
  8. Re-init Aspects to use updated settings:
    tutor local do init -l aspects
  9. Reboot Tutor to use new images:
    tutor local reboot -d

Testing instructions:

  1. Register a new user on the platform, and update that user's Account (aka user profile) details.
    Use Superset's SQL Lab to check that the user profile change(s) flow through to the event_sink.user_pii table.
  2. Enrol the user in a course to see external IDs created and flowing into the event_sink.user_pii table.
  3. In the LMS Accounts page, delete the user.
  4. From the command line, run the user retirement pipeline to move the user's retirement request from PENDING into COMPLETED.
    tutor local retire-users
  5. After ASPECTS_PII_CACHE_LIFETIME elapses, check Superset SQL Lab to ensure that the user records have been deleted from event_sink.user_pii.

Merge checklist:

  • All reviewers approved
  • CI build is green
  • Version bumped
  • Changelog record added
  • Documentation updated (not only docstrings)
  • Commits are squashed

Post merge:

  • Create a tag
  • Check new version is pushed to PyPI after tag-triggered build is
    finished.
  • Delete working branch (if not needed anymore)

so we can run `make format`
@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Dec 4, 2023
@openedx-webhooks
Copy link

openedx-webhooks commented Dec 4, 2023

Thanks for the pull request, @pomegranited! Please note that it may take us up to several weeks or months to complete a review and merge your PR.

Feel free to add as much of the following information to the ticket as you can:

  • supporting documentation
  • Open edX discussion forum threads
  • timeline information ("this must be merged by XX date", and why that is)
  • partner information ("this is a course on edx.org")
  • any other information that can help Product understand the context for the PR

All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here.

Please let us know once your PR is ready for our review and all tests are green.

@pomegranited pomegranited force-pushed the jill/retire-user branch 2 times, most recently from 3d9688d to 5a8400a Compare December 4, 2023 03:52
Comment on lines 11 to 16
try:
from openedx.core.djangoapps.user_api.accounts.signals import USER_RETIREMENT_LMS_MISC
except ImportError:
# Tests don't have the platform installed
USER_RETIREMENT_LMS_MISC = Signal()

Copy link
Contributor

Choose a reason for hiding this comment

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

We should try to use an openedx event for this one, I think there isn't one but I'm not sure. I can do the contribution if needed

Copy link
Contributor

Choose a reason for hiding this comment

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

This is the default retirement Signal inside edx-platform, it's used for a lot of things. I totally agree that we should refactor retirement to use openedx-events (and eventually the event bus), but I don't think we should do it as part of this work as I think it would further confuse an already complicated process.

@pomegranited pomegranited marked this pull request as ready for review December 5, 2023 06:11
@patch("event_sink_clickhouse.sinks.user_retire.UserRetirementSink.serialize_item")
@patch("event_sink_clickhouse.sinks.user_retire.UserRetirementSink.is_enabled")
@patch("event_sink_clickhouse.sinks.user_retire.UserRetirementSink.get_model")
def test_retire_user(mock_user_model, mock_is_enabled, mock_serialize_item):
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we get one more test that exercises the many version of this, just to make sure no one breaks it in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

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


model = "auth_user"
unique_key = "id"
clickhouse_table_name = ["user_profile", "external_id"]
Copy link
Contributor

Choose a reason for hiding this comment

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

It's sad that we don't have a more data driven way to deal with this list, but I think it's ok. Can you put a comment here reminding people that this list should exactly match EVENT_SINK_CLICKHOUSE_PII_MODELS in the Aspects plugin? We'll probably want one there, too, to try to keep these from falling out of sync.

Copy link
Contributor

Choose a reason for hiding this comment

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

What if we read this value from settings, and inject it in tutor-contrib-aspects?

Copy link
Contributor

Choose a reason for hiding this comment

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

And transform the PII_MODELS, and MODELS, settings into OVERRIDE_SETTINGS. So those cannot be overriden

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know if this is a desired capability, but it is possible to define other sinks in plugins, so people may want to override those settings. I'm not 100% sure about the hierarchy of settings here, but I think if there's a default setting in this app, and a setting in tutor-contrib-aspects the latter will override. Then if an operator has other needs their specific config will take precedence. I think that would be my preference.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated tutor-contrib-aspects#529 to pass EVENT_SINK_CLICKHOUSE_PII_MODELS in to the openedx settings, and modified this code to use that setting: edc380f

I'm doing a full rebuild of my Tutor dev stack to test this, but how does it look to you?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(rebuild worked.)

This setting is overriden in production by the Tutor environment, so
that:

* the full list of Clickhouse PII tables can be controlled by Aspects
* end users can add their own PII tables too.
and alters the code to show coverage of this branch.
Copy link
Contributor

@bmtcril bmtcril left a comment

Choose a reason for hiding this comment

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

LGTM!

@Ian2012 Ian2012 merged commit bc68887 into main Dec 7, 2023
8 checks passed
@Ian2012 Ian2012 deleted the jill/retire-user branch December 7, 2023 15:34
@openedx-webhooks
Copy link

@pomegranited 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants