Skip to content

Commit 1bd1cc5

Browse files
authored
Merge pull request #107 from turnitin/develop
Release v2021030201
2 parents c1b641f + 19e4dda commit 1bd1cc5

8 files changed

+103
-21
lines changed

CHANGELOG.md

+31
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
1+
### Date: 2021-March-02
2+
### Release: v2021030201
3+
4+
#### :zap: What's new
5+
6+
---
7+
8+
#### API URLs will self-correct when inputted incorrectly
9+
10+
When configuring the plug-in, the API URL used should end in /API. However, some users have copied just the first part of the URL into the field, which will cause the configuration to fail. We now proactively check for instances where the URL has not been configured correctly and self-correct them so that the configuration will succeed.
11+
12+
#### :wrench: Fixes and enhancements
13+
14+
---
15+
16+
#### Default value change for quizanswer filed in submissions table
17+
18+
We have updated the default value for a database field in the submissions table (quizanswer) from null to 0. This could potentially cause automatic integration problems. Thank you to OpenLMS for letting us know about the problem. It’s now been fixed.
19+
20+
#### Missing User ID - various fixes
21+
22+
We’ve performed a thorough investigation into an issue where Moodle does not pass a user ID to Turnitin, which can present in various ways. These include:
23+
24+
* The annotate PDF module attempts to save a submission for when a PDF is annotated.
25+
* If a student who has not accepted our EULA tries to view the inbox after submissions have begun but before the instructor has viewed it.
26+
* Text-submissions for group assignments would not save correctly if Turnitin was enabled after the submission was made.
27+
28+
All of these issues are fixed in this release.
29+
30+
---
31+
132
### Date: 2021-January-18
233
### Release: v2021011801
334

classes/request.class.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,6 @@ public function send_request($endpoint, $requestbody, $method, $requesttype = 'g
123123

124124
$tiiurl = $this->get_apiurl();
125125

126-
if ($requesttype === 'logging') {
127-
$tiiurl = str_replace('/api', '', $this->get_apiurl());
128-
}
129-
130126
if ($this->logger) {
131127
$this->logger->info('[' . $method . '] Request to: ' . $tiiurl . $endpoint);
132128
$this->logger->info('Headers: ', $this->headers);
@@ -244,7 +240,10 @@ public function send_request($endpoint, $requestbody, $method, $requesttype = 'g
244240
*/
245241
public function test_connection($apiurl, $apikey) {
246242

247-
$validurlregex = '/.+\.(turnitin\.com|turnitinuk\.com|turnitin\.dev|turnitin\.org|tii-sandbox\.com)\/api$/m';
243+
// Strip any trailing / chars from api url.
244+
$apiurl = rtrim($apiurl, '/');
245+
246+
$validurlregex = '/.+\.(turnitin\.com|turnitinuk\.com|turnitin\.dev|turnitin\.org|tii-sandbox\.com)(\/api)?$/m';
248247

249248
if (empty($apikey) || empty($apiurl)) {
250249
$data["connection_status"] = TURNITINSIM_HTTP_BAD_REQUEST;
@@ -260,6 +259,8 @@ public function test_connection($apiurl, $apikey) {
260259
return json_encode($data);
261260
}
262261

262+
$apiurl = str_replace("/api", '', $apiurl);
263+
263264
$this->set_apiurl($apiurl);
264265
$this->set_apikey($apikey);
265266
$this->set_headers();

classes/setup_form.class.php

+16-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,22 @@ public function save($data) {
171171
}
172172
}
173173

174-
$turnitinapiurl = (!empty($data->turnitinapiurl)) ? $data->turnitinapiurl : '';
174+
$validurlregexwithapi = '/.+\.(turnitin\.com|turnitinuk\.com|turnitin\.dev|turnitin\.org|tii-sandbox\.com)\/api$/m';
175+
176+
if ((!empty($data->turnitinapiurl))) {
177+
// Strip any trailing / chars from api url.
178+
$apiurl = rtrim($data->turnitinapiurl, '/');
179+
if (preg_match($validurlregexwithapi, $apiurl)) {
180+
$logger = new plagiarism_turnitinsim_logger();
181+
$logger->info('Stripping /api from Turnitin URL on save: ', array($apiurl));
182+
$turnitinapiurl = str_replace("/api", '', $apiurl);
183+
} else {
184+
$turnitinapiurl = $apiurl;
185+
}
186+
} else {
187+
$turnitinapiurl = '';
188+
}
189+
175190
$turnitinapikey = (!empty($data->turnitinapikey)) ? $data->turnitinapikey : '';
176191
$turnitinenablelogging = (!empty($data->turnitinenablelogging)) ? $data->turnitinenablelogging : 0;
177192
$turnitinenableremotelogging = (!empty($data->turnitinenableremotelogging)) ? $data->turnitinenableremotelogging : 0;

classes/user.class.php

+4
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ class plagiarism_turnitinsim_user {
7070
public function __construct($userid) {
7171
global $DB;
7272

73+
if (empty($userid)) {
74+
return;
75+
}
76+
7377
$this->set_userid($userid);
7478

7579
// If there is no user record then create one.

db/upgrade.php

+18-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
/**
2929
* Database upgrade script for plagiarism_turnitinsim component.
3030
*
31-
* @param int $oldversion The version that is currently installed.
31+
* @param int $oldversion The version that is currently installed. (The version being upgraded from)
3232
* @return bool true if upgrade was successful.
3333
* @throws ddl_exception
3434
* @throws ddl_table_missing_exception
@@ -304,5 +304,22 @@ function xmldb_plagiarism_turnitinsim_upgrade($oldversion) {
304304
upgrade_plugin_savepoint(true, 2020092301, 'plagiarism', 'turnitinsim');
305305
}
306306

307+
// Remove "/api" from the Turnitin URL as its been added to the endpoint constants.
308+
// Update field defaults for quizanswer to match install.xml.
309+
if ($oldversion < 2021030201) {
310+
(new handle_deprecation)->unset_turnitinsim_use();
311+
312+
$turnitinapiurl = get_config('plagiarism_turnitinsim', 'turnitinapiurl');
313+
314+
set_config('turnitinapiurl', str_replace("/api", '', $turnitinapiurl), 'plagiarism_turnitinsim');
315+
316+
$table = new xmldb_table('plagiarism_turnitinsim_sub');
317+
$field = new xmldb_field('quizanswer', XMLDB_TYPE_CHAR, '32', null, false, null, 0, 'tiiretrytime');
318+
319+
$dbman->change_field_default($table, $field);
320+
321+
upgrade_plugin_savepoint(true, 2021030201, 'plagiarism', 'turnitinsim');
322+
}
323+
307324
return true;
308325
}

lib.php

+18-4
Original file line numberDiff line numberDiff line change
@@ -161,24 +161,31 @@ public function save_form_elements($data) {
161161
* @throws moodle_exception
162162
*/
163163
public function get_links($linkarray) {
164-
global $DB, $OUTPUT, $PAGE;
164+
global $DB, $OUTPUT, $PAGE, $USER;
165165

166166
// Require the relevant JS modules. Only include once.
167167
static $jsloaded;
168168
if (empty($jsloaded)) {
169169
$jsloaded = true;
170170
$PAGE->requires->string_for_js('submissiondisplaystatus:queued', 'plagiarism_turnitinsim');
171+
$PAGE->requires->string_for_js('eulaaccepted', 'plagiarism_turnitinsim');
172+
$PAGE->requires->string_for_js('euladeclined', 'plagiarism_turnitinsim');
173+
$PAGE->requires->string_for_js('submissiondisplaystatus:queued', 'plagiarism_turnitinsim');
171174
$PAGE->requires->js_call_amd('plagiarism_turnitinsim/cv_launch', 'openCv');
172175
$PAGE->requires->js_call_amd('plagiarism_turnitinsim/resend_submission', 'resendSubmission');
176+
$PAGE->requires->js_call_amd('plagiarism_turnitinsim/eula_response', 'eulaResponse');
173177
}
174178
$output = '';
175179

176180
// Don't show links for certain file types as they won't have been submitted to Turnitin.
177181
if (!empty($linkarray["file"])) {
178182
$file = $linkarray["file"];
179183
$filearea = $file->get_filearea();
184+
180185
$nonsubmittingareas = array("feedback_files", "introattachment");
181-
if (in_array($filearea, $nonsubmittingareas)) {
186+
$allowedcomponents = array("assignsubmission_file", "mod_assign", "mod_forum", "mod_workshop", "question");
187+
188+
if ((in_array($filearea, $nonsubmittingareas)) || !in_array($file->get_component(), $allowedcomponents)) {
182189
return $output;
183190
}
184191
}
@@ -235,6 +242,7 @@ public function get_links($linkarray) {
235242
if ((!empty($linkarray['file'])) || (!empty($linkarray['content']))) {
236243
$submissionid = '';
237244
$eulaconfirm = '';
245+
$status = '';
238246
$showresubmitlink = false;
239247
$submission = null;
240248

@@ -338,7 +346,13 @@ public function get_links($linkarray) {
338346
break;
339347
}
340348

341-
} else {
349+
} else if ($linkarray['userid'] != null) {
350+
if ($instructor && $linkarray['userid'] === "0") {
351+
return $output;
352+
} else {
353+
$linkarray['userid'] = $USER->id;
354+
}
355+
342356
// If the plugin was enabled after a submission was made then it will not have been sent to Turnitin. Queue it.
343357
$moduleclass = 'plagiarism_turnitinsim_'.$cm->modname;
344358
$moduleobject = new $moduleclass;
@@ -351,7 +365,7 @@ public function get_links($linkarray) {
351365

352366
if ($plagiarismfile->status === TURNITINSIM_SUBMISSION_STATUS_EULA_NOT_ACCEPTED) {
353367
$eula = new plagiarism_turnitinsim_eula();
354-
$statusset = $eula->get_eula_status($cm->id, $submission->gettype());
368+
$statusset = $eula->get_eula_status($cm->id, $plagiarismfile->type);
355369
$status = $statusset['eula-status'];
356370
$eulaconfirm = $statusset['eula-confirm'];
357371
} else {

utilities/constants.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@
5757
define('TURNITINSIM_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS', 451);
5858

5959
// API Endpoints.
60-
define('TURNITINSIM_ENDPOINT_CREATE_SUBMISSION', '/v1/submissions');
61-
define('TURNITINSIM_ENDPOINT_GET_SUBMISSION_INFO', '/v1/submissions/{{submission_id}}');
62-
define('TURNITINSIM_ENDPOINT_UPLOAD_SUBMISSION', '/v1/submissions/{{submission_id}}/original');
63-
define('TURNITINSIM_ENDPOINT_SIMILARITY_REPORT', '/v1/submissions/{{submission_id}}/similarity');
64-
define('TURNITINSIM_ENDPOINT_CV_LAUNCH', '/v1/submissions/{{submission_id}}/viewer-url');
65-
define('TURNITINSIM_ENDPOINT_WEBHOOKS', '/v1/webhooks');
66-
define('TURNITINSIM_ENDPOINT_GET_WEBHOOK', '/v1/webhooks/{{webhook_id}}');
67-
define('TURNITINSIM_ENDPOINT_GET_LATEST_EULA', '/v1/eula/latest');
68-
define('TURNITINSIM_ENDPOINT_GET_FEATURES_ENABLED', '/v1/features-enabled');
60+
define('TURNITINSIM_ENDPOINT_CREATE_SUBMISSION', '/api/v1/submissions');
61+
define('TURNITINSIM_ENDPOINT_GET_SUBMISSION_INFO', '/api/v1/submissions/{{submission_id}}');
62+
define('TURNITINSIM_ENDPOINT_UPLOAD_SUBMISSION', '/api/v1/submissions/{{submission_id}}/original');
63+
define('TURNITINSIM_ENDPOINT_SIMILARITY_REPORT', '/api/v1/submissions/{{submission_id}}/similarity');
64+
define('TURNITINSIM_ENDPOINT_CV_LAUNCH', '/api/v1/submissions/{{submission_id}}/viewer-url');
65+
define('TURNITINSIM_ENDPOINT_WEBHOOKS', '/api/v1/webhooks');
66+
define('TURNITINSIM_ENDPOINT_GET_WEBHOOK', '/api/v1/webhooks/{{webhook_id}}');
67+
define('TURNITINSIM_ENDPOINT_GET_LATEST_EULA', '/api/v1/eula/latest');
68+
define('TURNITINSIM_ENDPOINT_GET_FEATURES_ENABLED', '/api/v1/features-enabled');
6969
define('TURNITINSIM_ENDPOINT_LOGGING', '/remote-logging/api/log');
7070

7171
// URLs.

version.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
defined('MOODLE_INTERNAL') || die();
2727

28-
$plugin->version = 2021011801;
28+
$plugin->version = 2021030201;
2929
$plugin->release = "v1.2";
3030
$plugin->requires = 2017051500;
3131
$plugin->component = 'plagiarism_turnitinsim';

0 commit comments

Comments
 (0)