Skip to content

Conversation

@arslanashraf7
Copy link
Contributor

@arslanashraf7 arslanashraf7 commented Nov 18, 2025

What are the relevant tickets?

https://github.com/mitodl/hq/issues/8853

Description (What does it do?)

  • Adds a new plugin for LTI-related utilities
  • Initially, the plugin adds an API to fix the bad state of users in OpenEdX who are created via Canvas
  • The API is authenticated via staff token, just like some of our other APIs, e.g., course modes or course details
  • The API receives an email address as a POST parameter and tries to identify if the user was created via LTI and is in a bad state
    • NOTE: Any user that has been created via LTI has two fields: 1) lti_user_id in the LtiUser table mapping and username in the edX users table. As long as both of these values are the same, we are sure that the user was created automatically via Canvas/LTI
  • The API if successfully identifies the LTI-created user would do the following:
    • Update the email address and replace the organization part with <existing_email_name@lti_example.com>
    • Delete all the social auth records for this user
    • Delete the LTI record for this user because a new one should be created for the correct user when they use LTI content next time
    • Move the user to retirement so that a proper user can be created via MITx Online next time

How can this be tested?

  • Install this plugin in the edX instance (Steps are mentioned in the plugin readme)
  • Setup different users manually without using MITx Online
  • Enable feature flag in private.py FEATURES["ENABLE_LTI_PROVIDER"] = True
  • Add a new application ('lms.djangoapps.lti_provider') in INSTALLED_APPS in lms/envs/common.py e.g
    'lms.djangoapps.bulk_email',
    'lms.djangoapps.branding',
    'lms.djangoapps.lti_provider',
  • Add a new entry in http://local.openedx.io:8000/admin/lti_provider/lticonsumer/
  • Run script below and see if you are able to create a dummy LTI user in edX
  • Once you create a new user, use the email id to register a new account in MITx Online
    • The account registration should be successful if you are on fix: Fix LTI based duplicate email users mitxonline#3098
    • A new user should be created in edX with the correct email, and the old one you created via script should have its email ID changed to the placeholder
    • Any existing social auth records for this old user should be deleted automatically
    • The user should be moved to retirement flow

SCRIPT TO SET UP DUMMY LTI USER
In your LMS Django admin, use this script to create a dummy LTI user:

from lms.djangoapps.lti_provider.users import create_lti_user
from lms.djangoapps.lti_provider.models import LtiConsumer

lti_user_id="129012909f2ae33423232323261d2a0c87"


profile = {"email": "email_name+lti1@org.com", "username": lti_user_id}

consumer = LtiConsumer.objects.first()

create_lti_user(lti_user_id, consumer, profile)

Additional Context

Should be tested along with mitodl/mitxonline#3098 and mitodl/edx-api-client#133

@arslanashraf7 arslanashraf7 force-pushed the arslan/8853-lti-user-fix branch 2 times, most recently from 8d5774d to f8d68a8 Compare November 18, 2025 09:34
@arslanashraf7 arslanashraf7 force-pushed the arslan/8853-lti-user-fix branch 3 times, most recently from 3e94a09 to 3a4deee Compare November 20, 2025 08:03
@arslanashraf7 arslanashraf7 marked this pull request as ready for review November 20, 2025 16:35
@arslanashraf7 arslanashraf7 force-pushed the arslan/8853-lti-user-fix branch from abddeff to 624c7fe Compare November 20, 2025 16:38
@arslanashraf7 arslanashraf7 force-pushed the arslan/8853-lti-user-fix branch 4 times, most recently from 2ff0176 to e9082e8 Compare November 21, 2025 10:46
@arslanashraf7 arslanashraf7 force-pushed the arslan/8853-lti-user-fix branch from e9082e8 to bfd54c3 Compare November 21, 2025 14:10
Copy link

@rhysyngsun rhysyngsun left a comment

Choose a reason for hiding this comment

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

One comment

try:
create_retirement_request_and_deactivate_account(user)
except Exception as e: # noqa: BLE001
log.error("Error retiring and deactivating user: %s", e) # noqa: TRY400

Choose a reason for hiding this comment

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

If we get an error here, shouldn't we respond with an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I added it as an additional step and I explicitly didn't return error to MITx Online if retirement fails. That's because we would have already updated the email of the old user at this point so MITx Online registration can be retried. Let me know if we should link it to the error response we send to MITx Online.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants