Skip to content

Commit

Permalink
🐛(backend) fix blackboard LTI roles parsing
Browse files Browse the repository at this point in the history
Parsing LTI roles sent by blackboard was broken.

Fixes #2676
  • Loading branch information
kernicPanel committed Jan 9, 2025
1 parent 0b443a1 commit 65196bc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed

- Fix blackboard LTI roles parsing

## [5.5.2] - 2024-12-19

### Added
Expand Down
2 changes: 1 addition & 1 deletion src/backend/marsha/core/lti/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def roles(self):
"""
roles = self.request.POST.get("roles", "")
# remove LIS roles prefix
roles = re.sub(r"^urn:lti:instrole:ims/lis/", "", roles)
roles = re.sub(r"urn:lti:(inst)?role:ims/lis/", "", roles)
# Remove all spaces from the string and extra trailing or leading commas
roles = re.sub(r"[\s+]", "", roles).strip(",")
# Return a set of the roles mentioned in the request
Expand Down
5 changes: 3 additions & 2 deletions src/backend/marsha/core/tests/lti/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,16 @@ def test_lti_video_instructor(self):
", staff", # a leading comma should be ignored
"staff,", # a trailing comma should be ignored
"urn:lti:instrole:ims/lis/Instructor", # the LIS role identifier should be recognized
"urn:lti:role:ims/lis/Instructor,urn:lti:instrole:ims/lis/Faculty",
]:
request = self.factory.post("/", {"roles": roles_string})
lti = LTI(request, uuid.uuid4())
self.assertTrue(lti.is_instructor)
self.assertTrue(lti.is_instructor, roles_string)

for roles_string in ["", "instructori", "student", "administrator,student"]:
request = self.factory.post("/", {"roles": roles_string})
lti = LTI(request, uuid.uuid4())
self.assertFalse(lti.is_instructor)
self.assertFalse(lti.is_instructor, roles_string)

@mock.patch.object(lti_module, "verify_request_common", return_value=True)
def test_lti_passport_unknown(self, mock_verify):
Expand Down

0 comments on commit 65196bc

Please sign in to comment.