Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store LMS API id on LMSUser during launches #6878

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lms/services/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ def upsert_user(self, lti_user: LTIUser) -> User:
def upsert_lms_user(self, user: User, lti_params: LTIParams) -> LMSUser:
"""Upsert LMSUser based on a User object."""
self._db.flush() # Make sure User has hit the DB on the current transaction

# API ID, only Canvas for now
lms_api_user_id = lti_params.get("custom_canvas_user_id")
lms_user = bulk_upsert(
self._db,
LMSUser,
Expand All @@ -86,6 +89,7 @@ def upsert_lms_user(self, user: User, lti_params: LTIParams) -> LMSUser:
"h_userid": user.h_userid,
"email": user.email,
"display_name": user.display_name,
"lms_api_user_id": lms_api_user_id,
}
],
index_elements=["h_userid"],
Expand All @@ -100,6 +104,7 @@ def upsert_lms_user(self, user: User, lti_params: LTIParams) -> LMSUser:
text('"lms_user"."lti_v13_user_id"'),
),
),
"lms_api_user_id",
],
).one()
bulk_upsert(
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/lms/services/user_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def test_upsert_user_doesnt_save_email_for_existing_students(

def test_upsert_lms_user(self, service, lti_user, pyramid_request, db_session):
user = service.upsert_user(lti_user)
pyramid_request.lti_params["custom_canvas_user_id"] = "lms_api_user_id"

lms_user = service.upsert_lms_user(user, pyramid_request.lti_params)

lms_user = db_session.scalars(
Expand All @@ -75,6 +77,7 @@ def test_upsert_lms_user(self, service, lti_user, pyramid_request, db_session):
assert lms_user.email == user.email
assert lms_user.updated == user.updated
assert lms_user.lti_v13_user_id == pyramid_request.lti_params.v13.get("sub")
assert lms_user.lms_api_user_id == "lms_api_user_id"

def test_upsert_lms_user_doesnt_clear_lti_v13_user_id(
self, service, lti_user, pyramid_request, db_session
Expand Down
Loading