MDL-53832 enrol_lti: Split launch and proxy registration end points

Original subtask: MDL-55752.
This commit is contained in:
John Okely 2016-08-30 11:24:14 +08:00
parent da65fcf027
commit 098ee549ee
7 changed files with 747 additions and 985 deletions

File diff suppressed because it is too large Load diff

View file

@ -71,7 +71,7 @@ class tool_provider extends ToolProvider\ToolProvider {
parent::__construct($dataconnector);
$this->baseUrl = $CFG->wwwroot;
$toolpath = helper::get_proxy_url($tool);
$toolpath = helper::get_launch_url($toolid);
$toolpath = $this->strip_base_url($toolpath);
$vendorid = $SITE->shortname;

View file

@ -53,11 +53,11 @@
<KEY NAME="toolid" TYPE="foreign" FIELDS="toolid" REFTABLE="enrol_lti_tools" REFFIELDS="id"/>
</KEYS>
</TABLE>
<TABLE NAME="enrol_lti_lti2_consumer" COMMENT="TODO">
<TABLE NAME="enrol_lti_lti2_consumer" COMMENT="LTI consumers interacting with moodle">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="11" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="name" TYPE="char" LENGTH="50" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="consumer_key256" TYPE="char" LENGTH="256" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="consumer_key256" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="consumer_key" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="secret" TYPE="char" LENGTH="1024" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="lti_version" TYPE="char" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
@ -69,76 +69,61 @@
<FIELD NAME="settings" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="protected" TYPE="int" LENGTH="1" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="enabled" TYPE="int" LENGTH="1" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="enable_from" TYPE="datetime" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="enable_until" TYPE="datetime" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="last_access" TYPE="datetime" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="created" TYPE="datetime" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="updated" TYPE="datetime" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="enable_from" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="enable_until" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="last_access" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="created" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="updated" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<!-- <KEY NAME="consumer_key256_uniq" TYPE="unique" FIELDS="consumer_key256"/> TODO We can't have unique 256... either no unique or 255 length -->
</KEYS>
<INDEXES>
<INDEX NAME="consumer_key256_uniq" UNIQUE="true" FIELDS="consumer_key256"/>
</INDEXES>
</TABLE>
<TABLE NAME="enrol_lti_lti2_tool_proxy" COMMENT="TODO">
<TABLE NAME="enrol_lti_lti2_tool_proxy" COMMENT="A tool proxy between moodle and a consumer">
<FIELDS>
<FIELD NAME="tool_proxy_pk" TYPE="int" LENGTH="11" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="id" TYPE="int" LENGTH="11" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="tool_proxy_id" TYPE="char" LENGTH="32" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="consumer_pk" TYPE="int" LENGTH="11" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="tool_proxy" TYPE="text" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="created" TYPE="datetime" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="updated" TYPE="datetime" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="created" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="updated" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="tool_proxy_pk"/>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="tool_proxy_id_uniq" TYPE="unique" FIELDS="tool_proxy_id"/>
<KEY NAME="consumer_pk" TYPE="foreign" FIELDS="consumer_pk" REFTABLE="enrol_lti_lti2_consumer" REFFIELDS="id"/>
</KEYS>
</TABLE>
<TABLE NAME="enrol_lti_item" COMMENT="TODO">
<TABLE NAME="enrol_lti_lti2_context" COMMENT="Information about a specific LTI contexts from the consumers">
<FIELDS>
<FIELD NAME="item_pk" TYPE="int" LENGTH="11" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="resource_link_pk" TYPE="int" LENGTH="11" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="item_title" TYPE="char" LENGTH="200" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="item_text" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="item_url" TYPE="char" LENGTH="200" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="max_rating" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="5" SEQUENCE="false"/>
<FIELD NAME="step" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" SEQUENCE="false"/>
<FIELD NAME="visible" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="created" TYPE="datetime" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="updated" TYPE="datetime" NOTNULL="true" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="item_pk"/>
<KEY NAME="resource_link_pk" TYPE="foreign" FIELDS="resource_link_pk" REFTABLE="enrol_lti_lti2_resource_link" REFFIELDS="id"/>
</KEYS>
</TABLE>
<TABLE NAME="enrol_lti_lti2_context" COMMENT="TODO">
<FIELDS>
<FIELD NAME="context_pk" TYPE="int" LENGTH="11" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="id" TYPE="int" LENGTH="11" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="consumer_pk" TYPE="int" LENGTH="11" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="lti_context_id" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="settings" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="created" TYPE="datetime" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="updated" TYPE="datetime" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="created" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="updated" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="context_pk"/>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="consumer_pk" TYPE="foreign" FIELDS="consumer_pk" REFTABLE="enrol_lti_lti2_consumer" REFFIELDS="id"/>
</KEYS>
</TABLE>
<TABLE NAME="enrol_lti_lti2_nonce" COMMENT="TODO">
<TABLE NAME="enrol_lti_lti2_nonce" COMMENT="Nonce used for authentication between moodle and a consumer">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="11" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="consumer_pk" TYPE="int" LENGTH="11" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="value" TYPE="char" LENGTH="32" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="expires" TYPE="datetime" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="expires" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="consumer_pk,value"/>
<KEY NAME="consumer_pk" TYPE="foreign" FIELDS="consumer_pk" REFTABLE="enrol_lti_lti2_consumer" REFFIELDS="id"/>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="consumer_pk" TYPE="foreign-unique" FIELDS="consumer_pk" REFTABLE="enrol_lti_lti2_consumer" REFFIELDS="id"/>
</KEYS>
</TABLE>
<TABLE NAME="enrol_lti_lti2_resource_link" COMMENT="TODO">
<TABLE NAME="enrol_lti_lti2_resource_link" COMMENT="Link from the consumer to the tool">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="11" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="context_pk" TYPE="int" LENGTH="11" NOTNULL="false" SEQUENCE="false"/>
@ -147,54 +132,43 @@
<FIELD NAME="settings" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="primary_resource_link_pk" TYPE="int" LENGTH="11" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="share_approved" TYPE="int" LENGTH="1" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="created" TYPE="datetime" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="updated" TYPE="datetime" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="created" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="updated" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="context_pk" TYPE="foreign" FIELDS="context_pk" REFTABLE="enrol_lti_lti2_context" REFFIELDS="context_pk"/>
<KEY NAME="context_pk" TYPE="foreign" FIELDS="context_pk" REFTABLE="enrol_lti_lti2_context" REFFIELDS="id"/>
<KEY NAME="primary_resource_link_pk" TYPE="foreign" FIELDS="primary_resource_link_pk" REFTABLE="enrol_lti_lti2_resource_link" REFFIELDS="id"/>
<KEY NAME="consumer_pk" TYPE="foreign" FIELDS="consumer_pk" REFTABLE="enrol_lti_lti2_consumer" REFFIELDS="id"/>
</KEYS>
<INDEXES>
<INDEX NAME="consumer_pk" UNIQUE="false" FIELDS="consumer_pk"/> <!-- TODO shouldn't this be foreign?? -->
</INDEXES>
</TABLE>
<TABLE NAME="enrol_lti_lti2_share_key" COMMENT="TODO">
<TABLE NAME="enrol_lti_lti2_share_key" COMMENT="Resource link share key">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="11" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="share_key_id" TYPE="char" LENGTH="32" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="resource_link_pk" TYPE="int" LENGTH="11" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="auto_approve" TYPE="int" LENGTH="1" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="expires" TYPE="datetime" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="expires" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="share_key_id"/>
<KEY NAME="resource_link_pk" TYPE="foreign" FIELDS="resource_link_pk" REFTABLE="enrol_lti_lti2_resource_link" REFFIELDS="id"/>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="share_key_id" TYPE="unique" FIELDS="share_key_id" />
<KEY NAME="resource_link_pk" TYPE="foreign-unique" FIELDS="resource_link_pk" REFTABLE="enrol_lti_lti2_resource_link" REFFIELDS="id"/>
</KEYS>
</TABLE>
<TABLE NAME="enrol_lti_lti2_user_result" COMMENT="TODO">
<TABLE NAME="enrol_lti_lti2_user_result" COMMENT="Results for each user for each resource link">
<FIELDS>
<FIELD NAME="user_pk" TYPE="int" LENGTH="11" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="id" TYPE="int" LENGTH="11" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="resource_link_pk" TYPE="int" LENGTH="11" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="lti_user_id" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="lti_result_sourcedid" TYPE="char" LENGTH="1024" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="created" TYPE="datetime" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="updated" TYPE="datetime" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="created" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="updated" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="user_pk"/>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="resource_link_pk" TYPE="foreign" FIELDS="resource_link_pk" REFTABLE="enrol_lti_lti2_resource_link" REFFIELDS="id"/>
</KEYS>
</TABLE>
<TABLE NAME="enrol_lti_rating" COMMENT="TODO">
<FIELDS>
<FIELD NAME="item_pk" TYPE="int" LENGTH="11" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="user_pk" TYPE="int" LENGTH="11" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="rating" TYPE="number" LENGTH="10" NOTNULL="true" SEQUENCE="false" DECIMALS="2"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="item_pk,user_pk"/>
<KEY NAME="item_pk" TYPE="foreign" FIELDS="item_pk" REFTABLE="enrol_lti_item" REFFIELDS="item_pk"/>
</KEYS>
</TABLE>
</TABLES>
</XMLDB>

View file

@ -37,7 +37,7 @@
* @return boolean
*/
function xmldb_enrol_lti_upgrade($oldversion) {
global $CFG, $DB;
global $DB;
$dbman = $DB->get_manager();
@ -49,7 +49,7 @@ function xmldb_enrol_lti_upgrade($oldversion) {
// Adding fields to table enrol_lti_lti2_consumer.
$table->add_field('id', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('name', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null);
$table->add_field('consumer_key256', XMLDB_TYPE_CHAR, '256', null, XMLDB_NOTNULL, null, null);
$table->add_field('consumer_key256', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
$table->add_field('consumer_key', XMLDB_TYPE_TEXT, null, null, null, null, null);
$table->add_field('secret', XMLDB_TYPE_CHAR, '1024', null, XMLDB_NOTNULL, null, null);
$table->add_field('lti_version', XMLDB_TYPE_CHAR, '10', null, null, null, null);
@ -61,15 +61,18 @@ function xmldb_enrol_lti_upgrade($oldversion) {
$table->add_field('settings', XMLDB_TYPE_TEXT, null, null, null, null, null);
$table->add_field('protected', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null);
$table->add_field('enabled', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null);
$table->add_field('enable_from', XMLDB_TYPE_DATETIME, null, null, null, null, null);
$table->add_field('enable_until', XMLDB_TYPE_DATETIME, null, null, null, null, null);
$table->add_field('last_access', XMLDB_TYPE_DATETIME, null, null, null, null, null);
$table->add_field('created', XMLDB_TYPE_DATETIME, null, null, XMLDB_NOTNULL, null, null);
$table->add_field('updated', XMLDB_TYPE_DATETIME, null, null, XMLDB_NOTNULL, null, null);
$table->add_field('enable_from', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
$table->add_field('enable_until', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
$table->add_field('last_access', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
$table->add_field('created', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('updated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
// Adding keys to table enrol_lti_lti2_consumer.
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
// Adding indexes to table enrol_lti_lti2_consumer.
$table->add_index('consumer_key256_uniq', XMLDB_INDEX_UNIQUE, array('consumer_key256'));
// Conditionally launch create table for enrol_lti_lti2_consumer.
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
@ -79,15 +82,15 @@ function xmldb_enrol_lti_upgrade($oldversion) {
$table = new xmldb_table('enrol_lti_lti2_tool_proxy');
// Adding fields to table enrol_lti_lti2_tool_proxy.
$table->add_field('tool_proxy_pk', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('id', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('tool_proxy_id', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null);
$table->add_field('consumer_pk', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, null, null);
$table->add_field('tool_proxy', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
$table->add_field('created', XMLDB_TYPE_DATETIME, null, null, XMLDB_NOTNULL, null, null);
$table->add_field('updated', XMLDB_TYPE_DATETIME, null, null, XMLDB_NOTNULL, null, null);
$table->add_field('created', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('updated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
// Adding keys to table enrol_lti_lti2_tool_proxy.
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('tool_proxy_pk'));
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('tool_proxy_id_uniq', XMLDB_KEY_UNIQUE, array('tool_proxy_id'));
$table->add_key('consumer_pk', XMLDB_KEY_FOREIGN, array('consumer_pk'), 'enrol_lti_lti2_consumer', array('id'));
@ -96,49 +99,19 @@ function xmldb_enrol_lti_upgrade($oldversion) {
$dbman->create_table($table);
}
// Define table enrol_lti_item to be created.
$table = new xmldb_table('enrol_lti_item');
// Adding fields to table enrol_lti_item.
$table->add_field('item_pk', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('resource_link_pk', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, null, null);
$table->add_field('item_title', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null);
$table->add_field('item_text', XMLDB_TYPE_TEXT, null, null, null, null, null);
$table->add_field('item_url', XMLDB_TYPE_CHAR, '200', null, null, null, null);
$table->add_field('max_rating', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '5');
$table->add_field('step', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1');
$table->add_field('visible', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0');
$table->add_field('created', XMLDB_TYPE_DATETIME, null, null, XMLDB_NOTNULL, null, null);
$table->add_field('updated', XMLDB_TYPE_DATETIME, null, null, XMLDB_NOTNULL, null, null);
// Adding keys to table enrol_lti_item.
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('item_pk'));
$table->add_key(
'resource_link_pk',
XMLDB_KEY_FOREIGN,
array('resource_link_pk'),
'enrol_lti_lti2_resource_link',
array('id')
);
// Conditionally launch create table for enrol_lti_item.
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
// Define table enrol_lti_lti2_context to be created.
$table = new xmldb_table('enrol_lti_lti2_context');
// Adding fields to table enrol_lti_lti2_context.
$table->add_field('context_pk', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('id', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('consumer_pk', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, null, null);
$table->add_field('lti_context_id', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
$table->add_field('settings', XMLDB_TYPE_TEXT, null, null, null, null, null);
$table->add_field('created', XMLDB_TYPE_DATETIME, null, null, XMLDB_NOTNULL, null, null);
$table->add_field('updated', XMLDB_TYPE_DATETIME, null, null, XMLDB_NOTNULL, null, null);
$table->add_field('created', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('updated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
// Adding keys to table enrol_lti_lti2_context.
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('context_pk'));
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('consumer_pk', XMLDB_KEY_FOREIGN, array('consumer_pk'), 'enrol_lti_lti2_consumer', array('id'));
// Conditionally launch create table for enrol_lti_lti2_context.
@ -150,13 +123,14 @@ function xmldb_enrol_lti_upgrade($oldversion) {
$table = new xmldb_table('enrol_lti_lti2_nonce');
// Adding fields to table enrol_lti_lti2_nonce.
$table->add_field('id', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('consumer_pk', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, null, null);
$table->add_field('value', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null);
$table->add_field('expires', XMLDB_TYPE_DATETIME, null, null, XMLDB_NOTNULL, null, null);
$table->add_field('expires', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
// Adding keys to table enrol_lti_lti2_nonce.
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('consumer_pk', 'value'));
$table->add_key('consumer_pk', XMLDB_KEY_FOREIGN, array('consumer_pk'), 'enrol_lti_lti2_consumer', array('id'));
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('consumer_pk', XMLDB_KEY_FOREIGN_UNIQUE, array('consumer_pk'), 'enrol_lti_lti2_consumer', array('id'));
// Conditionally launch create table for enrol_lti_lti2_nonce.
if (!$dbman->table_exists($table)) {
@ -174,22 +148,15 @@ function xmldb_enrol_lti_upgrade($oldversion) {
$table->add_field('settings', XMLDB_TYPE_TEXT, null, null, null, null, null);
$table->add_field('primary_resource_link_pk', XMLDB_TYPE_INTEGER, '11', null, null, null, null);
$table->add_field('share_approved', XMLDB_TYPE_INTEGER, '1', null, null, null, null);
$table->add_field('created', XMLDB_TYPE_DATETIME, null, null, XMLDB_NOTNULL, null, null);
$table->add_field('updated', XMLDB_TYPE_DATETIME, null, null, XMLDB_NOTNULL, null, null);
$table->add_field('created', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('updated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
// Adding keys to table enrol_lti_lti2_resource_link.
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('context_pk', XMLDB_KEY_FOREIGN, array('context_pk'), 'enrol_lti_lti2_context', array('context_pk'));
$table->add_key(
'primary_resource_link_pk',
XMLDB_KEY_FOREIGN,
array('primary_resource_link_pk'),
'enrol_lti_lti2_resource_link',
array('id')
);
// Adding indexes to table enrol_lti_lti2_resource_link.
$table->add_index('consumer_pk', XMLDB_INDEX_NOTUNIQUE, array('consumer_pk'));
$table->add_key('context_pk', XMLDB_KEY_FOREIGN, array('context_pk'), 'enrol_lti_lti2_context', array('id'));
$table->add_key('primary_resource_link_pk', XMLDB_KEY_FOREIGN, array('primary_resource_link_pk'),
'enrol_lti_lti2_resource_link', array('id'));
$table->add_key('consumer_pk', XMLDB_KEY_FOREIGN, array('consumer_pk'), 'enrol_lti_lti2_consumer', array('id'));
// Conditionally launch create table for enrol_lti_lti2_resource_link.
if (!$dbman->table_exists($table)) {
@ -200,20 +167,16 @@ function xmldb_enrol_lti_upgrade($oldversion) {
$table = new xmldb_table('enrol_lti_lti2_share_key');
// Adding fields to table enrol_lti_lti2_share_key.
$table->add_field('id', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('share_key_id', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null);
$table->add_field('resource_link_pk', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, null, null);
$table->add_field('auto_approve', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null);
$table->add_field('expires', XMLDB_TYPE_DATETIME, null, null, XMLDB_NOTNULL, null, null);
$table->add_field('expires', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
// Adding keys to table enrol_lti_lti2_share_key.
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('share_key_id'));
$table->add_key(
'resource_link_pk',
XMLDB_KEY_FOREIGN,
array('resource_link_pk'),
'enrol_lti_lti2_resource_link',
array('id')
);
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('share_key_id', XMLDB_KEY_UNIQUE, array('share_key_id'));
$table->add_key('resource_link_pk', XMLDB_KEY_FOREIGN_UNIQUE, array('resource_link_pk'), 'enrol_lti_lti2_resource_link', array('id'));
// Conditionally launch create table for enrol_lti_lti2_share_key.
if (!$dbman->table_exists($table)) {
@ -224,45 +187,23 @@ function xmldb_enrol_lti_upgrade($oldversion) {
$table = new xmldb_table('enrol_lti_lti2_user_result');
// Adding fields to table enrol_lti_lti2_user_result.
$table->add_field('user_pk', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('id', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('resource_link_pk', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, null, null);
$table->add_field('lti_user_id', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
$table->add_field('lti_result_sourcedid', XMLDB_TYPE_CHAR, '1024', null, XMLDB_NOTNULL, null, null);
$table->add_field('created', XMLDB_TYPE_DATETIME, null, null, XMLDB_NOTNULL, null, null);
$table->add_field('updated', XMLDB_TYPE_DATETIME, null, null, XMLDB_NOTNULL, null, null);
$table->add_field('created', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('updated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
// Adding keys to table enrol_lti_lti2_user_result.
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('user_pk'));
$table->add_key(
'resource_link_pk',
XMLDB_KEY_FOREIGN,
array('resource_link_pk'),
'enrol_lti_lti2_resource_link',
array('id')
);
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('resource_link_pk', XMLDB_KEY_FOREIGN, array('resource_link_pk'),
'enrol_lti_lti2_resource_link', array('id'));
// Conditionally launch create table for enrol_lti_lti2_user_result.
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
// Define table enrol_lti_rating to be created.
$table = new xmldb_table('enrol_lti_rating');
// Adding fields to table enrol_lti_rating.
$table->add_field('item_pk', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, null, null);
$table->add_field('user_pk', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, null, null);
$table->add_field('rating', XMLDB_TYPE_NUMBER, '10, 2', null, XMLDB_NOTNULL, null, null);
// Adding keys to table enrol_lti_rating.
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('item_pk', 'user_pk'));
$table->add_key('item_pk', XMLDB_KEY_FOREIGN, array('item_pk'), 'enrol_lti_item', array('item_pk'));
// Conditionally launch create table for enrol_lti_rating.
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
// Lti savepoint reached.
upgrade_plugin_savepoint(true, 2016052303, 'enrol', 'lti');
}

View file

@ -45,7 +45,7 @@ $PAGE->set_title(get_string('registration', 'enrol_lti'));
// If we do not compare with a shared secret, someone could very easily
// guess an id for the enrolment.
if (!\enrol_lti\helper::verify_proxy_token($toolid, $token)) {
throw new \moodle_exception('incorrecttoken', 'enrol_lti'); // TODO can we do an LTI error? Not really important as this bug will only occur if the url is wrong.
throw new \moodle_exception('incorrecttoken', 'enrol_lti');
}
$tool = \enrol_lti\helper::get_lti_tool($toolid);
@ -66,6 +66,14 @@ if ($tool->status != ENROL_INSTANCE_ENABLED) {
exit();
}
$messagetype = required_param('lti_message_type', PARAM_TEXT);
// Only accept proxy registration requests from this endpoint.
if ($messagetype != "ToolProxyRegistrationRequest") {
print_error('invalidrequest', 'enrol_lti');
exit();
}
$toolprovider = new \enrol_lti\tool_provider($toolid);
$toolprovider->handleRequest();
echo $OUTPUT->header();

View file

@ -400,7 +400,7 @@ class enrol_lti_data_connector_testcase extends advanced_testcase {
}
/**
* Test for data_connector::loadContext().
* Test for data_connector::saveContext().
*/
public function test_save_context() {
$dc = new data_connector();
@ -876,11 +876,6 @@ class enrol_lti_data_connector_testcase extends advanced_testcase {
// Save the nonce.
$this->assertTrue($dc->saveConsumerNonce($nonce));
// We should only be doing inserts and a consumer can only have one nonce record.
// So saving again the nonce without it getting cleaned up (by data_connector::loadConsumerNonce()) will throw an exception.
$this->expectException('dml_write_exception');
$this->assertTrue($dc->saveConsumerNonce($nonce));
}
/**

View file

@ -57,11 +57,12 @@ $consumerkey = required_param('oauth_consumer_key', PARAM_TEXT);
$ltiversion = optional_param('lti_version', null, PARAM_TEXT);
$messagetype = required_param('lti_message_type', PARAM_TEXT);
// Only accept launch requests from this old LTI endpoint.
// Only accept launch requests from this endpoint.
if ($messagetype != "basic-lti-launch-request") {
print_error('invalidrequest', 'enrol_lti');
exit();
}
// Special handling for LTIv1 launch requests.
if ($ltiversion === \IMSGlobal\LTI\ToolProvider\ToolProvider::LTI_VERSION1) {
$dataconnector = new \enrol_lti\data_connector();
@ -79,9 +80,9 @@ if ($ltiversion === \IMSGlobal\LTI\ToolProvider\ToolProvider::LTI_VERSION1) {
$consumer->protected = true;
$consumer->save();
}
}
$toolprovider = new \enrol_lti\tool_provider($toolid);
$toolprovider->handleRequest();
}
echo $OUTPUT->header();
echo $OUTPUT->footer();