From 8628fa6fceed2fb1fa180ff83052980225bcd266 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Wed, 14 Nov 2018 15:42:47 -0500 Subject: [PATCH] LTI fix role_score_mentor param - refs BT#13469 --- plugin/ims_lti/ImsLtiPlugin.php | 32 +++++++++++++++++--------------- plugin/ims_lti/form.php | 4 ++-- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/plugin/ims_lti/ImsLtiPlugin.php b/plugin/ims_lti/ImsLtiPlugin.php index b51cfe9578..1f85736fe5 100644 --- a/plugin/ims_lti/ImsLtiPlugin.php +++ b/plugin/ims_lti/ImsLtiPlugin.php @@ -298,18 +298,22 @@ class ImsLtiPlugin extends Plugin */ public static function getUserRoles(User $user) { + if (DRH === $user->getStatus()) { + return 'urn:lti:role:ims/lis/Mentor'; + } + if ($user->getStatus() === INVITEE) { - return 'Learner/GuestLearner,Learner'; + return 'Learner,urn:lti:role:ims/lis/Learner/GuestLearner'; } if (!api_is_allowed_to_edit(false, true)) { - return 'Learner,Learner/Learner'; + return 'Learner'; } $roles = ['Instructor']; if (api_is_platform_admin_by_id($user->getId())) { - $roles[] = 'Administrator/SystemAdministrator'; + $roles[] = 'urn:lti:role:ims/lis/Administrator'; } return implode(',', $roles); @@ -331,24 +335,22 @@ class ImsLtiPlugin extends Plugin } /** - * @param Course $course - * @param Session|null $session + * @param User $currentUser * * @return string */ - public static function getRoleScopeMentor(Course $course, Session $session = null) + public static function getRoleScopeMentor(User $currentUser) { - $scope = []; - - if ($session) { - $students = $session->getUserCourseSubscriptionsByStatus($course, Session::STUDENT); - } else { - $students = $course->getStudents(); + if (DRH !== $currentUser->getStatus()) { + return ''; } - /** @var SessionRelCourseRelUser|CourseRelUser $subscription */ - foreach ($students as $subscription) { - $scope[] = self::generateToolUserId($subscription->getUser()->getId()); + $followedUsers = UserManager::get_users_followed_by_drh($currentUser->getId()); + + $scope = []; + + foreach ($followedUsers as $userInfo) { + $scope[] = self::generateToolUserId($userInfo['user_id']); } return implode(',', $scope); diff --git a/plugin/ims_lti/form.php b/plugin/ims_lti/form.php index 43cf8a3d8c..ded7e2a42b 100644 --- a/plugin/ims_lti/form.php +++ b/plugin/ims_lti/form.php @@ -89,8 +89,8 @@ if ($tool->isSharingEmail()) { $params['lis_person_contact_email_primary'] = $user->getEmail(); } -if (api_is_allowed_to_edit(false, true)) { - $scopeMentor = ImsLtiPlugin::getRoleScopeMentor($course, $session); +if (DRH === $user->getStatus()) { + $scopeMentor = ImsLtiPlugin::getRoleScopeMentor($user); if (!empty($scopeMentor)) { $params['role_scope_mentor'] = $scopeMentor;