Skip to content

Commit d679c69

Browse files
committed
add lis_person_sourcedid to LTI_13_UserAlias
LTI 1.3 platforms can send a unique identifier under the `person_sourcedid` field of the LIS claim, corresponding to the `lis_person_sourcedid` field from LTI 1.1. This commit adds a `lis_person_sourcedid` field to `LTI_13_UserAlias` objects, and uses it as the user's identifier when set, instead of the `sub` value from OAuth. Moodle sends the "ID Number" field as `lis_person_sourcedid`. I haven't looked at what other VLEs do yet.
1 parent 9054d33 commit d679c69

5 files changed

Lines changed: 29 additions & 3 deletions

File tree

‎numbas_lti/backends.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,11 @@ def authenticate(self, request):
200200
if locale:
201201
user_alias.locale = locale
202202

203-
user_alias.save(update_fields=('full_name', 'given_name', 'family_name', 'email', 'locale'))
203+
lis_claim = launch_data.get('https://purl.imsglobal.org/spec/lti/claim/lis')
204+
if lis_claim:
205+
user_alias.lis_person_sourcedid = lis_claim.get('person_sourcedid')
206+
207+
user_alias.save(update_fields=('full_name', 'given_name', 'family_name', 'email', 'locale', 'lis_person_sourcedid'))
204208
user.save(update_fields=('first_name', 'last_name', 'email'))
205209

206210
return user
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 5.1.4 on 2025-04-01 13:16
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('numbas_lti', '0099_alter_resource_allow_student_reopen'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='lti_13_useralias',
15+
name='lis_person_sourcedid',
16+
field=models.CharField(blank=True, max_length=255, null=True),
17+
),
18+
]

‎numbas_lti/models.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ class LTI_13_UserAlias(models.Model):
192192
consumer = models.ForeignKey(LTIConsumer, related_name='lti_13_user_aliases', on_delete=models.CASCADE)
193193
user = models.ForeignKey(User, related_name='lti_13_aliases', on_delete=models.CASCADE)
194194
sub = models.CharField(max_length=255) # The platform's identifier for the user
195+
lis_person_sourcedid = models.CharField(max_length=255, blank=True, null=True) # Another identifier for the user from the platform.
195196

196197
full_name = models.CharField(max_length=1000, blank=True, default='')
197198
given_name = models.CharField(max_length=1000, blank=True, default='')
@@ -1064,6 +1065,8 @@ def get_source_id(self):
10641065
try:
10651066
if self.lti_11 and self.lti_11.lis_person_sourcedid:
10661067
return self.lti_11.lis_person_sourcedid
1068+
elif self.lti_13 and self.lti_13.lis_person_sourcedid:
1069+
return self.lti_13.lis_person_sourcedid
10671070
else:
10681071
return self.consumer_user_id
10691072
except LTI_11_UserData.DoesNotExist:

‎numbas_lti/templates/numbas_lti/management/attempts.html‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ <h1>{% translate "Attempts" %}</h1>
5050
</nav>
5151
{% endif %}
5252

53-
{% with identifier_field=resource.context.consumer.identifier_field %}
53+
{% with identifier_field=context.consumer.identifier_field %}
5454
<div class="scrolling-table">
5555
<table id="attempts" class="table-striped">
5656
<thead>
5757
<tr>
5858
<th scope="col">{% translate "Student" %}</th>
5959
{% if identifier_field %}
60-
<th scope="col">{{resource.context.consumer.get_identifier_field_display}}</th>
60+
<th scope="col">{{context.consumer.get_identifier_field_display}}</th>
6161
{% endif %}
6262
<th scope="col">{% translate "Start time" %}</th>
6363
<th scope="col" aria-label="{% translate "Controls" %}"></th>

‎numbas_lti/views/resource.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ def get_context_data(self, *args, **kwargs):
580580
context = super(AllAttemptsView,self).get_context_data(*args,**kwargs)
581581
resource = self.get_resource()
582582
context['resource'] = resource
583+
context['context'] = resource.lti_contexts().first()
583584
context['query'] = self.query
584585

585586
return context

0 commit comments

Comments
 (0)