LTI: Fix custom values and substitution + fix params

pull/3065/head
Angel Fernando Quiroz Campos 6 years ago
parent cb40d1a28f
commit dbfb9820d9
  1. 30
      plugin/ims_lti/ImsLtiPlugin.php
  2. 39
      plugin/ims_lti/auth.php

@ -430,19 +430,37 @@ class ImsLtiPlugin extends Plugin
*/ */
public static function getRoleScopeMentor(User $currentUser) public static function getRoleScopeMentor(User $currentUser)
{ {
if (DRH !== $currentUser->getStatus()) { $scope = self::getRoleScopeMentorAsArray($currentUser, true);
return '';
return implode(',', $scope);
}
/**
* Tool User IDs which the user DRH can access as a mentor.
*
* @param User $user
* @param bool $generateIdForTool. Optional. Set TRUE for LTI 1.x.
*
* @return array
*/
public static function getRoleScopeMentorAsArray(User $user, $generateIdForTool = false)
{
if (DRH !== $user->getStatus()) {
return [];
} }
$followedUsers = UserManager::get_users_followed_by_drh($currentUser->getId()); $followedUsers = UserManager::get_users_followed_by_drh($user->getId());
$scope = []; $scope = [];
/** @var array $userInfo */
foreach ($followedUsers as $userInfo) { foreach ($followedUsers as $userInfo) {
$scope[] = self::generateToolUserId($userInfo['user_id']); $scope[] = $generateIdForTool
? self::generateToolUserId($userInfo['user_id'])
: (string) $userInfo['user_id'];
} }
return implode(',', $scope); return $scope;
} }
/** /**
@ -668,7 +686,7 @@ class ImsLtiPlugin extends Plugin
[ [
'digest_alg' => 'sha256', 'digest_alg' => 'sha256',
'private_key_bits' => 2048, 'private_key_bits' => 2048,
'private_key_type' => OPENSSL_KEYTYPE_RSA 'private_key_type' => OPENSSL_KEYTYPE_RSA,
] ]
); );

@ -103,6 +103,12 @@ try {
$jwtContent['family_name'] = $user->getLastname(); $jwtContent['family_name'] = $user->getLastname();
} }
if (DRH === $user->getStatus()) {
$roleScopeMentor = ImsLtiPlugin::getRoleScopeMentor($user);
$jwtContent['https://purl.imsglobal.org/spec/lti/claim/role_scope_mentor'] = $roleScopeMentor;
}
if ($tool->isSharingPicture()) { if ($tool->isSharingPicture()) {
$jwtContent['picture'] = UserManager::getUserPicture($user->getId()); $jwtContent['picture'] = UserManager::getUserPicture($user->getId());
} }
@ -179,17 +185,48 @@ try {
]; ];
// LIS info // LIS info
$toolEval = $tool->getGradebookEval();
if (!empty($toolEval)) {
$jwtContent['https://purl.imsglobal.org/spec/lti-ags/claim/endpoint'] = [
'lineitem' => api_get_path(WEB_PATH).'lti/ags_endpoint/'.$toolEval->getId(),
];
$jwtContent['https://purl.imsglobal.org/spec/lti/claim/lis'] = [ $jwtContent['https://purl.imsglobal.org/spec/lti/claim/lis'] = [
'person_sourcedid' => "$platformDomain:$toolUserId", 'person_sourcedid' => "$platformDomain:{$user->getId()}",
'course_offering_sourcedid' => "$platformDomain:{$course->getId()}" 'course_offering_sourcedid' => "$platformDomain:{$course->getId()}"
.($session ? ":{$session->getId()}" : ''), .($session ? ":{$session->getId()}" : ''),
]; ];
} }
}
// Custom params info // Custom params info
$customParams = $tool->getCustomParamsAsArray(); $customParams = $tool->getCustomParamsAsArray();
if (!empty($customParams)) { if (!empty($customParams)) {
$substitutables = ImsLti::getSubstitutableParams($user, $course, $session);
$variables = array_keys($substitutables);
foreach ($customParams as $customKey => $customValue) {
if (in_array($customValue, $variables)) {
$substitutableValue = $substitutables[$customValue];
$substitutedValue = '';
if (is_array($substitutableValue)) {
$substitutableValue = current($substitutableValue);
if (array_key_exists($substitutableValue, $jwtContent)) {
$substitutedValue = $jwtContent[$substitutableValue];
}
} elseif ($substitutableValue !== false) {
$substitutedValue = $substitutableValue;
}
$customParams[$customKey] = $substitutedValue;
}
}
$jwtContent['https://purl.imsglobal.org/spec/lti/claim/custom'] = $customParams; $jwtContent['https://purl.imsglobal.org/spec/lti/claim/custom'] = $customParams;
} }

Loading…
Cancel
Save