Skip to content

Commit

Permalink
Backfill LMSUser.lms_api_user_id from the assignment roster data
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospri committed Nov 28, 2024
1 parent 2e508fc commit 8b21a87
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lms/services/roster.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from logging import getLogger

from sqlalchemy import Select, select, update
from sqlalchemy import Select, select, update, func, text

from lms.models import (
ApplicationInstance,
Expand Down Expand Up @@ -251,6 +251,11 @@ def _get_roster_users(self, roster, tool_consumer_instance_guid):
for member in roster:
lti_user_id = member.get("lti11_legacy_user_id") or member["user_id"]
lti_v13_user_id = member["user_id"]
lms_api_user_id = (
member.get("message", [{}])[0]
.get("https://purl.imsglobal.org/spec/lti/claim/custom", {})
.get("canvas_user_id")
)
name = display_name(
given_name=member.get("name", ""),
family_name=member.get("family_name", ""),
Expand All @@ -270,6 +275,7 @@ def _get_roster_users(self, roster, tool_consumer_instance_guid):
"lti_v13_user_id": lti_v13_user_id,
"h_userid": h_userid,
"display_name": name,
"lms_api_user_id": lms_api_user_id,
}
)

Expand All @@ -282,6 +288,14 @@ def _get_roster_users(self, roster, tool_consumer_instance_guid):
"updated",
# lti_v13_user_id is not going to change but we want to backfill it for existing users.
"lti_v13_user_id",
# Same for lms_api_user_id, not going to change for existing user but we are backfilling for now
(
"lms_api_user_id",
func.coalesce(
text('"excluded"."lms_api_user_id"'),
text('"lms_user"."lms_api_user_id"'),
),
),
],
)

Expand Down

0 comments on commit 8b21a87

Please sign in to comment.