Skip to content

Commit

Permalink
Make export work better with LTI 1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
csev committed Sep 3, 2022
1 parent 92f74b4 commit 69371d3
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cc/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@
<p>
<label for="topic_select_full">How would you like to import discussions/topics?</label>
<select name="topic" id="topic_select_full">
<option value="none">Do not import discussion topics</option>
<!-- <option value="lti">Use discussion tool on this server (LTI)</option> -->
<option value="lti_grade">Use discussion tool on this server (LTI) with grade passback</option>
<option value="lms">Use the Canvas discussion tool</option>
<option value="none">Do not import discussion topics</option>
</select>
</p>
<?php } else { ?>
Expand Down
4 changes: 2 additions & 2 deletions cc/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@
<p>
<label for="topic_select_full">How would you like to import discussions/topics?</label>
<select name="topic" id="topic_select_full">
<option value="none">Do not import discussion topics</option>
<option value="lti">Use discussion tool on this server (LTI)</option>
<option value="lms">Use the LMS Discussion Tool</option>
<option value="lti_grade">Use discussion tool on this server (LTI) with grade passback</option>
<option value="none">Do not import discussion topics</option>
</select>
</p>
<?php } else { ?>
Expand Down Expand Up @@ -129,10 +129,10 @@
<p>
<label for="topic_select_full">How would you like to import discussions/topics?</label>
<select name="topic" id="topic_select_partial">
<option value="none">Do not import discussion topics</option>
<option value="lti">Use discussion tool on this server (LTI)</option>
<option value="lms">Use the LMS Discussion Tool</option>
<option value="lti_grade">Use discussion tool on this server (LTI) with grade passback</option>
<option value="none">Do not import discussion topics</option>
</select>
</p>
<?php } else { ?>
Expand Down
2 changes: 2 additions & 0 deletions lti/store/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,7 @@
<p>
<label for="topic_select_full">How would you like to import discussions/topics?</label>
<select name="topic" id="topic_select_full">
<option value="none">Do not import discussion topics</option>
<option value="lti">Use discussion tool on this server (LTI)</option>
<option value="lms">Use the LMS Discussion Tool</option>
<option value="lti_grade">Use discussion tool on this server (LTI) with grade passback</option>
Expand Down Expand Up @@ -851,6 +852,7 @@
<p>
<label for="topic_select_partial">How would you like to import discussions/topics?</label>
<select name="topic" id="topic_select_partial">
<option value="none">Do not import discussion topics</option>
<option value="lti">Use discussion tool on this server (LTI)</option>
<option value="lms">Use the LMS Discussion Tool</option>
<option value="lti_grade">Use discussion tool on this server (LTI) with grade passback</option>
Expand Down
35 changes: 35 additions & 0 deletions vendor/tsugi/lib/src/Core/Launch.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,41 @@ public function isCoursera() {
}
}

/**
* Return the document target
* The value for this property MUST be one of: frame, iframe, or window.
*/
public function documentTarget() {
$claim = $this->ltiJWTClaim(LTI13::PRESENTATION_CLAIM, null);
if ( is_object($claim) ) {
$target = null;
if ( isset($claim->{LTI13::DOCUMENT_TARGET}) ) {
$target = $claim->{LTI13::DOCUMENT_TARGET};
}
return $target;
} else {
$target = $this->ltiRawParameter(LTIConstants::LAUNCH_PRESENTATION_DOCUMENT_TARGET, null);
return $target;
}
}

/**
* Return the return Url
*/
public function returnUrl() {
$claim = $this->ltiJWTClaim(LTI13::PRESENTATION_CLAIM, null);
if ( is_object($claim) ) {
$target = null;
if ( isset($claim->{LTI13::RETURN_URL}) ) {
$target = $claim->{LTI13::RETURN_URL};
}
return $target;
} else {
$target = $this->ltiRawParameter(LTIConstants::LAUNCH_PRESENTATION_RETURN_URL, null);
return $target;
}
}

/**
* Return a boolean is this is an LTI Advantage launch
*/
Expand Down
27 changes: 19 additions & 8 deletions vendor/tsugi/lib/src/UI/Output.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ function headerData() {
$websocket_token = (WebSocket::enabled() && $LINK) ? '"'.WebSocket::getToken($LINK->launch).'"' : 'false';
$retval .= "websocket_token: ".$websocket_token.",\n";
$retval .= "react_token: \"".session_id()."\",\n";
$retval .= "window_close_message: \""._m('Application complete')."\",\n";
$retval .= "window_close_message: \""._m('Application complete - You can close this tab.')."\",\n";
$retval .= "session_expire_message: \""._m('Your session has expired')."\"\n";
$retval .= "\n}\n</script>\n";
return $retval;
Expand Down Expand Up @@ -847,7 +847,15 @@ function topNav($tool_menu=false) {
global $CFG, $TSUGI_LAUNCH;
$sess_key = 'tsugi_top_nav_'.$CFG->wwwroot;

$launch_return_url = LTIX::ltiRawParameter('launch_presentation_return_url', false);
// $launch_target = LTIX::ltiRawParameter('launch_presentation_document_target', false);
// $launch_return_url = LTIX::ltiRawParameter('launch_presentation_return_url', false);
$launch_target = null;
$launch_return_url = null;
if ( is_object($TSUGI_LAUNCH) ) {
$launch_target = $TSUGI_LAUNCH->documentTarget();
$launch_return_url = $TSUGI_LAUNCH->returnUrl();
}

// Ways to know if this was a launch or are we stand alone
$user_id = LTIX::ltiRawParameter('user_id', false);
$oauth_nonce = LTIX::ltiRawParameter('oauth_nonce', false);
Expand All @@ -857,7 +865,6 @@ function topNav($tool_menu=false) {
if ( $CFG->wwwroot && startsWith($launch_return_url, $CFG->wwwroot) ) $same_host = true;

// Canvas bug: launch_target is iframe even in new window (2017-01-10)
$launch_target = LTIX::ltiRawParameter('launch_presentation_document_target', false);
$menu_set = false;
if ( $menu_set === false && $this->session_get($sess_key) ) {
$menu_set = \Tsugi\UI\MenuSet::import($this->session_get($sess_key));
Expand All @@ -866,15 +873,19 @@ function topNav($tool_menu=false) {
} else if ( $same_host && $launch_return_url ) {
// If we are in an iframe we will be hidden
$menu_set = self::returnMenuSet($launch_return_url);
} else if ( $launch_target !== false && strtolower($launch_target) == 'window' ) {
} else if ( is_string($launch_target) && strtolower($launch_target) == 'window' ) {
$menu_set = self::closeMenuSet();
// Since Sakai sets returnUrl but really does nothing with it except tell the user
// to close the tab
} else if ( is_object($TSUGI_LAUNCH) && $TSUGI_LAUNCH->isSakai() ) {
$menu_set = self::closeMenuSet();
// Since Coursers sets precious little
// Since Coursera sets precious little
} else if ( is_object($TSUGI_LAUNCH) && $TSUGI_LAUNCH->isCoursera() ) {
$menu_set = self::closeMenuSet();
// Since canvas does not set launch_target properly
} else if ( $launch_target !== false && is_object($TSUGI_LAUNCH) && ( $TSUGI_LAUNCH->isCanvas() || $TSUGI_LAUNCH->isCoursera() ) ) {
// Since Canvas does not set launch_target properly
} else if ( is_string($launch_target) && is_object($TSUGI_LAUNCH) && ( $TSUGI_LAUNCH->isCanvas() || $TSUGI_LAUNCH->isCoursera() ) ) {
$menu_set = self::closeMenuSet();
} else if ( $launch_return_url !== false && strlen($launch_return_url) > 0 ) {
} else if ( is_string($launch_return_url) && strlen($launch_return_url) > 0 ) {
$menu_set = self::returnMenuSet($launch_return_url);
// We are running stand alone (i.e. not from a real LTI Launch)
} else if ( $user_id === false ) {
Expand Down
8 changes: 8 additions & 0 deletions vendor/tsugi/lib/src/Util/LTI13.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ class LTI13 {
const DEPLOYMENT_ID_CLAIM = 'https://purl.imsglobal.org/spec/lti/claim/deployment_id';
const ROLES_CLAIM = 'https://purl.imsglobal.org/spec/lti/claim/roles';
const PRESENTATION_CLAIM = 'https://purl.imsglobal.org/spec/lti/claim/launch_presentation';
// The value for this property MUST be one of: frame, iframe, or window.
const DOCUMENT_TARGET = 'document_target';
const DOCUMENT_TARGET_FRAME = 'frame';
const DOCUMENT_TARGET_IFRAME = 'iframe';
const DOCUMENT_TARGET_WINDOW = 'window';
const RETURN_URL = 'return_url';

const LTI11_TRANSITION_CLAIM = 'https://purl.imsglobal.org/spec/lti/claim/lti1p1';
const FOR_USER_CLAIM = 'https://purl.imsglobal.org/spec/lti/claim/for_user';

Expand All @@ -39,6 +46,7 @@ class LTI13 {
const SCORE_TYPE = 'application/vnd.ims.lis.v1.score+json';
const RESULTS_TYPE = 'application/vnd.ims.lis.v2.resultcontainer+json';

// https://www.imsglobal.org/spec/lti/v1p3/#platform-instance-claim
const TOOL_PLATFORM_CLAIM = 'https://purl.imsglobal.org/spec/lti/claim/tool_platform';
const PRODUCT_FAMILY_CODE = "product_family_code";

Expand Down

0 comments on commit 69371d3

Please sign in to comment.