Skip to content

Add support for Canvas ltiLaunchUrl in outcome request #77

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
16 changes: 14 additions & 2 deletions src/lti/outcome_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def post_replace_result(self, score, result_data=None):

'text' : str text
'url' : str url
'ltiLaunchUrl' : str url
'''
self.operation = REPLACE_REQUEST
self.score = score
Expand All @@ -84,9 +85,9 @@ def post_replace_result(self, score, result_data=None):
error_msg = ('Dictionary result_data can only have one entry. '
'{0} entries were found.'.format(len(result_data)))
raise InvalidLTIConfigError(error_msg)
elif 'text' not in result_data and 'url' not in result_data:
elif 'text' not in result_data and 'url' not in result_data and 'ltiLaunchUrl' not in result_data:
error_msg = ('Dictionary result_data can only have the key '
'"text" or the key "url".')
'"text" or the key "url" or the key "ltiLaunchUrl".')
raise InvalidLTIConfigError(error_msg)
else:
return self.post_outcome_request()
Expand Down Expand Up @@ -164,6 +165,14 @@ def process_xml(self, xml):
sourcedGUID.sourcedId
self.score = str(result.resultRecord.result.
resultScore.textString)

if len(resultData := result.find('resultRecord/result/resultData', root.nsmap)):
if r := resultData.find('text', root.nsmap):
self.result_data = {'text': result}
elif r := resultData.find('url', root.nsmap):
self.result_data = {'url': result}
elif r := resultData.find('ltiLaunchUrl', root.nsmap):
self.result_data = {'ltiLaunchUrl': r}
except:
pass

Expand Down Expand Up @@ -230,5 +239,8 @@ def generate_request_xml(self):
elif 'url' in self.result_data:
resultDataURL = etree.SubElement(resultData, 'url')
resultDataURL.text = self.result_data['url']
elif 'ltiLaunchUrl' in self.result_data:
resultDataLaunchURL = etree.SubElement(resultData, 'ltiLaunchUrl')
resultDataLaunchURL.text = self.result_data['ltiLaunchUrl']

return etree.tostring(root, xml_declaration=True, encoding='utf-8')