Skip to content

Commit

Permalink
consolidate role naming
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeseibel committed Dec 10, 2024
1 parent c05a42a commit dec3e20
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 49 deletions.
38 changes: 38 additions & 0 deletions blti/roles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0


LTI_1p3_ROLES_CLAIM = "https://purl.imsglobal.org/spec/lti/claim/roles"
LTI_1p3_ROLE_PREFIX = "http://purl.imsglobal.org/vocab/lis/v2/"

def roles_from_role_name(role_names):
roles = []

for role_name in role_names:
if role_name == 'User':
roles += ["system/person#User"]
elif role_name in ['Observer', 'Mentor']:
roles += ["institution/person#Observer",
"institution/person#Mentor",
"membership#Mentor"]
elif role_name in ['Student', 'Learner']:
roles += [
"institution/person#Learner",
"institution/person#Student",
"membeship#Learner"]
elif role_name in ['Instructor', 'Faculty', 'Teacher']:
roles += [
"institution/person#Instructor",
"institution/person#Faculty",
"membeship#Instructor"]
elif role_name == 'Administrator':
roles += [
"system/person#User",
"institution/person#Administrator",
"membeship#Administrator"]
elif role_name == 'TeachingAssistant':
roles += ["membership/Instructor#TeachingAssistant"]
elif role_name == 'ContentDeveloper':
roles += ["membership#ContentDeveloper"]

return LTI_1p3_ROLES_CLAIM, [f"{LTI_1p3_ROLE_PREFIX}{r}" for r in roles]
36 changes: 3 additions & 33 deletions blti/tests/test_lti_1p3.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.core.exceptions import ImproperlyConfigured
from blti.validators import BLTIRequestValidator, Roles
from blti.models import CanvasData
from blti.roles import roles_from_role_name
from blti.performance import log_response_time
from blti import BLTI, LTI_DATA_KEY
from blti.mock_data import Mock1p3Data
Expand Down Expand Up @@ -135,39 +136,8 @@ def test_authorize_specific(self):
CanvasData(**self.params)).authorize, role='Manager')

def _set_role(self, role):
self.params[
"https://purl.imsglobal.org/spec/lti/claim/roles"] = []
roles = []
if role == 'User':
roles = ["system/person#User"]
elif role in ['Observer', 'Mentor']:
roles = ["institution/person#Observer",
"institution/person#Mentor",
"membership#Mentor"]
elif role in ['Student', 'Learner']:
roles = [
"institution/person#Learner",
"institution/person#Student",
"membeship#Learner"]
elif role == 'Instructor':
roles = [
"institution/person#Instructor",
"institution/person#Faculty",
"membeship#Instructor"]
elif role == 'Administrator':
roles = [
"system/person#User",
"institution/person#Administrator",
"membeship#Administrator"]
elif role == 'TeachingAssistant':
roles = ["membership/Instructor#TeachingAssistant"]
elif role == 'ContentDeveloper':
roles = ["membership#ContentDeveloper"]

for r in roles:
self.params[
"https://purl.imsglobal.org/spec/lti/claim/roles"].append(
f"http://purl.imsglobal.org/vocab/lis/v2/{r}")
claim, roles = roles_from_role_name([role])
self.params[claim] = roles


class BLTI1p3SessionTest(TestCase):
Expand Down
19 changes: 3 additions & 16 deletions blti/views/develop.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# SPDX-License-Identifier: Apache-2.0

from blti.mock_data import Mock1p3Data
from blti.roles import roles_from_role_name
from django.views.generic import TemplateView
from django.urls import reverse, resolve
from django.urls.exceptions import NoReverseMatch
Expand Down Expand Up @@ -29,22 +30,8 @@ def get_context_data(self, **kwargs):
f"uwcourse:{campus}:a-and-s:pych:psych")

# insert role
role_base = "http://purl.imsglobal.org/vocab/lis/v2"
roles = [f"{role_base}system/person#User"]
if role == "Instructor":
roles += [f"{role_base}/institution/person#Instructor",
f"{role_base}/membership#Instructor"]
elif role == "TeachingAssistant":
roles += [f"{role_base}/membership#TeachingAssistant"]
elif role == "Student":
roles += [f"{role_base}/institution/person#Student",
f"{role_base}/membership#Learner"]
elif role == "Administrator":
roles += [f"{role_base}/system/person#Administrator"]
elif role == "ContentDeveloper":
roles += [f"{role_base}/membership#ContentDeveloper"]

mock_jwt["https://purl.imsglobal.org/spec/lti/claim/roles"] = roles
claim, roles = roles_from_role_name(['User', role])
mock_jwt[claim] = roles

launch_module, launch_class = self._launch_module_and_class()
launch_class.validate_1p3 = lambda launch_class, request: mock_jwt
Expand Down

0 comments on commit dec3e20

Please sign in to comment.