first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,147 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains a class definition for the Context Memberships resource
*
* @package ltiservice_memberships
* @copyright 2015 Vital Source Technologies http://vitalsource.com
* @author Stephen Vickers
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace ltiservice_memberships\local\resources;
use mod_lti\local\ltiservice\resource_base;
use ltiservice_memberships\local\service\memberships;
use core_availability\info_module;
defined('MOODLE_INTERNAL') || die();
/**
* A resource implementing Context Memberships.
*
* @package ltiservice_memberships
* @since Moodle 3.0
* @copyright 2015 Vital Source Technologies http://vitalsource.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class contextmemberships extends resource_base {
/**
* Class constructor.
*
* @param \ltiservice_memberships\local\service\memberships $service Service instance
*/
public function __construct($service) {
parent::__construct($service);
$this->id = 'ToolProxyBindingMemberships';
$this->template = '/{context_type}/{context_id}/bindings/{tool_code}/memberships';
$this->variables[] = 'ToolProxyBinding.memberships.url';
$this->formats[] = 'application/vnd.ims.lis.v2.membershipcontainer+json';
$this->formats[] = 'application/vnd.ims.lti-nrps.v2.membershipcontainer+json';
$this->methods[] = self::HTTP_GET;
}
/**
* Execute the request for this resource.
*
* @param \mod_lti\local\ltiservice\response $response Response object for this request.
*/
public function execute($response) {
global $DB;
$params = $this->parse_template();
$role = optional_param('role', '', PARAM_TEXT);
$limitnum = optional_param('limit', 0, PARAM_INT);
$limitfrom = optional_param('from', 0, PARAM_INT);
$linkid = optional_param('rlid', '', PARAM_TEXT);
$lti = null;
$modinfo = null;
if ($limitnum <= 0) {
$limitfrom = 0;
}
try {
if (!$this->check_tool($params['tool_code'], $response->get_request_data(),
array(memberships::SCOPE_MEMBERSHIPS_READ))) {
throw new \Exception(null, 401);
}
if (!($course = $DB->get_record('course', array('id' => $params['context_id']), 'id,shortname,fullname',
IGNORE_MISSING))) {
throw new \Exception("Not Found: Course {$params['context_id']} doesn't exist", 404);
}
if (!$this->get_service()->is_allowed_in_context($params['tool_code'], $course->id)) {
throw new \Exception(null, 404);
}
if (!($context = \context_course::instance($course->id))) {
throw new \Exception("Not Found: Course instance {$course->id} doesn't exist", 404);
}
if (!empty($linkid)) {
if (!($lti = $DB->get_record('lti', array('id' => $linkid), 'id,course,typeid,servicesalt', IGNORE_MISSING))) {
throw new \Exception("Not Found: LTI link {$linkid} doesn't exist", 404);
}
$modinfo = get_fast_modinfo($course);
$cm = get_coursemodule_from_instance('lti', $linkid, $lti->course, false, MUST_EXIST);
$cm = $modinfo->get_cm($cm->id);
$modinfo = new info_module($cm);
if ($modinfo->is_available_for_all()) {
$modinfo = null;
}
}
$json = $this->get_service()->get_members_json($this, $context, $course, $role, $limitfrom, $limitnum, $lti,
$modinfo, $response);
$response->set_body($json);
} catch (\Exception $e) {
$response->set_code($e->getCode());
$response->set_reason($e->getMessage());
}
}
/**
* Parse a value for custom parameter substitution variables.
*
* @param string $value String to be parsed
*
* @return string
*/
public function parse_value($value) {
global $COURSE, $DB;
if (strpos($value, '$ToolProxyBinding.memberships.url') !== false) {
if ($COURSE->id === SITEID) {
$this->params['context_type'] = 'Group';
} else {
$this->params['context_type'] = 'CourseSection';
}
$this->params['context_id'] = $COURSE->id;
if ($tool = $this->get_service()->get_type()) {
$this->params['tool_code'] = $tool->id;
}
$value = str_replace('$ToolProxyBinding.memberships.url', parent::get_endpoint(), $value);
}
return $value;
}
}
@@ -0,0 +1,153 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains a class definition for the Link Memberships resource
*
* @package ltiservice_memberships
* @copyright 2015 Vital Source Technologies http://vitalsource.com
* @author Stephen Vickers
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace ltiservice_memberships\local\resources;
use mod_lti\local\ltiservice\resource_base;
use ltiservice_memberships\local\service\memberships;
use core_availability\info_module;
defined('MOODLE_INTERNAL') || die();
/**
* A resource implementing Link Memberships.
* The link membership is no longer defined in the published
* version of the LTI specification. It is replaced by the
* rlid parameter in the context membership URL.
*
* @package ltiservice_memberships
* @since Moodle 3.0
* @copyright 2015 Vital Source Technologies http://vitalsource.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class linkmemberships extends resource_base {
/**
* Class constructor.
*
* @param \ltiservice_memberships\local\service\memberships $service Service instance
*/
public function __construct($service) {
parent::__construct($service);
$this->id = 'LtiLinkMemberships';
$this->template = '/links/{link_id}/memberships';
$this->variables[] = 'LtiLink.memberships.url';
$this->formats[] = 'application/vnd.ims.lis.v2.membershipcontainer+json';
$this->methods[] = 'GET';
}
/**
* Execute the request for this resource.
*
* @param \mod_lti\local\ltiservice\response $response Response object for this request.
*/
public function execute($response) {
global $DB;
$params = $this->parse_template();
$linkid = $params['link_id'];
$role = optional_param('role', '', PARAM_TEXT);
$limitnum = optional_param('limit', 0, PARAM_INT);
$limitfrom = optional_param('from', 0, PARAM_INT);
if ($limitnum <= 0) {
$limitfrom = 0;
}
if (empty($linkid)) {
$response->set_code(404);
return;
}
if (!($lti = $DB->get_record('lti', array('id' => $linkid), 'id,course,typeid,servicesalt', IGNORE_MISSING))) {
$response->set_code(404);
return;
}
if (!$this->check_tool($lti->typeid, $response->get_request_data(), array(memberships::SCOPE_MEMBERSHIPS_READ))) {
$response->set_code(403);
return;
}
if (!($course = $DB->get_record('course', array('id' => $lti->course), 'id', IGNORE_MISSING))) {
$response->set_code(404);
return;
}
if (!($context = \context_course::instance($lti->course))) {
$response->set_code(404);
return;
}
$modinfo = get_fast_modinfo($course);
$cm = get_coursemodule_from_instance('lti', $linkid, $lti->course, false, MUST_EXIST);
$cm = $modinfo->get_cm($cm->id);
$info = new info_module($cm);
if ($info->is_available_for_all()) {
$info = null;
}
$json = $this->get_service()->get_members_json($this, $context, $course, $role,
$limitfrom, $limitnum, $lti, $info, $response);
$response->set_content_type($this->formats[0]);
$response->set_body($json);
}
/**
* get permissions from the config of the tool for that resource
*
* @param string $typeid
*
* @return array with the permissions related to this resource by the $lti_type or null if none.
*/
public function get_permissions($typeid) {
$tool = lti_get_type_type_config($typeid);
if ($tool->memberships == '1') {
return array('ToolProxyBinding.memberships.url:get');
} else {
return array();
}
}
/**
* Parse a value for custom parameter substitution variables.
*
* @param string $value String to be parsed
*
* @return string
*/
public function parse_value($value) {
if (strpos($value, '$LtiLink.memberships.url') !== false) {
$id = optional_param('id', 0, PARAM_INT); // Course Module ID.
if (!empty($id)) {
$cm = get_coursemodule_from_id('lti', $id, 0, false, MUST_EXIST);
$this->params['link_id'] = $cm->instance;
}
$value = str_replace('$LtiLink.memberships.url', parent::get_endpoint(), $value);
}
return $value;
}
}
@@ -0,0 +1,579 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains a class definition for the Memberships service
*
* @package ltiservice_memberships
* @copyright 2015 Vital Source Technologies http://vitalsource.com
* @author Stephen Vickers
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace ltiservice_memberships\local\service;
defined('MOODLE_INTERNAL') || die();
/**
* A service implementing Memberships.
*
* @package ltiservice_memberships
* @since Moodle 3.0
* @copyright 2015 Vital Source Technologies http://vitalsource.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class memberships extends \mod_lti\local\ltiservice\service_base {
/** Default prefix for context-level roles */
const CONTEXT_ROLE_PREFIX = 'http://purl.imsglobal.org/vocab/lis/v2/membership#';
/** Context-level role for Instructor */
const CONTEXT_ROLE_INSTRUCTOR = 'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor';
/** Context-level role for Learner */
const CONTEXT_ROLE_LEARNER = 'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner';
/** Capability used to identify Instructors */
const INSTRUCTOR_CAPABILITY = 'moodle/course:manageactivities';
/** Always include field */
const ALWAYS_INCLUDE_FIELD = 1;
/** Allow the instructor to decide if included */
const DELEGATE_TO_INSTRUCTOR = 2;
/** Instructor chose to include field */
const INSTRUCTOR_INCLUDED = 1;
/** Instructor delegated and approved for include */
const INSTRUCTOR_DELEGATE_INCLUDED = array(self::DELEGATE_TO_INSTRUCTOR && self::INSTRUCTOR_INCLUDED);
/** Scope for reading membership data */
const SCOPE_MEMBERSHIPS_READ = 'https://purl.imsglobal.org/spec/lti-nrps/scope/contextmembership.readonly';
/**
* Class constructor.
*/
public function __construct() {
parent::__construct();
$this->id = 'memberships';
$this->name = get_string($this->get_component_id(), $this->get_component_id());
}
/**
* Get the resources for this service.
*
* @return array
*/
public function get_resources() {
if (empty($this->resources)) {
$this->resources = array();
$this->resources[] = new \ltiservice_memberships\local\resources\contextmemberships($this);
$this->resources[] = new \ltiservice_memberships\local\resources\linkmemberships($this);
}
return $this->resources;
}
/**
* Get the scope(s) permitted for the tool relevant to this service.
*
* @return array
*/
public function get_permitted_scopes() {
$scopes = array();
$ok = !empty($this->get_type());
if ($ok && isset($this->get_typeconfig()[$this->get_component_id()]) &&
($this->get_typeconfig()[$this->get_component_id()] == parent::SERVICE_ENABLED)) {
$scopes[] = self::SCOPE_MEMBERSHIPS_READ;
}
return $scopes;
}
/**
* Get the scope(s) defined by this service.
*
* @return array
*/
public function get_scopes() {
return [self::SCOPE_MEMBERSHIPS_READ];
}
/**
* Get the JSON for members.
*
* @param \mod_lti\local\ltiservice\resource_base $resource Resource handling the request
* @param \context_course $context Course context
* @param string $contextid Course ID
* @param object $tool Tool instance object
* @param string $role User role requested (empty if none)
* @param int $limitfrom Position of first record to be returned
* @param int $limitnum Maximum number of records to be returned
* @param object $lti LTI instance record
* @param \core_availability\info_module $info Conditional availability information
* for LTI instance (null if context-level request)
*
* @return string
* @deprecated since Moodle 3.7 MDL-62599 - please do not use this function any more.
* @see memberships::get_members_json($resource, $context, $course, $role, $limitfrom, $limitnum, $lti, $info, $response)
*/
public static function get_users_json($resource, $context, $contextid, $tool, $role, $limitfrom, $limitnum, $lti, $info) {
global $DB;
debugging('get_users_json() has been deprecated, ' .
'please use memberships::get_members_json() instead.', DEBUG_DEVELOPER);
$course = $DB->get_record('course', array('id' => $contextid), 'id,shortname,fullname', IGNORE_MISSING);
$memberships = new memberships();
$memberships->check_tool($tool->id, null, array(self::SCOPE_MEMBERSHIPS_READ));
$response = new \mod_lti\local\ltiservice\response();
$json = $memberships->get_members_json($resource, $context, $course, $role, $limitfrom, $limitnum, $lti, $info, $response);
return $json;
}
/**
* Get the JSON for members.
*
* @param \mod_lti\local\ltiservice\resource_base $resource Resource handling the request
* @param \context_course $context Course context
* @param \course $course Course
* @param string $role User role requested (empty if none)
* @param int $limitfrom Position of first record to be returned
* @param int $limitnum Maximum number of records to be returned
* @param object $lti LTI instance record
* @param \core_availability\info_module $info Conditional availability information
* for LTI instance (null if context-level request)
* @param \mod_lti\local\ltiservice\response $response Response object for the request
*
* @return string
*/
public function get_members_json($resource, $context, $course, $role, $limitfrom, $limitnum, $lti, $info, $response) {
$withcapability = '';
$exclude = array();
if (!empty($role)) {
if ((strpos($role, 'http://') !== 0) && (strpos($role, 'https://') !== 0)) {
$role = self::CONTEXT_ROLE_PREFIX . $role;
}
if ($role === self::CONTEXT_ROLE_INSTRUCTOR) {
$withcapability = self::INSTRUCTOR_CAPABILITY;
} else if ($role === self::CONTEXT_ROLE_LEARNER) {
$exclude = array_keys(get_enrolled_users($context, self::INSTRUCTOR_CAPABILITY, 0, 'u.id',
null, null, null, true));
}
}
$users = get_enrolled_users($context, $withcapability, 0, 'u.*', null, 0, 0, true);
if (($response->get_accept() === 'application/vnd.ims.lti-nrps.v2.membershipcontainer+json') ||
(($response->get_accept() !== 'application/vnd.ims.lis.v2.membershipcontainer+json') &&
($this->get_type()->ltiversion === LTI_VERSION_1P3))) {
$json = $this->users_to_json($resource, $users, $course, $exclude, $limitfrom, $limitnum, $lti, $info, $response);
} else {
$json = $this->users_to_jsonld($resource, $users, $course->id, $exclude, $limitfrom, $limitnum, $lti, $info, $response);
}
return $json;
}
/**
* Get the JSON-LD representation of the users.
*
* Note that when a limit is set and the exclude array is not empty, then the number of memberships
* returned may be less than the limit.
*
* @param \mod_lti\local\ltiservice\resource_base $resource Resource handling the request
* @param array $users Array of user records
* @param string $contextid Course ID
* @param array $exclude Array of user records to be excluded from the response
* @param int $limitfrom Position of first record to be returned
* @param int $limitnum Maximum number of records to be returned
* @param object $lti LTI instance record
* @param \core_availability\info_module $info Conditional availability information
* for LTI instance (null if context-level request)
* @param \mod_lti\local\ltiservice\response $response Response object for the request
*
* @return string
*/
private function users_to_jsonld($resource, $users, $contextid, $exclude, $limitfrom, $limitnum,
$lti, $info, $response) {
global $DB;
$tool = $this->get_type();
$toolconfig = $this->get_typeconfig();
$arrusers = [
'@context' => 'http://purl.imsglobal.org/ctx/lis/v2/MembershipContainer',
'@type' => 'Page',
'@id' => $resource->get_endpoint(),
];
$arrusers['pageOf'] = [
'@type' => 'LISMembershipContainer',
'membershipSubject' => [
'@type' => 'Context',
'contextId' => $contextid,
'membership' => []
]
];
$enabledcapabilities = lti_get_enabled_capabilities($tool);
$islti2 = $tool->toolproxyid > 0;
$n = 0;
$more = false;
foreach ($users as $user) {
if (in_array($user->id, $exclude)) {
continue;
}
if (!empty($info) && !$info->is_user_visible($info->get_course_module(), $user->id)) {
continue;
}
$n++;
if ($limitnum > 0) {
if ($n <= $limitfrom) {
continue;
}
if (count($arrusers['pageOf']['membershipSubject']['membership']) >= $limitnum) {
$more = true;
break;
}
}
$member = new \stdClass();
$member->{"@type" } = 'LISPerson';
$membership = new \stdClass();
$membership->status = 'Active';
$membership->role = explode(',', lti_get_ims_role($user->id, null, $contextid, true));
$instanceconfig = null;
if (!is_null($lti)) {
$instanceconfig = lti_get_type_config_from_instance($lti->id);
}
$isallowedlticonfig = self::is_allowed_field_set($toolconfig, $instanceconfig,
['name' => 'sendname', 'email' => 'sendemailaddr']);
$includedcapabilities = [
'User.id' => ['type' => 'id',
'member.field' => 'userId',
'source.value' => $user->id],
'Person.sourcedId' => ['type' => 'id',
'member.field' => 'sourcedId',
'source.value' => format_string($user->idnumber)],
'Person.name.full' => ['type' => 'name',
'member.field' => 'name',
'source.value' => format_string("{$user->firstname} {$user->lastname}")],
'Person.name.given' => ['type' => 'name',
'member.field' => 'givenName',
'source.value' => format_string($user->firstname)],
'Person.name.family' => ['type' => 'name',
'member.field' => 'familyName',
'source.value' => format_string($user->lastname)],
'Person.email.primary' => ['type' => 'email',
'member.field' => 'email',
'source.value' => format_string($user->email)],
'User.username' => ['type' => 'name',
'member.field' => 'ext_user_username',
'source.value' => format_string($user->username)]
];
if (!is_null($lti)) {
$message = new \stdClass();
$message->message_type = 'basic-lti-launch-request';
$conditions = array('courseid' => $contextid, 'itemtype' => 'mod',
'itemmodule' => 'lti', 'iteminstance' => $lti->id);
if (!empty($lti->servicesalt) && $DB->record_exists('grade_items', $conditions)) {
$message->lis_result_sourcedid = json_encode(lti_build_sourcedid($lti->id,
$user->id,
$lti->servicesalt,
$lti->typeid));
// Not per specification but added to comply with earlier version of the service.
$member->resultSourcedId = $message->lis_result_sourcedid;
}
$membership->message = [$message];
}
foreach ($includedcapabilities as $capabilityname => $capability) {
if ($islti2) {
if (in_array($capabilityname, $enabledcapabilities)) {
$member->{$capability['member.field']} = $capability['source.value'];
}
} else {
if (($capability['type'] === 'id')
|| ($capability['type'] === 'name' && $isallowedlticonfig['name'])
|| ($capability['type'] === 'email' && $isallowedlticonfig['email'])) {
$member->{$capability['member.field']} = $capability['source.value'];
}
}
}
$membership->member = $member;
$arrusers['pageOf']['membershipSubject']['membership'][] = $membership;
}
if ($more) {
$nextlimitfrom = $limitfrom + $limitnum;
$nextpage = "{$resource->get_endpoint()}?limit={$limitnum}&from={$nextlimitfrom}";
if (!is_null($lti)) {
$nextpage .= "&rlid={$lti->id}";
}
$arrusers['nextPage'] = $nextpage;
}
$response->set_content_type('application/vnd.ims.lis.v2.membershipcontainer+json');
return json_encode($arrusers);
}
/**
* Get the NRP service JSON representation of the users.
*
* Note that when a limit is set and the exclude array is not empty, then the number of memberships
* returned may be less than the limit.
*
* @param \mod_lti\local\ltiservice\resource_base $resource Resource handling the request
* @param array $users Array of user records
* @param \course $course Course
* @param array $exclude Array of user records to be excluded from the response
* @param int $limitfrom Position of first record to be returned
* @param int $limitnum Maximum number of records to be returned
* @param object $lti LTI instance record
* @param \core_availability\info_module $info Conditional availability information for LTI instance
* @param \mod_lti\local\ltiservice\response $response Response object for the request
*
* @return string
*/
private function users_to_json($resource, $users, $course, $exclude, $limitfrom, $limitnum,
$lti, $info, $response) {
global $DB, $CFG;
$tool = $this->get_type();
$toolconfig = $this->get_typeconfig();
$context = new \stdClass();
$context->id = $course->id;
$context->label = trim(html_to_text($course->shortname, 0));
$context->title = trim(html_to_text($course->fullname, 0));
$arrusers = [
'id' => $resource->get_endpoint(),
'context' => $context,
'members' => []
];
$islti2 = $tool->toolproxyid > 0;
$n = 0;
$more = false;
foreach ($users as $user) {
if (in_array($user->id, $exclude)) {
continue;
}
if (!empty($info) && !$info->is_user_visible($info->get_course_module(), $user->id)) {
continue;
}
$n++;
if ($limitnum > 0) {
if ($n <= $limitfrom) {
continue;
}
if (count($arrusers['members']) >= $limitnum) {
$more = true;
break;
}
}
$member = new \stdClass();
$member->status = 'Active';
$member->roles = explode(',', lti_get_ims_role($user->id, null, $course->id, true));
$instanceconfig = null;
if (!is_null($lti)) {
$instanceconfig = lti_get_type_config_from_instance($lti->id);
}
if (!$islti2) {
$isallowedlticonfig = self::is_allowed_field_set($toolconfig, $instanceconfig,
['name' => 'sendname', 'givenname' => 'sendname', 'familyname' => 'sendname',
'email' => 'sendemailaddr']);
} else {
$isallowedlticonfig = self::is_allowed_capability_set($tool,
['name' => 'Person.name.full', 'givenname' => 'Person.name.given',
'familyname' => 'Person.name.family', 'email' => 'Person.email.primary']);
}
$includedcapabilities = [
'User.id' => ['type' => 'id',
'member.field' => 'user_id',
'source.value' => $user->id],
'Person.sourcedId' => ['type' => 'id',
'member.field' => 'lis_person_sourcedid',
'source.value' => format_string($user->idnumber)],
'Person.name.full' => ['type' => 'name',
'member.field' => 'name',
'source.value' => format_string("{$user->firstname} {$user->lastname}")],
'Person.name.given' => ['type' => 'givenname',
'member.field' => 'given_name',
'source.value' => format_string($user->firstname)],
'Person.name.family' => ['type' => 'familyname',
'member.field' => 'family_name',
'source.value' => format_string($user->lastname)],
'Person.email.primary' => ['type' => 'email',
'member.field' => 'email',
'source.value' => format_string($user->email)],
'User.username' => ['type' => 'name',
'member.field' => 'ext_user_username',
'source.value' => format_string($user->username)],
];
if (!is_null($lti)) {
$message = new \stdClass();
$message->{'https://purl.imsglobal.org/spec/lti/claim/message_type'} = 'LtiResourceLinkRequest';
$conditions = array('courseid' => $course->id, 'itemtype' => 'mod',
'itemmodule' => 'lti', 'iteminstance' => $lti->id);
if (!empty($lti->servicesalt) && $DB->record_exists('grade_items', $conditions)) {
$basicoutcome = new \stdClass();
$basicoutcome->lis_result_sourcedid = json_encode(lti_build_sourcedid($lti->id,
$user->id,
$lti->servicesalt,
$lti->typeid));
// Add outcome service URL.
$serviceurl = new \moodle_url('/mod/lti/service.php');
$serviceurl = $serviceurl->out();
$forcessl = false;
if (!empty($CFG->mod_lti_forcessl)) {
$forcessl = true;
}
if ((isset($toolconfig['forcessl']) && ($toolconfig['forcessl'] == '1')) or $forcessl) {
$serviceurl = lti_ensure_url_is_https($serviceurl);
}
$basicoutcome->lis_outcome_service_url = $serviceurl;
$message->{'https://purl.imsglobal.org/spec/lti-bo/claim/basicoutcome'} = $basicoutcome;
}
$member->message = [$message];
}
foreach ($includedcapabilities as $capabilityname => $capability) {
if (($capability['type'] === 'id') || $isallowedlticonfig[$capability['type']]) {
$member->{$capability['member.field']} = $capability['source.value'];
}
}
$arrusers['members'][] = $member;
}
if ($more) {
$nextlimitfrom = $limitfrom + $limitnum;
$nextpage = "{$resource->get_endpoint()}?limit={$limitnum}&from={$nextlimitfrom}";
if (!is_null($lti)) {
$nextpage .= "&rlid={$lti->id}";
}
$response->add_additional_header("Link: <{$nextpage}>; rel=\"next\"");
}
$response->set_content_type('application/vnd.ims.lti-nrps.v2.membershipcontainer+json');
return json_encode($arrusers);
}
/**
* Determines whether a user attribute may be used as part of LTI membership
* @param array $toolconfig Tool config
* @param object $instanceconfig Tool instance config
* @param array $fields Set of fields to return if allowed or not
* @return array Verification which associates an attribute with a boolean (allowed or not)
*/
private static function is_allowed_field_set($toolconfig, $instanceconfig, $fields) {
$isallowedstate = [];
foreach ($fields as $key => $field) {
$allowed = isset($toolconfig[$field]) && (self::ALWAYS_INCLUDE_FIELD == $toolconfig[$field]);
if (!$allowed && isset($toolconfig[$field]) && (self::DELEGATE_TO_INSTRUCTOR == $toolconfig[$field]) &&
!is_null($instanceconfig)) {
$allowed = isset($instanceconfig->{"lti_{$field}"}) &&
($instanceconfig->{"lti_{$field}"} == self::INSTRUCTOR_INCLUDED);
}
$isallowedstate[$key] = $allowed;
}
return $isallowedstate;
}
/**
* Adds form elements for membership add/edit page.
*
* @param \MoodleQuickForm $mform
*/
public function get_configuration_options(&$mform) {
$elementname = $this->get_component_id();
$options = [
get_string('notallow', $this->get_component_id()),
get_string('allow', $this->get_component_id())
];
$mform->addElement('select', $elementname, get_string($elementname, $this->get_component_id()), $options);
$mform->setType($elementname, 'int');
$mform->setDefault($elementname, 0);
$mform->addHelpButton($elementname, $elementname, $this->get_component_id());
}
/**
* Return an array of key/values to add to the launch parameters.
*
* @param string $messagetype 'basic-lti-launch-request' or 'ContentItemSelectionRequest'.
* @param string $courseid The course id.
* @param string $user The user id.
* @param string $typeid The tool lti type id.
* @param string $modlti The id of the lti activity.
*
* The type is passed to check the configuration
* and not return parameters for services not used.
*
* @return array of key/value pairs to add as launch parameters.
*/
public function get_launch_parameters($messagetype, $courseid, $user, $typeid, $modlti = null) {
global $COURSE;
$launchparameters = array();
$tool = lti_get_type_type_config($typeid);
if (isset($tool->{$this->get_component_id()})) {
if ($tool->{$this->get_component_id()} == parent::SERVICE_ENABLED && $this->is_used_in_context($typeid, $courseid)) {
$launchparameters['context_memberships_url'] = '$ToolProxyBinding.memberships.url';
$launchparameters['context_memberships_v2_url'] = '$ToolProxyBinding.memberships.url';
$launchparameters['context_memberships_versions'] = '1.0,2.0';
}
}
return $launchparameters;
}
/**
* Return an array of key/claim mapping allowing LTI 1.1 custom parameters
* to be transformed to LTI 1.3 claims.
*
* @return array Key/value pairs of params to claim mapping.
*/
public function get_jwt_claim_mappings(): array {
return [
'custom_context_memberships_v2_url' => [
'suffix' => 'nrps',
'group' => 'namesroleservice',
'claim' => 'context_memberships_url',
'isarray' => false
],
'custom_context_memberships_versions' => [
'suffix' => 'nrps',
'group' => 'namesroleservice',
'claim' => 'service_versions',
'isarray' => true
]
];
}
}
@@ -0,0 +1,114 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Privacy Subsystem implementation for ltiservice_memberships.
*
* @package ltiservice_memberships
* @copyright 2018 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace ltiservice_memberships\privacy;
use \core_privacy\local\metadata\collection;
use \core_privacy\local\request\contextlist;
use \core_privacy\local\request\approved_contextlist;
use \core_privacy\local\request\userlist;
use \core_privacy\local\request\approved_userlist;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for ltiservice_memberships.
*
* @copyright 2018 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements
\core_privacy\local\metadata\provider,
\core_privacy\local\request\core_userlist_provider,
\core_privacy\local\request\plugin\provider {
/**
* Returns meta data about this system.
*
* @param collection $collection The initialised collection to add items to.
* @return collection A listing of user data stored through this system.
*/
public static function get_metadata(collection $collection): collection {
$collection->link_external_location('External LTI provider.', [
'userid' => 'privacy:metadata:userid',
'useridnumber' => 'privacy:metadata:useridnumber',
'fullname' => 'privacy:metadata:fullname',
'firstname' => 'privacy:metadata:firstname',
'lastname' => 'privacy:metadata:lastname',
'email' => 'privacy:metadata:email'
], 'privacy:metadata:externalpurpose');
return $collection;
}
/**
* Get the list of contexts that contain user information for the specified user.
*
* @param int $userid The user to search.
* @return contextlist The contextlist containing the list of contexts used in this plugin.
*/
public static function get_contexts_for_userid(int $userid): contextlist {
return new contextlist();
}
/**
* Get the list of users who have data within a context.
*
* @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination.
*/
public static function get_users_in_context(userlist $userlist) {
}
/**
* Export all user data for the specified user, in the specified contexts.
*
* @param approved_contextlist $contextlist The approved contexts to export information for.
*/
public static function export_user_data(approved_contextlist $contextlist) {
}
/**
* Delete all user data which matches the specified context.
*
* @param \context $context A user context.
*/
public static function delete_data_for_all_users_in_context(\context $context) {
}
/**
* Delete multiple users within a single context.
*
* @param approved_userlist $userlist The approved context and user information to delete information for.
*/
public static function delete_data_for_users(approved_userlist $userlist) {
}
/**
* Delete all user data for the specified user, in the specified contexts.
*
* @param approved_contextlist $contextlist The approved contexts and user information to delete information for.
*/
public static function delete_data_for_user(approved_contextlist $contextlist) {
}
}
@@ -0,0 +1,37 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Strings for component 'ltiservice_memberships', language 'en'
*
* @package ltiservice_memberships
* @copyright 2015 Vital Source Technologies http://vitalsource.com
* @author Stephen Vickers
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['allow'] = 'Use this service to retrieve members\' information as per privacy settings';
$string['ltiservice_memberships'] = 'IMS LTI Names and Role Provisioning';
$string['ltiservice_memberships_help'] = 'Allow the tool to retrieve members\' info from the course using the IMS LTI Names and Role Provisioning Service. The privacy settings will apply. For course-level requests these will be based on the tool configuration settings. If you wish to always send such details, do not delegate the choice to teachers. Link-level requests will always use the privacy settings which apply to the link.';
$string['notallow'] = 'Do not use this service';
$string['pluginname'] = 'Names and Role Provisioning LTI Service';
$string['privacy:metadata:email'] = 'The email of the user using the LTI consumer.';
$string['privacy:metadata:externalpurpose'] = 'This information is sent to an external LTI provider.';
$string['privacy:metadata:firstname'] = 'The firstname of the user using the LTI consumer.';
$string['privacy:metadata:fullname'] = 'The fullname of the user using the LTI consumer.';
$string['privacy:metadata:lastname'] = 'The lastname of the user using the LTI consumer.';
$string['privacy:metadata:userid'] = 'The ID of the user using the LTI consumer.';
$string['privacy:metadata:useridnumber'] = 'The ID number of the user using the LTI consumer';
@@ -0,0 +1,52 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Unit tests for ltiservice_memberships privacy provider.
*
* @package ltiservice_memberships
* @copyright 2018 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace ltiservice_memberships\privacy;
defined('MOODLE_INTERNAL') || die();
use core_privacy\tests\provider_testcase;
/**
* Unit tests for ltiservice_memberships privacy provider.
*
* @copyright 2018 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider_test extends provider_testcase {
/**
* Basic setup for these tests.
*/
public function setUp(): void {
$this->resetAfterTest(true);
}
/**
* Test getting the context for the user ID related to this plugin.
*/
public function test_get_contexts_for_userid(): void {
$user = $this->getDataGenerator()->create_user();
$contextlist = \ltiservice_memberships\privacy\provider::get_contexts_for_userid($user->id);
$this->assertEmpty($contextlist);
}
}
+32
View File
@@ -0,0 +1,32 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Version information for the ltiservice_memberships service.
*
* @package ltiservice_memberships
* @copyright 2015 Vital Source Technologies http://vitalsource.com
* @author Stephen Vickers
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200;
$plugin->requires = 2024041600;
$plugin->component = 'ltiservice_memberships';