From 4e45a3af840a14e5ec3cd00935511e50b02ccafe Mon Sep 17 00:00:00 2001 From: David Winn Date: Mon, 27 Apr 2020 15:40:21 +0100 Subject: [PATCH 01/48] Convert headers to lowercase for consistent checking. --- callbacks.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/callbacks.php b/callbacks.php index 56a4803..6da8b9a 100644 --- a/callbacks.php +++ b/callbacks.php @@ -35,11 +35,7 @@ $tscallback = new plagiarism_turnitinsim_callback(); // Get headers and body from request. -$reqheaders = plagiarism_turnitinsim_get_request_headers(); -// There is a strange anomaly with the headers on different environments. -if (isset($reqheaders['X-Turnitin-Eventtype'])) { - $reqheaders['X-Turnitin-EventType'] = $reqheaders['X-Turnitin-Eventtype']; -} +$reqheaders = array_change_key_case(plagiarism_turnitinsim_get_request_headers(), CASE_LOWER); $requeststring = file_get_contents('php://input'); $params = (object)json_decode($requeststring, true); @@ -59,7 +55,7 @@ } // Verify that callback is genuine. Exit if not. -if ($expectedsecret !== $reqheaders['X-Turnitin-Signature']) { +if ($expectedsecret !== $reqheaders['x-turnitin-signature']) { if ($pluginconfig->turnitinenablelogging) { $logger->error(get_string('webhookincorrectsignature', 'plagiarism_turnitinsim')); } @@ -69,7 +65,7 @@ } // Handle Submission complete callback. -if ($reqheaders['X-Turnitin-EventType'] == TURNITINSIM_SUBMISSION_COMPLETE) { +if ($reqheaders['x-turnitin-eventtype'] == TURNITINSIM_SUBMISSION_COMPLETE) { // Get Moodle submission id from Turnitin id. $submission = $DB->get_record_select('plagiarism_turnitinsim_sub', 'turnitinid = ?', array($params->id)); $tssubmission = new plagiarism_turnitinsim_submission( new plagiarism_turnitinsim_request(), $submission->id ); @@ -86,8 +82,8 @@ } // Handle Similarity complete callback. -if ($reqheaders['X-Turnitin-EventType'] == TURNITINSIM_SIMILARITY_COMPLETE || - $reqheaders['X-Turnitin-EventType'] == TURNITINSIM_SIMILARITY_UPDATED) { +if ($reqheaders['x-turnitin-eventtype'] == TURNITINSIM_SIMILARITY_COMPLETE || + $reqheaders['x-turnitin-eventtype'] == TURNITINSIM_SIMILARITY_UPDATED) { // Get Moodle submission id from Turnitin id. $submission = $DB->get_record_select('plagiarism_turnitinsim_sub', 'turnitinid = ?', array($params->submission_id)); $tssubmission = new plagiarism_turnitinsim_submission( new plagiarism_turnitinsim_request(), $submission->id ); From 3014600327345bf651de10e3a670877a4c4a53a3 Mon Sep 17 00:00:00 2001 From: David Winn Date: Wed, 29 Apr 2020 17:05:32 +0100 Subject: [PATCH 02/48] Fix connection test button colours --- amd/build/connection_test.min.js | 2 +- amd/build/connection_test.min.js.map | 2 +- amd/src/connection_test.js | 17 ++++++++++------- styles.css | 18 ------------------ 4 files changed, 12 insertions(+), 27 deletions(-) diff --git a/amd/build/connection_test.min.js b/amd/build/connection_test.min.js index 62eda43..5a3a252 100644 --- a/amd/build/connection_test.min.js +++ b/amd/build/connection_test.min.js @@ -1,2 +1,2 @@ -define ("plagiarism_turnitinsim/connection_test",["jquery","core/str"],function(a,b){return{connectionTest:function connectionTest(){var d=a("#id_connection_test");if(0.\n\n/**\n * Javascript controller for the Turnitin Connection Test.\n *\n * @package plagiarism_turnitinsim\n * @copyright 2018 Turnitin\n * @author David Winn \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n/**\n * @module plagiarism_turnitinsim/connection_test\n */\n\ndefine(['jquery', 'core/str'], function($, str) {\n return {\n connectionTest: function() {\n // Store connection test selector.\n var ct = $('#id_connection_test');\n\n if (ct.length > 0) {\n ct.click(function() {\n $.ajax({\n type: \"POST\",\n url: M.cfg.wwwroot + \"/plagiarism/turnitinsim/ajax/connection_test.php\",\n dataType: \"json\",\n data: {\n action: \"connection_test\",\n sesskey: M.cfg.sesskey,\n apiurl: $('#id_turnitinapiurl').val(),\n apikey: $('#id_turnitinapikey').val()\n },\n success: function(data) {\n if (data.connection_status === 200) {\n ct.removeClass(\"connection-test-failed\");\n ct.addClass(\"connection-test-success\");\n\n str.get_string('connecttestsuccess', 'plagiarism_turnitinsim').done(function(text) {\n changeString(ct, text);\n });\n } else {\n ct.removeClass(\"connection-test-success\");\n ct.addClass(\"connection-test-failed\");\n\n str.get_string('connecttestfailed', 'plagiarism_turnitinsim').done(function(text) {\n changeString(ct, text);\n });\n }\n\n // Fade out classes and swap back values.\n ct.delay(1000).fadeOut(\"slow\", function() {\n $(this).removeClass(\"turnitinsim_connection-test-failed\");\n $(this).removeClass(\"turnitinsim_connection-test-success\");\n\n str.get_string('connecttest', 'plagiarism_turnitinsim').done(function(text) {\n changeString(ct, text);\n });\n }).fadeIn(\"slow\");\n }\n });\n });\n }\n\n /**\n * Helper function to change the button text depending on which type of element we're handling.\n * @param {jQuery} ct - The button element - may be input or button depending on the Moodle theme.\n * @param {String} langString - The language string we're setting.\n */\n function changeString(ct, langString) {\n if (ct.get(0).tagName === \"BUTTON\") {\n ct.text(langString);\n } else {\n ct.attr('value', langString);\n }\n }\n }\n };\n});"],"file":"connection_test.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/connection_test.js"],"names":["define","$","str","connectionTest","ct","length","click","ajax","type","url","M","cfg","wwwroot","dataType","data","action","sesskey","apiurl","val","apikey","success","removeClass","connection_status","addClass","get_string","done","text","changeString","delay","fadeOut","fadeIn","langString","get","tagName","attr"],"mappings":"AA4BAA,OAAM,0CAAC,CAAC,QAAD,CAAW,UAAX,CAAD,CAAyB,SAASC,CAAT,CAAYC,CAAZ,CAAiB,CAC5C,MAAO,CACHC,cAAc,CAAE,yBAAW,CAEvB,GAAIC,CAAAA,CAAE,CAAGH,CAAC,CAAC,qBAAD,CAAV,CAEA,GAAgB,CAAZ,CAAAG,CAAE,CAACC,MAAP,CAAmB,CACfD,CAAE,CAACE,KAAH,CAAS,UAAW,CAChBL,CAAC,CAACM,IAAF,CAAO,CACHC,IAAI,CAAE,MADH,CAEHC,GAAG,CAAEC,CAAC,CAACC,GAAF,CAAMC,OAAN,CAAgB,kDAFlB,CAGHC,QAAQ,CAAE,MAHP,CAIHC,IAAI,CAAE,CACFC,MAAM,CAAE,iBADN,CAEFC,OAAO,CAAEN,CAAC,CAACC,GAAF,CAAMK,OAFb,CAGFC,MAAM,CAAEhB,CAAC,CAAC,oBAAD,CAAD,CAAwBiB,GAAxB,EAHN,CAIFC,MAAM,CAAElB,CAAC,CAAC,oBAAD,CAAD,CAAwBiB,GAAxB,EAJN,CAJH,CAUHE,OAAO,CAAE,iBAASN,CAAT,CAAe,CAEpBV,CAAE,CAACiB,WAAH,CAAe,eAAf,EACA,GAA+B,GAA3B,GAAAP,CAAI,CAACQ,iBAAT,CAAoC,CAChClB,CAAE,CAACiB,WAAH,CAAe,YAAf,EACAjB,CAAE,CAACmB,QAAH,CAAY,aAAZ,EAEArB,CAAG,CAACsB,UAAJ,CAAe,oBAAf,CAAqC,wBAArC,EAA+DC,IAA/D,CAAoE,SAASC,CAAT,CAAe,CAC/EC,CAAY,CAACvB,CAAD,CAAKsB,CAAL,CACf,CAFD,CAGH,CAPD,IAOO,CACHtB,CAAE,CAACiB,WAAH,CAAe,aAAf,EACAjB,CAAE,CAACmB,QAAH,CAAY,YAAZ,EAEArB,CAAG,CAACsB,UAAJ,CAAe,mBAAf,CAAoC,wBAApC,EAA8DC,IAA9D,CAAmE,SAASC,CAAT,CAAe,CAC9EC,CAAY,CAACvB,CAAD,CAAKsB,CAAL,CACf,CAFD,CAGH,CAGDtB,CAAE,CAACwB,KAAH,CAAS,GAAT,EAAeC,OAAf,CAAuB,MAAvB,CAA+B,UAAW,CACtCzB,CAAE,CAACiB,WAAH,CAAe,YAAf,EACAjB,CAAE,CAACiB,WAAH,CAAe,aAAf,EACApB,CAAC,CAAC,IAAD,CAAD,CAAQsB,QAAR,CAAiB,eAAjB,EAEArB,CAAG,CAACsB,UAAJ,CAAe,aAAf,CAA8B,wBAA9B,EAAwDC,IAAxD,CAA6D,SAASC,CAAT,CAAe,CACxEC,CAAY,CAACvB,CAAD,CAAKsB,CAAL,CACf,CAFD,CAGH,CARD,EAQGI,MARH,CAQU,MARV,CASH,CAvCE,CAAP,CAyCH,CA1CD,CA2CH,CAOD,QAASH,CAAAA,CAAT,CAAsBvB,CAAtB,CAA0B2B,CAA1B,CAAsC,CAClC,GAA0B,QAAtB,GAAA3B,CAAE,CAAC4B,GAAH,CAAO,CAAP,EAAUC,OAAd,CAAoC,CAChC7B,CAAE,CAACsB,IAAH,CAAQK,CAAR,CACH,CAFD,IAEO,CACH3B,CAAE,CAAC8B,IAAH,CAAQ,OAAR,CAAiBH,CAAjB,CACH,CACJ,CACJ,CA/DE,CAiEV,CAlEK,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Javascript controller for the Turnitin Connection Test.\n *\n * @package plagiarism_turnitinsim\n * @copyright 2018 Turnitin\n * @author David Winn \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n/**\n * @module plagiarism_turnitinsim/connection_test\n */\n\ndefine(['jquery', 'core/str'], function($, str) {\n return {\n connectionTest: function() {\n // Store connection test selector.\n var ct = $('#id_connection_test');\n\n if (ct.length > 0) {\n ct.click(function() {\n $.ajax({\n type: \"POST\",\n url: M.cfg.wwwroot + \"/plagiarism/turnitinsim/ajax/connection_test.php\",\n dataType: \"json\",\n data: {\n action: \"connection_test\",\n sesskey: M.cfg.sesskey,\n apiurl: $('#id_turnitinapiurl').val(),\n apikey: $('#id_turnitinapikey').val()\n },\n success: function(data) {\n // ct.removeClass(\"btn\");\n ct.removeClass(\"btn-secondary\");\n if (data.connection_status === 200) {\n ct.removeClass(\"btn-danger\");\n ct.addClass(\"btn-success\");\n\n str.get_string('connecttestsuccess', 'plagiarism_turnitinsim').done(function(text) {\n changeString(ct, text);\n });\n } else {\n ct.removeClass(\"btn-success\");\n ct.addClass(\"btn-danger\");\n\n str.get_string('connecttestfailed', 'plagiarism_turnitinsim').done(function(text) {\n changeString(ct, text);\n });\n }\n\n // Fade out classes and swap back values.\n ct.delay(3000).fadeOut(\"slow\", function() {\n ct.removeClass(\"btn-danger\");\n ct.removeClass(\"btn-success\");\n $(this).addClass(\"btn-secondary\");\n\n str.get_string('connecttest', 'plagiarism_turnitinsim').done(function(text) {\n changeString(ct, text);\n });\n }).fadeIn(\"slow\");\n }\n });\n });\n }\n\n /**\n * Helper function to change the button text depending on which type of element we're handling.\n * @param {jQuery} ct - The button element - may be input or button depending on the Moodle theme.\n * @param {String} langString - The language string we're setting.\n */\n function changeString(ct, langString) {\n if (ct.get(0).tagName === \"BUTTON\") {\n ct.text(langString);\n } else {\n ct.attr('value', langString);\n }\n }\n }\n };\n});"],"file":"connection_test.min.js"} \ No newline at end of file diff --git a/amd/src/connection_test.js b/amd/src/connection_test.js index a07e27c..ea91b13 100644 --- a/amd/src/connection_test.js +++ b/amd/src/connection_test.js @@ -45,16 +45,18 @@ define(['jquery', 'core/str'], function($, str) { apikey: $('#id_turnitinapikey').val() }, success: function(data) { + // ct.removeClass("btn"); + ct.removeClass("btn-secondary"); if (data.connection_status === 200) { - ct.removeClass("connection-test-failed"); - ct.addClass("connection-test-success"); + ct.removeClass("btn-danger"); + ct.addClass("btn-success"); str.get_string('connecttestsuccess', 'plagiarism_turnitinsim').done(function(text) { changeString(ct, text); }); } else { - ct.removeClass("connection-test-success"); - ct.addClass("connection-test-failed"); + ct.removeClass("btn-success"); + ct.addClass("btn-danger"); str.get_string('connecttestfailed', 'plagiarism_turnitinsim').done(function(text) { changeString(ct, text); @@ -62,9 +64,10 @@ define(['jquery', 'core/str'], function($, str) { } // Fade out classes and swap back values. - ct.delay(1000).fadeOut("slow", function() { - $(this).removeClass("turnitinsim_connection-test-failed"); - $(this).removeClass("turnitinsim_connection-test-success"); + ct.delay(3000).fadeOut("slow", function() { + ct.removeClass("btn-danger"); + ct.removeClass("btn-success"); + $(this).addClass("btn-secondary"); str.get_string('connecttest', 'plagiarism_turnitinsim').done(function(text) { changeString(ct, text); diff --git a/styles.css b/styles.css index 62e4906..fdcbca0 100644 --- a/styles.css +++ b/styles.css @@ -126,22 +126,4 @@ .turnitinsim_links .turnitinsim_status .or_score_colour_100 { background: #db4221; color: #fff; -} - -/* Connection Test*/ -.turnitinsim_connection-test-success, -.turnitinsim_connection-test-failed { - background-image: none; - color: #fff; - text-shadow: none; -} -.turnitinsim_connection-test-success button:focus, -.turnitinsim_connection-test-failed button:focus { - outline: 0; -} -.turnitinsim_connection-test-success { - background-color: #51a351; -} -.turnitinsim_connection-test-failed { - background-color: #d9534f; } \ No newline at end of file From 3f94e1737917c113bcdbe5a000ea5589fd041152 Mon Sep 17 00:00:00 2001 From: David Winn Date: Wed, 29 Apr 2020 17:06:35 +0100 Subject: [PATCH 03/48] Removing commented out line --- amd/build/connection_test.min.js.map | 2 +- amd/src/connection_test.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/amd/build/connection_test.min.js.map b/amd/build/connection_test.min.js.map index bbb8e9a..ef097b3 100644 --- a/amd/build/connection_test.min.js.map +++ b/amd/build/connection_test.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/connection_test.js"],"names":["define","$","str","connectionTest","ct","length","click","ajax","type","url","M","cfg","wwwroot","dataType","data","action","sesskey","apiurl","val","apikey","success","removeClass","connection_status","addClass","get_string","done","text","changeString","delay","fadeOut","fadeIn","langString","get","tagName","attr"],"mappings":"AA4BAA,OAAM,0CAAC,CAAC,QAAD,CAAW,UAAX,CAAD,CAAyB,SAASC,CAAT,CAAYC,CAAZ,CAAiB,CAC5C,MAAO,CACHC,cAAc,CAAE,yBAAW,CAEvB,GAAIC,CAAAA,CAAE,CAAGH,CAAC,CAAC,qBAAD,CAAV,CAEA,GAAgB,CAAZ,CAAAG,CAAE,CAACC,MAAP,CAAmB,CACfD,CAAE,CAACE,KAAH,CAAS,UAAW,CAChBL,CAAC,CAACM,IAAF,CAAO,CACHC,IAAI,CAAE,MADH,CAEHC,GAAG,CAAEC,CAAC,CAACC,GAAF,CAAMC,OAAN,CAAgB,kDAFlB,CAGHC,QAAQ,CAAE,MAHP,CAIHC,IAAI,CAAE,CACFC,MAAM,CAAE,iBADN,CAEFC,OAAO,CAAEN,CAAC,CAACC,GAAF,CAAMK,OAFb,CAGFC,MAAM,CAAEhB,CAAC,CAAC,oBAAD,CAAD,CAAwBiB,GAAxB,EAHN,CAIFC,MAAM,CAAElB,CAAC,CAAC,oBAAD,CAAD,CAAwBiB,GAAxB,EAJN,CAJH,CAUHE,OAAO,CAAE,iBAASN,CAAT,CAAe,CAEpBV,CAAE,CAACiB,WAAH,CAAe,eAAf,EACA,GAA+B,GAA3B,GAAAP,CAAI,CAACQ,iBAAT,CAAoC,CAChClB,CAAE,CAACiB,WAAH,CAAe,YAAf,EACAjB,CAAE,CAACmB,QAAH,CAAY,aAAZ,EAEArB,CAAG,CAACsB,UAAJ,CAAe,oBAAf,CAAqC,wBAArC,EAA+DC,IAA/D,CAAoE,SAASC,CAAT,CAAe,CAC/EC,CAAY,CAACvB,CAAD,CAAKsB,CAAL,CACf,CAFD,CAGH,CAPD,IAOO,CACHtB,CAAE,CAACiB,WAAH,CAAe,aAAf,EACAjB,CAAE,CAACmB,QAAH,CAAY,YAAZ,EAEArB,CAAG,CAACsB,UAAJ,CAAe,mBAAf,CAAoC,wBAApC,EAA8DC,IAA9D,CAAmE,SAASC,CAAT,CAAe,CAC9EC,CAAY,CAACvB,CAAD,CAAKsB,CAAL,CACf,CAFD,CAGH,CAGDtB,CAAE,CAACwB,KAAH,CAAS,GAAT,EAAeC,OAAf,CAAuB,MAAvB,CAA+B,UAAW,CACtCzB,CAAE,CAACiB,WAAH,CAAe,YAAf,EACAjB,CAAE,CAACiB,WAAH,CAAe,aAAf,EACApB,CAAC,CAAC,IAAD,CAAD,CAAQsB,QAAR,CAAiB,eAAjB,EAEArB,CAAG,CAACsB,UAAJ,CAAe,aAAf,CAA8B,wBAA9B,EAAwDC,IAAxD,CAA6D,SAASC,CAAT,CAAe,CACxEC,CAAY,CAACvB,CAAD,CAAKsB,CAAL,CACf,CAFD,CAGH,CARD,EAQGI,MARH,CAQU,MARV,CASH,CAvCE,CAAP,CAyCH,CA1CD,CA2CH,CAOD,QAASH,CAAAA,CAAT,CAAsBvB,CAAtB,CAA0B2B,CAA1B,CAAsC,CAClC,GAA0B,QAAtB,GAAA3B,CAAE,CAAC4B,GAAH,CAAO,CAAP,EAAUC,OAAd,CAAoC,CAChC7B,CAAE,CAACsB,IAAH,CAAQK,CAAR,CACH,CAFD,IAEO,CACH3B,CAAE,CAAC8B,IAAH,CAAQ,OAAR,CAAiBH,CAAjB,CACH,CACJ,CACJ,CA/DE,CAiEV,CAlEK,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Javascript controller for the Turnitin Connection Test.\n *\n * @package plagiarism_turnitinsim\n * @copyright 2018 Turnitin\n * @author David Winn \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n/**\n * @module plagiarism_turnitinsim/connection_test\n */\n\ndefine(['jquery', 'core/str'], function($, str) {\n return {\n connectionTest: function() {\n // Store connection test selector.\n var ct = $('#id_connection_test');\n\n if (ct.length > 0) {\n ct.click(function() {\n $.ajax({\n type: \"POST\",\n url: M.cfg.wwwroot + \"/plagiarism/turnitinsim/ajax/connection_test.php\",\n dataType: \"json\",\n data: {\n action: \"connection_test\",\n sesskey: M.cfg.sesskey,\n apiurl: $('#id_turnitinapiurl').val(),\n apikey: $('#id_turnitinapikey').val()\n },\n success: function(data) {\n // ct.removeClass(\"btn\");\n ct.removeClass(\"btn-secondary\");\n if (data.connection_status === 200) {\n ct.removeClass(\"btn-danger\");\n ct.addClass(\"btn-success\");\n\n str.get_string('connecttestsuccess', 'plagiarism_turnitinsim').done(function(text) {\n changeString(ct, text);\n });\n } else {\n ct.removeClass(\"btn-success\");\n ct.addClass(\"btn-danger\");\n\n str.get_string('connecttestfailed', 'plagiarism_turnitinsim').done(function(text) {\n changeString(ct, text);\n });\n }\n\n // Fade out classes and swap back values.\n ct.delay(3000).fadeOut(\"slow\", function() {\n ct.removeClass(\"btn-danger\");\n ct.removeClass(\"btn-success\");\n $(this).addClass(\"btn-secondary\");\n\n str.get_string('connecttest', 'plagiarism_turnitinsim').done(function(text) {\n changeString(ct, text);\n });\n }).fadeIn(\"slow\");\n }\n });\n });\n }\n\n /**\n * Helper function to change the button text depending on which type of element we're handling.\n * @param {jQuery} ct - The button element - may be input or button depending on the Moodle theme.\n * @param {String} langString - The language string we're setting.\n */\n function changeString(ct, langString) {\n if (ct.get(0).tagName === \"BUTTON\") {\n ct.text(langString);\n } else {\n ct.attr('value', langString);\n }\n }\n }\n };\n});"],"file":"connection_test.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/connection_test.js"],"names":["define","$","str","connectionTest","ct","length","click","ajax","type","url","M","cfg","wwwroot","dataType","data","action","sesskey","apiurl","val","apikey","success","removeClass","connection_status","addClass","get_string","done","text","changeString","delay","fadeOut","fadeIn","langString","get","tagName","attr"],"mappings":"AA4BAA,OAAM,0CAAC,CAAC,QAAD,CAAW,UAAX,CAAD,CAAyB,SAASC,CAAT,CAAYC,CAAZ,CAAiB,CAC5C,MAAO,CACHC,cAAc,CAAE,yBAAW,CAEvB,GAAIC,CAAAA,CAAE,CAAGH,CAAC,CAAC,qBAAD,CAAV,CAEA,GAAgB,CAAZ,CAAAG,CAAE,CAACC,MAAP,CAAmB,CACfD,CAAE,CAACE,KAAH,CAAS,UAAW,CAChBL,CAAC,CAACM,IAAF,CAAO,CACHC,IAAI,CAAE,MADH,CAEHC,GAAG,CAAEC,CAAC,CAACC,GAAF,CAAMC,OAAN,CAAgB,kDAFlB,CAGHC,QAAQ,CAAE,MAHP,CAIHC,IAAI,CAAE,CACFC,MAAM,CAAE,iBADN,CAEFC,OAAO,CAAEN,CAAC,CAACC,GAAF,CAAMK,OAFb,CAGFC,MAAM,CAAEhB,CAAC,CAAC,oBAAD,CAAD,CAAwBiB,GAAxB,EAHN,CAIFC,MAAM,CAAElB,CAAC,CAAC,oBAAD,CAAD,CAAwBiB,GAAxB,EAJN,CAJH,CAUHE,OAAO,CAAE,iBAASN,CAAT,CAAe,CACpBV,CAAE,CAACiB,WAAH,CAAe,eAAf,EACA,GAA+B,GAA3B,GAAAP,CAAI,CAACQ,iBAAT,CAAoC,CAChClB,CAAE,CAACiB,WAAH,CAAe,YAAf,EACAjB,CAAE,CAACmB,QAAH,CAAY,aAAZ,EAEArB,CAAG,CAACsB,UAAJ,CAAe,oBAAf,CAAqC,wBAArC,EAA+DC,IAA/D,CAAoE,SAASC,CAAT,CAAe,CAC/EC,CAAY,CAACvB,CAAD,CAAKsB,CAAL,CACf,CAFD,CAGH,CAPD,IAOO,CACHtB,CAAE,CAACiB,WAAH,CAAe,aAAf,EACAjB,CAAE,CAACmB,QAAH,CAAY,YAAZ,EAEArB,CAAG,CAACsB,UAAJ,CAAe,mBAAf,CAAoC,wBAApC,EAA8DC,IAA9D,CAAmE,SAASC,CAAT,CAAe,CAC9EC,CAAY,CAACvB,CAAD,CAAKsB,CAAL,CACf,CAFD,CAGH,CAGDtB,CAAE,CAACwB,KAAH,CAAS,GAAT,EAAeC,OAAf,CAAuB,MAAvB,CAA+B,UAAW,CACtCzB,CAAE,CAACiB,WAAH,CAAe,YAAf,EACAjB,CAAE,CAACiB,WAAH,CAAe,aAAf,EACApB,CAAC,CAAC,IAAD,CAAD,CAAQsB,QAAR,CAAiB,eAAjB,EAEArB,CAAG,CAACsB,UAAJ,CAAe,aAAf,CAA8B,wBAA9B,EAAwDC,IAAxD,CAA6D,SAASC,CAAT,CAAe,CACxEC,CAAY,CAACvB,CAAD,CAAKsB,CAAL,CACf,CAFD,CAGH,CARD,EAQGI,MARH,CAQU,MARV,CASH,CAtCE,CAAP,CAwCH,CAzCD,CA0CH,CAOD,QAASH,CAAAA,CAAT,CAAsBvB,CAAtB,CAA0B2B,CAA1B,CAAsC,CAClC,GAA0B,QAAtB,GAAA3B,CAAE,CAAC4B,GAAH,CAAO,CAAP,EAAUC,OAAd,CAAoC,CAChC7B,CAAE,CAACsB,IAAH,CAAQK,CAAR,CACH,CAFD,IAEO,CACH3B,CAAE,CAAC8B,IAAH,CAAQ,OAAR,CAAiBH,CAAjB,CACH,CACJ,CACJ,CA9DE,CAgEV,CAjEK,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Javascript controller for the Turnitin Connection Test.\n *\n * @package plagiarism_turnitinsim\n * @copyright 2018 Turnitin\n * @author David Winn \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n/**\n * @module plagiarism_turnitinsim/connection_test\n */\n\ndefine(['jquery', 'core/str'], function($, str) {\n return {\n connectionTest: function() {\n // Store connection test selector.\n var ct = $('#id_connection_test');\n\n if (ct.length > 0) {\n ct.click(function() {\n $.ajax({\n type: \"POST\",\n url: M.cfg.wwwroot + \"/plagiarism/turnitinsim/ajax/connection_test.php\",\n dataType: \"json\",\n data: {\n action: \"connection_test\",\n sesskey: M.cfg.sesskey,\n apiurl: $('#id_turnitinapiurl').val(),\n apikey: $('#id_turnitinapikey').val()\n },\n success: function(data) {\n ct.removeClass(\"btn-secondary\");\n if (data.connection_status === 200) {\n ct.removeClass(\"btn-danger\");\n ct.addClass(\"btn-success\");\n\n str.get_string('connecttestsuccess', 'plagiarism_turnitinsim').done(function(text) {\n changeString(ct, text);\n });\n } else {\n ct.removeClass(\"btn-success\");\n ct.addClass(\"btn-danger\");\n\n str.get_string('connecttestfailed', 'plagiarism_turnitinsim').done(function(text) {\n changeString(ct, text);\n });\n }\n\n // Fade out classes and swap back values.\n ct.delay(3000).fadeOut(\"slow\", function() {\n ct.removeClass(\"btn-danger\");\n ct.removeClass(\"btn-success\");\n $(this).addClass(\"btn-secondary\");\n\n str.get_string('connecttest', 'plagiarism_turnitinsim').done(function(text) {\n changeString(ct, text);\n });\n }).fadeIn(\"slow\");\n }\n });\n });\n }\n\n /**\n * Helper function to change the button text depending on which type of element we're handling.\n * @param {jQuery} ct - The button element - may be input or button depending on the Moodle theme.\n * @param {String} langString - The language string we're setting.\n */\n function changeString(ct, langString) {\n if (ct.get(0).tagName === \"BUTTON\") {\n ct.text(langString);\n } else {\n ct.attr('value', langString);\n }\n }\n }\n };\n});"],"file":"connection_test.min.js"} \ No newline at end of file diff --git a/amd/src/connection_test.js b/amd/src/connection_test.js index ea91b13..d8ad8f9 100644 --- a/amd/src/connection_test.js +++ b/amd/src/connection_test.js @@ -45,7 +45,6 @@ define(['jquery', 'core/str'], function($, str) { apikey: $('#id_turnitinapikey').val() }, success: function(data) { - // ct.removeClass("btn"); ct.removeClass("btn-secondary"); if (data.connection_status === 200) { ct.removeClass("btn-danger"); From 11cbc9fff66372810583ea2e0d50332a5aaf3a89 Mon Sep 17 00:00:00 2001 From: Grijesh Saini Date: Mon, 4 May 2020 21:44:02 +0530 Subject: [PATCH 04/48] INT-13960 - Fixed Connection test. --- classes/callback.class.php | 2 +- classes/request.class.php | 10 ++++++++-- tests/classes/tsrequest_test.php | 11 +++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/classes/callback.class.php b/classes/callback.class.php index ae529bf..0ebfa34 100644 --- a/classes/callback.class.php +++ b/classes/callback.class.php @@ -102,7 +102,7 @@ public function delete_webhook($webhookid) { $response = $this->tsrequest->send_request($endpoint, json_encode(array()), 'DELETE'); $responsedata = json_decode($response); - if ($responsedata->httpstatus == TURNITINSIM_HTTP_NO_CONTENT) { + if ($responsedata->httpstatus === TURNITINSIM_HTTP_NO_CONTENT) { mtrace(get_string('taskoutputwebhookdeleted', 'plagiarism_turnitinsim', $webhookid)); return true; } diff --git a/classes/request.class.php b/classes/request.class.php index 90580d2..4a90f3c 100644 --- a/classes/request.class.php +++ b/classes/request.class.php @@ -177,7 +177,7 @@ public function send_request($endpoint, $requestbody, $method, $requesttype = 'g if (is_array($result)) { $result["httpstatus"] = $httpstatus; } else { - $result->httpstatus = $httpstatus || ''; + $result->httpstatus = $httpstatus || '' ? $httpstatus : ''; } $result = json_encode($result); @@ -201,6 +201,12 @@ public function send_request($endpoint, $requestbody, $method, $requesttype = 'g * @throws moodle_exception when invalid session key. */ public function test_connection($apiurl, $apikey) { + + if(empty($apikey) || empty($apiurl)) { + $data["connection_status"] = TURNITINSIM_HTTP_BAD_REQUEST; + return json_encode($data); + } + $this->set_apiurl($apiurl); $this->set_apikey($apikey); $this->set_headers(); @@ -208,7 +214,7 @@ public function test_connection($apiurl, $apikey) { $response = $this->send_request(TURNITINSIM_ENDPOINT_WEBHOOKS, json_encode(array()), 'GET'); $responsedata = json_decode($response); - if (isset($responsedata->httpstatus) && $responsedata->httpstatus == TURNITINSIM_HTTP_OK) { + if (isset($responsedata->httpstatus) && $responsedata->httpstatus === TURNITINSIM_HTTP_OK) { $data["connection_status"] = TURNITINSIM_HTTP_OK; } else { $data["connection_status"] = TURNITINSIM_HTTP_BAD_REQUEST; diff --git a/tests/classes/tsrequest_test.php b/tests/classes/tsrequest_test.php index e905ab6..896ef43 100644 --- a/tests/classes/tsrequest_test.php +++ b/tests/classes/tsrequest_test.php @@ -61,6 +61,17 @@ public function test_connection_test() { ->setConstructorArgs([TURNITINSIM_ENDPOINT_WEBHOOKS]) ->getMock(); + //Test connection should return failed if url is missing + $result = $tsrequest->test_connection("", "key"); + $responsesuccessparsed = (array)json_decode($result); + $this->assertEquals(TURNITINSIM_HTTP_BAD_REQUEST, $responsesuccessparsed['connection_status']); + + //Test connection should return failed if key is missing + $result = $tsrequest->test_connection("url", ""); + $responsesuccessparsed = (array)json_decode($result); + $this->assertEquals(TURNITINSIM_HTTP_BAD_REQUEST, $responsesuccessparsed['connection_status']); + + // Mock API send request method. $tsrequest->expects($this->exactly(2)) ->method('send_request') From 875fed07b33650640e87193f53bb2751c4cf544d Mon Sep 17 00:00:00 2001 From: Grijesh Saini Date: Tue, 5 May 2020 14:25:58 +0530 Subject: [PATCH 05/48] INT-13960 - Addressed review comment. - Added (.) at the end of comment. --- tests/classes/tsrequest_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/classes/tsrequest_test.php b/tests/classes/tsrequest_test.php index 896ef43..b1484f4 100644 --- a/tests/classes/tsrequest_test.php +++ b/tests/classes/tsrequest_test.php @@ -61,12 +61,12 @@ public function test_connection_test() { ->setConstructorArgs([TURNITINSIM_ENDPOINT_WEBHOOKS]) ->getMock(); - //Test connection should return failed if url is missing + //Test connection should return failed if url is missing. $result = $tsrequest->test_connection("", "key"); $responsesuccessparsed = (array)json_decode($result); $this->assertEquals(TURNITINSIM_HTTP_BAD_REQUEST, $responsesuccessparsed['connection_status']); - //Test connection should return failed if key is missing + //Test connection should return failed if key is missing. $result = $tsrequest->test_connection("url", ""); $responsesuccessparsed = (array)json_decode($result); $this->assertEquals(TURNITINSIM_HTTP_BAD_REQUEST, $responsesuccessparsed['connection_status']); From 36f94eef47bec1cbd43fb016715eb77b9e586784 Mon Sep 17 00:00:00 2001 From: Grijesh Saini Date: Tue, 5 May 2020 17:14:03 +0530 Subject: [PATCH 06/48] INT-13960 - Added fix for invalid tii url --- classes/request.class.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/classes/request.class.php b/classes/request.class.php index 4a90f3c..494b020 100644 --- a/classes/request.class.php +++ b/classes/request.class.php @@ -168,11 +168,21 @@ public function send_request($endpoint, $requestbody, $method, $requesttype = 'g } $result = curl_exec($ch); - $result = (empty($result)) ? new stdClass() : json_decode($result); // Add httpstatus to $result. $httpstatus = curl_getinfo($ch, CURLINFO_HTTP_CODE); + if (empty($result)) { + $result = new stdClass(); + } else { + $result = json_decode($result); + // If Json is not valid set httpstatus 400. + if (json_last_error() !== JSON_ERROR_NONE) { + $result = new stdClass(); + $httpstatus = 400; + } + } + // The response could be an array or an object. if (is_array($result)) { $result["httpstatus"] = $httpstatus; @@ -202,7 +212,7 @@ public function send_request($endpoint, $requestbody, $method, $requesttype = 'g */ public function test_connection($apiurl, $apikey) { - if(empty($apikey) || empty($apiurl)) { + if (empty($apikey) || empty($apiurl)) { $data["connection_status"] = TURNITINSIM_HTTP_BAD_REQUEST; return json_encode($data); } From 53ec8765d1b713f6e70525ce9d8dccfe8621da43 Mon Sep 17 00:00:00 2001 From: Grijesh Saini Date: Wed, 6 May 2020 17:46:33 +0530 Subject: [PATCH 07/48] INT-13960 - Added regex to validate turnitin connection url. --- classes/request.class.php | 11 ++++++++ tests/classes/tsrequest_test.php | 47 +++++++++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/classes/request.class.php b/classes/request.class.php index 494b020..1bb57e3 100644 --- a/classes/request.class.php +++ b/classes/request.class.php @@ -212,11 +212,22 @@ public function send_request($endpoint, $requestbody, $method, $requesttype = 'g */ public function test_connection($apiurl, $apikey) { + $valid_url_regex = '/.+\.(turnitin\.com|turnitin\.co\.uk|turnitin\.dev|turnitin\.org|tii-sandbox\.com)\/api$/m'; + if (empty($apikey) || empty($apiurl)) { $data["connection_status"] = TURNITINSIM_HTTP_BAD_REQUEST; return json_encode($data); } + if (!preg_match($valid_url_regex, $apiurl)) { + $data["connection_status"] = TURNITINSIM_HTTP_BAD_REQUEST; + + if ($this->logger) { + $this->logger->info('Invalid Turnitin URL: ', array($apiurl)); + } + return json_encode($data); + } + $this->set_apiurl($apiurl); $this->set_apikey($apikey); $this->set_headers(); diff --git a/tests/classes/tsrequest_test.php b/tests/classes/tsrequest_test.php index b1484f4..c4f356f 100644 --- a/tests/classes/tsrequest_test.php +++ b/tests/classes/tsrequest_test.php @@ -71,21 +71,60 @@ public function test_connection_test() { $responsesuccessparsed = (array)json_decode($result); $this->assertEquals(TURNITINSIM_HTTP_BAD_REQUEST, $responsesuccessparsed['connection_status']); + //Test connection should return failed if url is invalid TII url. + $result = $tsrequest->test_connection("http://abcd.tii.com", "key"); + $responsesuccessparsed = (array)json_decode($result); + $this->assertEquals(TURNITINSIM_HTTP_BAD_REQUEST, $responsesuccessparsed['connection_status']); + + //Test connection should return failed if url doesn't end with /api. + $result = $tsrequest->test_connection("http://abcd.turnitin.com", "key"); + $responsesuccessparsed = (array)json_decode($result); + $this->assertEquals(TURNITINSIM_HTTP_BAD_REQUEST, $responsesuccessparsed['connection_status']); + + // Mock API send request method. - $tsrequest->expects($this->exactly(2)) + $tsrequest->expects($this->exactly(6)) ->method('send_request') - ->willReturnOnConsecutiveCalls($responsesuccess, $responsefailure); + ->willReturnOnConsecutiveCalls($responsesuccess, $responsesuccess, $responsesuccess, $responsesuccess, $responsesuccess, $responsefailure); + + // Test connection. + $result = $tsrequest->test_connection("http://test.turnitin.com/api", "key"); + + // Test that the connection was successful. + $responsesuccessparsed = (array)json_decode($result); + $this->assertEquals(TURNITINSIM_HTTP_OK, $responsesuccessparsed['connection_status']); + + // Test connection. + $result = $tsrequest->test_connection("http://test.turnitin.org/api", "key"); + + // Test that the connection was successful. + $responsesuccessparsed = (array)json_decode($result); + $this->assertEquals(TURNITINSIM_HTTP_OK, $responsesuccessparsed['connection_status']); + + // Test connection. + $result = $tsrequest->test_connection("http://test.turnitin.dev/api", "key"); + + // Test that the connection was successful. + $responsesuccessparsed = (array)json_decode($result); + $this->assertEquals(TURNITINSIM_HTTP_OK, $responsesuccessparsed['connection_status']); + + // Test connection. + $result = $tsrequest->test_connection("http://test.turnitin.co.uk/api", "key"); + + // Test that the connection was successful. + $responsesuccessparsed = (array)json_decode($result); + $this->assertEquals(TURNITINSIM_HTTP_OK, $responsesuccessparsed['connection_status']); // Test connection. - $result = $tsrequest->test_connection("url", "key"); + $result = $tsrequest->test_connection("http://test.tii-sandbox.com/api", "key"); // Test that the connection was successful. $responsesuccessparsed = (array)json_decode($result); $this->assertEquals(TURNITINSIM_HTTP_OK, $responsesuccessparsed['connection_status']); // Test connection when expecting a failure. - $result = $tsrequest->test_connection("url", "key"); + $result = $tsrequest->test_connection("http://test.turnitin.com/api", "key"); // Test that the connection failed. $responsefailedparsed = (array)json_decode($result); From 011924bb76580576a76c8a3a63cc90dbc518b891 Mon Sep 17 00:00:00 2001 From: Grijesh Saini Date: Thu, 7 May 2020 12:19:54 +0530 Subject: [PATCH 08/48] INT-13960 - Addressed review comments. - Renamed variable name. --- classes/request.class.php | 4 ++-- tests/classes/tsrequest_test.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/classes/request.class.php b/classes/request.class.php index 1bb57e3..8dc82ce 100644 --- a/classes/request.class.php +++ b/classes/request.class.php @@ -212,14 +212,14 @@ public function send_request($endpoint, $requestbody, $method, $requesttype = 'g */ public function test_connection($apiurl, $apikey) { - $valid_url_regex = '/.+\.(turnitin\.com|turnitin\.co\.uk|turnitin\.dev|turnitin\.org|tii-sandbox\.com)\/api$/m'; + $validurlregex = '/.+\.(turnitin\.com|turnitinuk\.com|turnitin\.dev|turnitin\.org|tii-sandbox\.com)\/api$/m'; if (empty($apikey) || empty($apiurl)) { $data["connection_status"] = TURNITINSIM_HTTP_BAD_REQUEST; return json_encode($data); } - if (!preg_match($valid_url_regex, $apiurl)) { + if (!preg_match($validurlregex, $apiurl)) { $data["connection_status"] = TURNITINSIM_HTTP_BAD_REQUEST; if ($this->logger) { diff --git a/tests/classes/tsrequest_test.php b/tests/classes/tsrequest_test.php index c4f356f..6fffaad 100644 --- a/tests/classes/tsrequest_test.php +++ b/tests/classes/tsrequest_test.php @@ -110,7 +110,7 @@ public function test_connection_test() { $this->assertEquals(TURNITINSIM_HTTP_OK, $responsesuccessparsed['connection_status']); // Test connection. - $result = $tsrequest->test_connection("http://test.turnitin.co.uk/api", "key"); + $result = $tsrequest->test_connection("http://test.turnitinuk.com/api", "key"); // Test that the connection was successful. $responsesuccessparsed = (array)json_decode($result); From 2b7f39ed23301fcee0be7f2af987ab79f7a66c96 Mon Sep 17 00:00:00 2001 From: David Winn Date: Wed, 13 May 2020 15:01:41 +0100 Subject: [PATCH 09/48] Disable resubmission of files when EULA was declined. --- classes/submission.class.php | 2 +- lib.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/classes/submission.class.php b/classes/submission.class.php index 54acf9c..4f841df 100644 --- a/classes/submission.class.php +++ b/classes/submission.class.php @@ -240,7 +240,7 @@ public function calculate_generation_time($generated = false) { $this->setgenerationtime($duedate); } - // If the duedate has past and the report has already been generated then we don't want to regenerate. + // If the duedate has passed and the report has already been generated then we don't want to regenerate. if ($duedate < time() && $generated) { $this->settogenerate(0); $this->setgenerationtime(null); diff --git a/lib.php b/lib.php index 612659a..9a6599e 100644 --- a/lib.php +++ b/lib.php @@ -220,7 +220,7 @@ public function get_links($linkarray) { $helpicon = $OUTPUT->pix_icon( 'help', - get_string('submissiondisplayerror:eulanotaccepted', 'plagiarism_turnitinsim'), + get_string('submissiondisplayerror:eulanotaccepted_help', 'plagiarism_turnitinsim'), 'core', ['class' => 'eula-row-launch', 'data-eula-link' => $eulaurl] ); @@ -232,7 +232,7 @@ public function get_links($linkarray) { get_string('submissiondisplaystatus:awaitingeula', 'plagiarism_turnitinsim') . $eulalaunch, array('class' => 'tii_status_text tii_status_text_eula') ); - $showresubmitlink = true; + $showresubmitlink = false; break; case TURNITINSIM_SUBMISSION_STATUS_ERROR: From a3568a37e6ecafb07a9c4c5546eb8e269f2c1bb9 Mon Sep 17 00:00:00 2001 From: David Winn Date: Wed, 13 May 2020 17:43:46 +0100 Subject: [PATCH 10/48] Ensure Cloud Viewer opens multiple times if multiple submissions are opened. --- amd/build/cv_launch.min.js | 2 +- amd/build/cv_launch.min.js.map | 2 +- amd/src/cv_launch.js | 15 +++++++-------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/amd/build/cv_launch.min.js b/amd/build/cv_launch.min.js index b3fcf8f..273a4e6 100644 --- a/amd/build/cv_launch.min.js +++ b/amd/build/cv_launch.min.js @@ -1,2 +1,2 @@ -define ("plagiarism_turnitinsim/cv_launch",["jquery","core/str"],function(a,b){return{openCv:function openCv(){a(document).on("click",".or_score",function(){var c=a(this).parent().attr("class").split(/\s+/),d=0;a(c).each(function(a){if(c[a].match("^submission_")){d=c[a].split("_")[1]}});var e=window.open("","cvWindow"),f="
",g=M.cfg.wwwroot+"/plagiarism/turnitinsim/pix/tiiIcon.svg";f+="";b.get_string("loadingcv","plagiarism_turnitinsim").done(function(b){f+="

"+b+"

";a(".eulacontainer").hide().html(b).fadeIn()});f+="
";a(e.document.body).html(f);a.ajax({type:"GET",url:M.cfg.wwwroot+"/plagiarism/turnitinsim/ajax/cv.php",dataType:"json",data:{action:"request_cv_launch",submissionid:d,sesskey:M.cfg.sesskey},success:function success(a){e.location=a.viewer_url;this.checkDVClosed(e)},checkDVClosed:function checkDVClosed(a){var b=this;if(a.closed){window.location=window.location}else{setTimeout(function(){b.checkDVClosed(a)},500)}}})})}}}); +define ("plagiarism_turnitinsim/cv_launch",["jquery","core/str"],function(a,b){return{openCv:function openCv(){a(document).on("click",".or_score",function(){var c=a(this).parent().attr("class").split(/\s+/),d=0;a(c).each(function(a){if(c[a].match("^submission_")){d=c[a].split("_")[1]}});var e=window.open(),f="
",g=M.cfg.wwwroot+"/plagiarism/turnitinsim/pix/tiiIcon.svg";f+="";b.get_string("loadingcv","plagiarism_turnitinsim").done(function(b){f+="

"+b+"

";a(".eulacontainer").hide().html(b).fadeIn()});f+="
";a(e.document.body).html(f);a.ajax({type:"GET",url:M.cfg.wwwroot+"/plagiarism/turnitinsim/ajax/cv.php",dataType:"json",data:{action:"request_cv_launch",submissionid:d,sesskey:M.cfg.sesskey},success:function success(a){e.location=a.viewer_url;this.checkDVClosed(e)},checkDVClosed:function checkDVClosed(a){var b=this;if(a.closed){window.location=window.location}else{setTimeout(function(){b.checkDVClosed(a)},500)}}})})}}}); //# sourceMappingURL=cv_launch.min.js.map diff --git a/amd/build/cv_launch.min.js.map b/amd/build/cv_launch.min.js.map index 902cbab..6fa0b4b 100644 --- a/amd/build/cv_launch.min.js.map +++ b/amd/build/cv_launch.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/cv_launch.js"],"names":["define","$","str","openCv","document","on","classList","parent","attr","split","submissionid","each","index","match","dvWindow","window","open","loading","icon","M","cfg","wwwroot","get_string","done","text","hide","html","fadeIn","body","ajax","type","url","dataType","data","action","sesskey","success","location","viewer_url","checkDVClosed","that","closed","setTimeout"],"mappings":"AA4BAA,OAAM,oCAAC,CAAC,QAAD,CAAW,UAAX,CAAD,CAAyB,SAASC,CAAT,CAAYC,CAAZ,CAAiB,CAC5C,MAAO,CACHC,MAAM,CAAE,iBAAW,CACfF,CAAC,CAACG,QAAD,CAAD,CAAYC,EAAZ,CAAe,OAAf,CAAwB,WAAxB,CAAqC,UAAW,IAGxCC,CAAAA,CAAS,CAAGL,CAAC,CAAC,IAAD,CAAD,CAAQM,MAAR,GAAiBC,IAAjB,CAAsB,OAAtB,EAA+BC,KAA/B,CAAqC,KAArC,CAH4B,CAIxCC,CAAY,CAAG,CAJyB,CAK5CT,CAAC,CAACK,CAAD,CAAD,CAAaK,IAAb,CAAkB,SAASC,CAAT,CAAgB,CAC9B,GAAIN,CAAS,CAACM,CAAD,CAAT,CAAiBC,KAAjB,CAAuB,cAAvB,CAAJ,CAA4C,CACxCH,CAAY,CAAGJ,CAAS,CAACM,CAAD,CAAT,CAAiBH,KAAjB,CAAuB,GAAvB,EAA4B,CAA5B,CAClB,CACJ,CAJD,EAL4C,GAaxCK,CAAAA,CAAQ,CAAGC,MAAM,CAACC,IAAP,CAAY,EAAZ,CAAgB,UAAhB,CAb6B,CAcxCC,CAAO,CAAG,6DAd8B,CAexCC,CAAI,CAAGC,CAAC,CAACC,GAAF,CAAMC,OAAN,CAAgB,yCAfiB,CAgB5CJ,CAAO,EAAI,cAAeC,CAAf,CAAsB,0CAAjC,CAEAhB,CAAG,CAACoB,UAAJ,CAAe,WAAf,CAA4B,wBAA5B,EAAsDC,IAAtD,CAA2D,SAASC,CAAT,CAAe,CACtEP,CAAO,EAAI,2DAA2DO,CAA3D,CAAkE,MAA7E,CACAvB,CAAC,CAAC,gBAAD,CAAD,CAAoBwB,IAApB,GAA2BC,IAA3B,CAAgCF,CAAhC,EAAsCG,MAAtC,EACH,CAHD,EAKAV,CAAO,EAAI,QAAX,CACAhB,CAAC,CAACa,CAAQ,CAACV,QAAT,CAAkBwB,IAAnB,CAAD,CAA0BF,IAA1B,CAA+BT,CAA/B,EAEAhB,CAAC,CAAC4B,IAAF,CAAO,CACHC,IAAI,CAAE,KADH,CAEHC,GAAG,CAAEZ,CAAC,CAACC,GAAF,CAAMC,OAAN,CAAgB,qCAFlB,CAGHW,QAAQ,CAAE,MAHP,CAIHC,IAAI,CAAE,CACFC,MAAM,CAAE,mBADN,CAEFxB,YAAY,CAAEA,CAFZ,CAGFyB,OAAO,CAAEhB,CAAC,CAACC,GAAF,CAAMe,OAHb,CAJH,CASHC,OAAO,CAAE,iBAASH,CAAT,CAAe,CAEpBnB,CAAQ,CAACuB,QAAT,CAAoBJ,CAAI,CAACK,UAAzB,CACA,KAAKC,aAAL,CAAmBzB,CAAnB,CACH,CAbE,CAcHyB,aAAa,CAAE,uBAASzB,CAAT,CAAmB,CAC9B,GAAI0B,CAAAA,CAAI,CAAG,IAAX,CACA,GAAI1B,CAAQ,CAAC2B,MAAb,CAAqB,CACjB1B,MAAM,CAACsB,QAAP,CAAkBtB,MAAM,CAACsB,QAC5B,CAFD,IAEO,CACHK,UAAU,CAAC,UAAW,CAClBF,CAAI,CAACD,aAAL,CAAmBzB,CAAnB,CACH,CAFS,CAEP,GAFO,CAGb,CACJ,CAvBE,CAAP,CAyBH,CAnDD,CAoDH,CAtDE,CAwDV,CAzDK,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Javascript controller for the Turnitin Cloud Viewer launch.\n *\n * @package plagiarism_turnitinsim\n * @copyright 2017 Turnitin\n * @author John McGettrick \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n/**\n * @module plagiarism_turnitinsim/cv_launch\n */\n\ndefine(['jquery', 'core/str'], function($, str) {\n return {\n openCv: function() {\n $(document).on('click', '.or_score', function() {\n\n // Moodle forums strip ids from elements so we have to use classes.\n var classList = $(this).parent().attr('class').split(/\\s+/);\n var submissionid = 0;\n $(classList).each(function(index) {\n if (classList[index].match(\"^submission_\")) {\n submissionid = classList[index].split(\"_\")[1];\n }\n });\n\n // Launch the Cloud Viewer in a new window.\n // It is being done this way as in the future we may have to listen for it closing and act on it.\n var dvWindow = window.open('', 'cvWindow');\n var loading = '
';\n var icon = M.cfg.wwwroot + '/plagiarism/turnitinsim/pix/tiiIcon.svg';\n loading += '';\n\n str.get_string('loadingcv', 'plagiarism_turnitinsim').done(function(text) {\n loading += '

' + text + '

';\n $('.eulacontainer').hide().html(text).fadeIn();\n });\n\n loading += '
';\n $(dvWindow.document.body).html(loading);\n\n $.ajax({\n type: \"GET\",\n url: M.cfg.wwwroot + \"/plagiarism/turnitinsim/ajax/cv.php\",\n dataType: \"json\",\n data: {\n action: 'request_cv_launch',\n submissionid: submissionid,\n sesskey: M.cfg.sesskey\n },\n success: function(data) {\n // Redirect opened window to returned URL.\n dvWindow.location = data.viewer_url;\n this.checkDVClosed(dvWindow);\n },\n checkDVClosed: function(dvWindow) {\n var that = this;\n if (dvWindow.closed) {\n window.location = window.location;\n } else {\n setTimeout(function() {\n that.checkDVClosed(dvWindow);\n }, 500);\n }\n }\n });\n });\n }\n };\n});"],"file":"cv_launch.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/cv_launch.js"],"names":["define","$","str","openCv","document","on","classList","parent","attr","split","submissionid","each","index","match","cvWindow","window","open","loading","icon","M","cfg","wwwroot","get_string","done","text","hide","html","fadeIn","body","ajax","type","url","dataType","data","action","sesskey","success","location","viewer_url","checkDVClosed","that","closed","setTimeout"],"mappings":"AA4BAA,OAAM,oCAAC,CAAC,QAAD,CAAW,UAAX,CAAD,CAAyB,SAASC,CAAT,CAAYC,CAAZ,CAAiB,CAC5C,MAAO,CACHC,MAAM,CAAE,iBAAW,CACfF,CAAC,CAACG,QAAD,CAAD,CAAYC,EAAZ,CAAe,OAAf,CAAwB,WAAxB,CAAqC,UAAW,IAGxCC,CAAAA,CAAS,CAAGL,CAAC,CAAC,IAAD,CAAD,CAAQM,MAAR,GAAiBC,IAAjB,CAAsB,OAAtB,EAA+BC,KAA/B,CAAqC,KAArC,CAH4B,CAIxCC,CAAY,CAAG,CAJyB,CAK5CT,CAAC,CAACK,CAAD,CAAD,CAAaK,IAAb,CAAkB,SAASC,CAAT,CAAgB,CAC9B,GAAIN,CAAS,CAACM,CAAD,CAAT,CAAiBC,KAAjB,CAAuB,cAAvB,CAAJ,CAA4C,CACxCH,CAAY,CAAGJ,CAAS,CAACM,CAAD,CAAT,CAAiBH,KAAjB,CAAuB,GAAvB,EAA4B,CAA5B,CAClB,CACJ,CAJD,EAL4C,GAYxCK,CAAAA,CAAQ,CAAGC,MAAM,CAACC,IAAP,EAZ6B,CAaxCC,CAAO,CAAG,6DAb8B,CAcxCC,CAAI,CAAGC,CAAC,CAACC,GAAF,CAAMC,OAAN,CAAgB,yCAdiB,CAe5CJ,CAAO,EAAI,cAAeC,CAAf,CAAsB,0CAAjC,CAEAhB,CAAG,CAACoB,UAAJ,CAAe,WAAf,CAA4B,wBAA5B,EAAsDC,IAAtD,CAA2D,SAASC,CAAT,CAAe,CACtEP,CAAO,EAAI,2DAA2DO,CAA3D,CAAkE,MAA7E,CACAvB,CAAC,CAAC,gBAAD,CAAD,CAAoBwB,IAApB,GAA2BC,IAA3B,CAAgCF,CAAhC,EAAsCG,MAAtC,EACH,CAHD,EAKAV,CAAO,EAAI,QAAX,CACAhB,CAAC,CAACa,CAAQ,CAACV,QAAT,CAAkBwB,IAAnB,CAAD,CAA0BF,IAA1B,CAA+BT,CAA/B,EAEAhB,CAAC,CAAC4B,IAAF,CAAO,CACHC,IAAI,CAAE,KADH,CAEHC,GAAG,CAAEZ,CAAC,CAACC,GAAF,CAAMC,OAAN,CAAgB,qCAFlB,CAGHW,QAAQ,CAAE,MAHP,CAIHC,IAAI,CAAE,CACFC,MAAM,CAAE,mBADN,CAEFxB,YAAY,CAAEA,CAFZ,CAGFyB,OAAO,CAAEhB,CAAC,CAACC,GAAF,CAAMe,OAHb,CAJH,CASHC,OAAO,CAAE,iBAASH,CAAT,CAAe,CAEpBnB,CAAQ,CAACuB,QAAT,CAAoBJ,CAAI,CAACK,UAAzB,CACA,KAAKC,aAAL,CAAmBzB,CAAnB,CACH,CAbE,CAcHyB,aAAa,CAAE,uBAASzB,CAAT,CAAmB,CAC9B,GAAI0B,CAAAA,CAAI,CAAG,IAAX,CACA,GAAI1B,CAAQ,CAAC2B,MAAb,CAAqB,CACjB1B,MAAM,CAACsB,QAAP,CAAkBtB,MAAM,CAACsB,QAC5B,CAFD,IAEO,CACHK,UAAU,CAAC,UAAW,CAClBF,CAAI,CAACD,aAAL,CAAmBzB,CAAnB,CACH,CAFS,CAEP,GAFO,CAGb,CACJ,CAvBE,CAAP,CAyBH,CAlDD,CAmDH,CArDE,CAuDV,CAxDK,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Javascript controller for the Turnitin Cloud Viewer launch.\n *\n * @package plagiarism_turnitinsim\n * @copyright 2017 Turnitin\n * @author John McGettrick \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n/**\n * @module plagiarism_turnitinsim/cv_launch\n */\n\ndefine(['jquery', 'core/str'], function($, str) {\n return {\n openCv: function() {\n $(document).on('click', '.or_score', function() {\n\n // Moodle forums strip ids from elements so we have to use classes.\n var classList = $(this).parent().attr('class').split(/\\s+/);\n var submissionid = 0;\n $(classList).each(function(index) {\n if (classList[index].match(\"^submission_\")) {\n submissionid = classList[index].split(\"_\")[1];\n }\n });\n\n // Launch the Cloud Viewer in a new window.\n var cvWindow = window.open();\n var loading = '
';\n var icon = M.cfg.wwwroot + '/plagiarism/turnitinsim/pix/tiiIcon.svg';\n loading += '';\n\n str.get_string('loadingcv', 'plagiarism_turnitinsim').done(function(text) {\n loading += '

' + text + '

';\n $('.eulacontainer').hide().html(text).fadeIn();\n });\n\n loading += '
';\n $(cvWindow.document.body).html(loading);\n\n $.ajax({\n type: \"GET\",\n url: M.cfg.wwwroot + \"/plagiarism/turnitinsim/ajax/cv.php\",\n dataType: \"json\",\n data: {\n action: 'request_cv_launch',\n submissionid: submissionid,\n sesskey: M.cfg.sesskey\n },\n success: function(data) {\n // Redirect opened window to returned URL.\n cvWindow.location = data.viewer_url;\n this.checkDVClosed(cvWindow);\n },\n checkDVClosed: function(cvWindow) {\n var that = this;\n if (cvWindow.closed) {\n window.location = window.location;\n } else {\n setTimeout(function() {\n that.checkDVClosed(cvWindow);\n }, 500);\n }\n }\n });\n });\n }\n };\n});"],"file":"cv_launch.min.js"} \ No newline at end of file diff --git a/amd/src/cv_launch.js b/amd/src/cv_launch.js index 587d930..a638cb4 100644 --- a/amd/src/cv_launch.js +++ b/amd/src/cv_launch.js @@ -41,8 +41,7 @@ define(['jquery', 'core/str'], function($, str) { }); // Launch the Cloud Viewer in a new window. - // It is being done this way as in the future we may have to listen for it closing and act on it. - var dvWindow = window.open('', 'cvWindow'); + var cvWindow = window.open(); var loading = '
'; var icon = M.cfg.wwwroot + '/plagiarism/turnitinsim/pix/tiiIcon.svg'; loading += ''; @@ -53,7 +52,7 @@ define(['jquery', 'core/str'], function($, str) { }); loading += '
'; - $(dvWindow.document.body).html(loading); + $(cvWindow.document.body).html(loading); $.ajax({ type: "GET", @@ -66,16 +65,16 @@ define(['jquery', 'core/str'], function($, str) { }, success: function(data) { // Redirect opened window to returned URL. - dvWindow.location = data.viewer_url; - this.checkDVClosed(dvWindow); + cvWindow.location = data.viewer_url; + this.checkDVClosed(cvWindow); }, - checkDVClosed: function(dvWindow) { + checkDVClosed: function(cvWindow) { var that = this; - if (dvWindow.closed) { + if (cvWindow.closed) { window.location = window.location; } else { setTimeout(function() { - that.checkDVClosed(dvWindow); + that.checkDVClosed(cvWindow); }, 500); } } From 54eee2b8339b0faf3e150e9059c55bffc9c7907f Mon Sep 17 00:00:00 2001 From: David Winn Date: Thu, 14 May 2020 13:55:04 +0100 Subject: [PATCH 11/48] Adding unit test --- tests/lib_test.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/lib_test.php b/tests/lib_test.php index e291344..53c3f40 100644 --- a/tests/lib_test.php +++ b/tests/lib_test.php @@ -305,12 +305,24 @@ public function test_get_links_with_submission() { $plagiarismturnitinsim->get_links($linkarray) ); - // Change submission status to Eula not accpetd and verify that the error message is displayed. + // Change submission status to Eula not accepted and verify that the error message is displayed. $tssubmission->setstatus(TURNITINSIM_SUBMISSION_STATUS_EULA_NOT_ACCEPTED); $tssubmission->update(); + $output = $plagiarismturnitinsim->get_links($linkarray); + $this->assertContains( get_string( 'submissiondisplaystatus:awaitingeula', 'plagiarism_turnitinsim'), - $plagiarismturnitinsim->get_links($linkarray) + $output + ); + $this->assertContains( + get_string( 'submissiondisplayerror:eulanotaccepted_help', 'plagiarism_turnitinsim'), + $output + ); + // Log instructor in and check they do not see a resubmit link. + $this->setUser($this->instructor); + $this->assertNotContains( + get_string( 'resubmittoturnitin', 'plagiarism_turnitinsim'), + $output ); // Change submission status to a non constant and verify that the default is displayed. From e3fdc2c34881bcd8db2d8277e07fa4da49258c68 Mon Sep 17 00:00:00 2001 From: David Winn Date: Thu, 14 May 2020 13:56:55 +0100 Subject: [PATCH 12/48] removing extra spaces --- tests/lib_test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/lib_test.php b/tests/lib_test.php index 53c3f40..d26f99e 100644 --- a/tests/lib_test.php +++ b/tests/lib_test.php @@ -311,17 +311,17 @@ public function test_get_links_with_submission() { $output = $plagiarismturnitinsim->get_links($linkarray); $this->assertContains( - get_string( 'submissiondisplaystatus:awaitingeula', 'plagiarism_turnitinsim'), + get_string('submissiondisplaystatus:awaitingeula', 'plagiarism_turnitinsim'), $output ); $this->assertContains( - get_string( 'submissiondisplayerror:eulanotaccepted_help', 'plagiarism_turnitinsim'), + get_string('submissiondisplayerror:eulanotaccepted_help', 'plagiarism_turnitinsim'), $output ); // Log instructor in and check they do not see a resubmit link. $this->setUser($this->instructor); $this->assertNotContains( - get_string( 'resubmittoturnitin', 'plagiarism_turnitinsim'), + get_string('resubmittoturnitin', 'plagiarism_turnitinsim'), $output ); From 49c6a4e80ce477e90ebf9bb235b25d77cb76ed7b Mon Sep 17 00:00:00 2001 From: Grijesh Saini Date: Thu, 21 May 2020 18:05:33 +0530 Subject: [PATCH 13/48] INT-14388 - Checking submission status before sending report generation request to TCA. --- classes/submission.class.php | 2 +- classes/task.class.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/classes/submission.class.php b/classes/submission.class.php index 4f841df..24201e7 100644 --- a/classes/submission.class.php +++ b/classes/submission.class.php @@ -977,7 +977,7 @@ public function is_submission_anonymous() { * @return bool|mixed * @throws coding_exception */ - private function get_submission_info() { + public function get_submission_info() { try { $endpoint = TURNITINSIM_ENDPOINT_GET_SUBMISSION_INFO; $endpoint = str_replace('{{submission_id}}', $this->getturnitinid(), $endpoint); diff --git a/classes/task.class.php b/classes/task.class.php index 7e13b21..55c0c31 100644 --- a/classes/task.class.php +++ b/classes/task.class.php @@ -166,6 +166,7 @@ public function get_reports() { // webhook callback so ignore anything submitted to Turnitin in the 2 minutes. // Otherwise retrieve originality score if we haven't received it back within 5 minutes. if ($tssubmission->getstatus() == TURNITINSIM_SUBMISSION_STATUS_UPLOADED + && $tssubmission->get_submission_info()->status === TURNITINSIM_SUBMISSION_STATUS_COMPLETE && $tssubmission->getsubmittedtime() < (time() - $this->get_report_gen_request_delay())) { $tssubmission->request_turnitin_report_generation(); From f80390ad973ef00eacaf2c2c495f4c33a84dd193 Mon Sep 17 00:00:00 2001 From: Grijesh Saini Date: Wed, 27 May 2020 15:04:38 +0530 Subject: [PATCH 14/48] INT-14388 - Checking submission status before sending report generation request to TCA. --- classes/submission.class.php | 61 ++++++++++++++++++++++++++++++++++++ classes/task.class.php | 7 +++-- 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/classes/submission.class.php b/classes/submission.class.php index 24201e7..594d5fa 100644 --- a/classes/submission.class.php +++ b/classes/submission.class.php @@ -598,6 +598,36 @@ public function handle_upload_response($params, $filename) { $this->update(); } + /** + * Handle the API submission info response and callback from Turnitin. + * + * @param object $params containing the upload response. + * @return bool, true if submission status is complete else false. + */ + public function handle_submission_info_response($params) { + $issubmissioncomplete = false; + + //Handle scenario if Turnitin API is returning error. + //Set status as processing, so it will be retried. + if (!empty($params->httpstatus) && ($params->httpstatus !== TURNITINSIM_HTTP_OK)) { + $params->status=TURNITINSIM_SUBMISSION_STATUS_PROCESSING; + } + + // On success, reset retries. On error, never retry. + if ($params->status === TURNITINSIM_SUBMISSION_STATUS_COMPLETE) { + $this->reset_retries(); + $issubmissioncomplete = true; + } else if ($params->status === TURNITINSIM_SUBMISSION_STATUS_PROCESSING) { // Only possible when running through cron + $this->update_report_generation_retries(); + } else { + $this->set_error_with_max_retry_attempts($params->error_code, TURNITINSIM_REPORT_GEN_MAX_ATTEMPTS); + } + + $this->update(); + + return $issubmissioncomplete; + } + /** * Send digital receipts to the instructors and student. * @@ -1328,4 +1358,35 @@ public function gettiiretrytime() { public function settiiretrytime($tiiretrytime) { $this->tiiretrytime = $tiiretrytime; } + + /** + * Reset retries. + */ + private function reset_retries() { + $this->settiiattempts(0); + $this->settiiretrytime(0); + } + + /** + * @param $error string Error code from Turnitin. + * @param $retry_attempts int Maximum retry attempts. + */ + private function set_error_with_max_retry_attempts($error, $retry_attempts) { + $this->settiiattempts($retry_attempts); + $this->seterrormessage($error); + $this->setstatus(TURNITINSIM_SUBMISSION_STATUS_ERROR); + } + + private function update_report_generation_retries() { + $this->settiiattempts($this->gettiiattempts() + 1); + // On first attempt set retry time as 10 minutes. + if ($this->gettiiattempts() === 1) { + $this->settiiretrytime(time() + 600); + } else if ($this->gettiiattempts() === TURNITINSIM_REPORT_GEN_MAX_ATTEMPTS) { + // Todo Create error code for Max retries. + $this->set_error_with_max_retry_attempts('', TURNITINSIM_REPORT_GEN_MAX_ATTEMPTS); + } else { + $this->settiiretrytime(time() + ($this->gettiiattempts() * TURNITINSIM_REPORT_GEN_RETRY_WAIT_SECONDS)); + } + } } diff --git a/classes/task.class.php b/classes/task.class.php index 55c0c31..339b519 100644 --- a/classes/task.class.php +++ b/classes/task.class.php @@ -166,10 +166,11 @@ public function get_reports() { // webhook callback so ignore anything submitted to Turnitin in the 2 minutes. // Otherwise retrieve originality score if we haven't received it back within 5 minutes. if ($tssubmission->getstatus() == TURNITINSIM_SUBMISSION_STATUS_UPLOADED - && $tssubmission->get_submission_info()->status === TURNITINSIM_SUBMISSION_STATUS_COMPLETE && $tssubmission->getsubmittedtime() < (time() - $this->get_report_gen_request_delay())) { - $tssubmission->request_turnitin_report_generation(); - + // If submission status has completed then request for report generation. + if ($tssubmission->handle_submission_info_response($tssubmission->get_submission_info())) { + $tssubmission->request_turnitin_report_generation(); + } } else if ($tssubmission->getstatus() != TURNITINSIM_SUBMISSION_STATUS_UPLOADED && $tssubmission->getrequestedtime() < (time() - $this->get_report_gen_score_delay())) { $tssubmission->request_turnitin_report_score(); From ba05d90a3416cd757b75b201e42b95db495a51a8 Mon Sep 17 00:00:00 2001 From: Grijesh Saini Date: Thu, 28 May 2020 02:44:37 +0530 Subject: [PATCH 15/48] INT-14388 - Increased first attempt time to 15 minutes. --- classes/submission.class.php | 7 +++---- utilities/constants.php | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/classes/submission.class.php b/classes/submission.class.php index 594d5fa..d4a5928 100644 --- a/classes/submission.class.php +++ b/classes/submission.class.php @@ -617,7 +617,7 @@ public function handle_submission_info_response($params) { if ($params->status === TURNITINSIM_SUBMISSION_STATUS_COMPLETE) { $this->reset_retries(); $issubmissioncomplete = true; - } else if ($params->status === TURNITINSIM_SUBMISSION_STATUS_PROCESSING) { // Only possible when running through cron + } else if ($params->status === TURNITINSIM_SUBMISSION_STATUS_PROCESSING) { $this->update_report_generation_retries(); } else { $this->set_error_with_max_retry_attempts($params->error_code, TURNITINSIM_REPORT_GEN_MAX_ATTEMPTS); @@ -1381,10 +1381,9 @@ private function update_report_generation_retries() { $this->settiiattempts($this->gettiiattempts() + 1); // On first attempt set retry time as 10 minutes. if ($this->gettiiattempts() === 1) { - $this->settiiretrytime(time() + 600); + $this->settiiretrytime(time() + TURNITINSIM_REPORT_GEN_FIRST_ATTEMPT_RETRY_WAIT_SECONDS); } else if ($this->gettiiattempts() === TURNITINSIM_REPORT_GEN_MAX_ATTEMPTS) { - // Todo Create error code for Max retries. - $this->set_error_with_max_retry_attempts('', TURNITINSIM_REPORT_GEN_MAX_ATTEMPTS); + $this->set_error_with_max_retry_attempts('retrylimitexceeded', TURNITINSIM_REPORT_GEN_MAX_ATTEMPTS); } else { $this->settiiretrytime(time() + ($this->gettiiattempts() * TURNITINSIM_REPORT_GEN_RETRY_WAIT_SECONDS)); } diff --git a/utilities/constants.php b/utilities/constants.php index d749ff0..d527f27 100644 --- a/utilities/constants.php +++ b/utilities/constants.php @@ -101,6 +101,7 @@ define('TURNITINSIM_REPORT_GEN_EXCLUDE_SELF_GROUP', 'GROUP_CONTEXT'); define('TURNITINSIM_REPORT_GEN_MAX_ATTEMPTS', 3); define('TURNITINSIM_REPORT_GEN_RETRY_WAIT_SECONDS', 3600); +define('TURNITINSIM_REPORT_GEN_FIRST_ATTEMPT_RETRY_WAIT_SECONDS', 900); // Metadata. define('TURNITINSIM_GROUP_TYPE_ASSIGNMENT', 'ASSIGNMENT'); From c624965bfa487205202c569612499816cf06bf72 Mon Sep 17 00:00:00 2001 From: Grijesh Saini Date: Fri, 29 May 2020 01:18:01 +0530 Subject: [PATCH 16/48] INT-14388 - Refactor and added test cases. --- classes/submission.class.php | 5 +- tests/classes/tssubmission_test.php | 142 ++++++++++++++++++++++++++++ 2 files changed, 145 insertions(+), 2 deletions(-) diff --git a/classes/submission.class.php b/classes/submission.class.php index d4a5928..3809909 100644 --- a/classes/submission.class.php +++ b/classes/submission.class.php @@ -620,7 +620,8 @@ public function handle_submission_info_response($params) { } else if ($params->status === TURNITINSIM_SUBMISSION_STATUS_PROCESSING) { $this->update_report_generation_retries(); } else { - $this->set_error_with_max_retry_attempts($params->error_code, TURNITINSIM_REPORT_GEN_MAX_ATTEMPTS); + $error = isset($params->error_code) ? $params->error_code : get_string('submissiondisplaystatus:unknown', 'plagiarism_turnitinsim'); + $this->set_error_with_max_retry_attempts($error, TURNITINSIM_REPORT_GEN_MAX_ATTEMPTS); } $this->update(); @@ -1383,7 +1384,7 @@ private function update_report_generation_retries() { if ($this->gettiiattempts() === 1) { $this->settiiretrytime(time() + TURNITINSIM_REPORT_GEN_FIRST_ATTEMPT_RETRY_WAIT_SECONDS); } else if ($this->gettiiattempts() === TURNITINSIM_REPORT_GEN_MAX_ATTEMPTS) { - $this->set_error_with_max_retry_attempts('retrylimitexceeded', TURNITINSIM_REPORT_GEN_MAX_ATTEMPTS); + $this->set_error_with_max_retry_attempts(get_string('submissiondisplaystatus:unknown', 'plagiarism_turnitinsim'), TURNITINSIM_REPORT_GEN_MAX_ATTEMPTS); } else { $this->settiiretrytime(time() + ($this->gettiiattempts() * TURNITINSIM_REPORT_GEN_RETRY_WAIT_SECONDS)); } diff --git a/tests/classes/tssubmission_test.php b/tests/classes/tssubmission_test.php index eb783a9..c76e61c 100644 --- a/tests/classes/tssubmission_test.php +++ b/tests/classes/tssubmission_test.php @@ -1947,4 +1947,146 @@ public function test_handle_similarity_response_status_sets_correct_values_if_re $this->assertEquals(1, $record->tiiattempts); $this->assertGreaterThan(time(), $record->tiiretrytime); } + + /** + * Test the submission info status when submission is in processing state. + */ + public function test_handle_submission_info_if_submission_is_in_processing_state() { + global $DB; + + $this->resetAfterTest(); + + $params = new stdClass(); + $params->status = TURNITINSIM_SUBMISSION_STATUS_PROCESSING; + + $tssubmission = new plagiarism_turnitinsim_submission(); + $tssubmission->setcm(1); + $tssubmission->setuserid(1); + $tssubmission->setsubmitter(1); + $tssubmission->setstatus(TURNITINSIM_SUBMISSION_STATUS_UPLOADED); + $tssubmission->setidentifier('6be293577b6b42bd04accd034bb40a8ca0b4bdd6'); + $tssubmission->calculate_generation_time(); + $tssubmission->update(); + + $tssubmission->handle_submission_info_response($params); + + $record = $DB->get_record('plagiarism_turnitinsim_sub', ['cm' => 1]); + + $this->assertEquals(TURNITINSIM_SUBMISSION_STATUS_UPLOADED, $record->status); + $this->assertEquals(1, $record->tiiattempts); + $this->assertGreaterThan(time(), $record->tiiretrytime); + + // Prepare to test scenario where max attempts is reached. + $tssubmission->settiiattempts(TURNITINSIM_REPORT_GEN_MAX_ATTEMPTS - 1); + $tssubmission->update(); + + $tssubmission->handle_submission_info_response($params); + + $record = $DB->get_record('plagiarism_turnitinsim_sub', ['cm' => 1]); + + $this->assertEquals(TURNITINSIM_SUBMISSION_STATUS_ERROR, $record->status); + $this->assertEquals(TURNITINSIM_REPORT_GEN_MAX_ATTEMPTS, $record->tiiattempts); + $this->assertEquals(get_string('submissiondisplaystatus:unknown', 'plagiarism_turnitinsim'), $record->errormessage); + } + + /** + * Test the submission info status when turnitin returns error. + */ + public function test_handle_submission_info_if_turnitin_returns_error() { + global $DB; + + $this->resetAfterTest(); + + $params = new stdClass(); + $params->httpstatus = 500; + + $tssubmission = new plagiarism_turnitinsim_submission(); + $tssubmission->setcm(1); + $tssubmission->setuserid(1); + $tssubmission->setsubmitter(1); + $tssubmission->setstatus(TURNITINSIM_SUBMISSION_STATUS_UPLOADED); + $tssubmission->setidentifier('6be293577b6b42bd04accd034bb40a8ca0b4bdd6'); + $tssubmission->calculate_generation_time(); + $tssubmission->update(); + + $tssubmission->handle_submission_info_response($params); + + $record = $DB->get_record('plagiarism_turnitinsim_sub', ['cm' => 1]); + + $this->assertEquals(TURNITINSIM_SUBMISSION_STATUS_UPLOADED, $record->status); + $this->assertEquals(1, $record->tiiattempts); + $this->assertGreaterThan(time(), $record->tiiretrytime); + + // Prepare to test scenario where max attempts is reached. + $tssubmission->settiiattempts(TURNITINSIM_REPORT_GEN_MAX_ATTEMPTS - 1); + $tssubmission->update(); + + $tssubmission->handle_submission_info_response($params); + + $record = $DB->get_record('plagiarism_turnitinsim_sub', ['cm' => 1]); + + $this->assertEquals(TURNITINSIM_SUBMISSION_STATUS_ERROR, $record->status); + $this->assertEquals(TURNITINSIM_REPORT_GEN_MAX_ATTEMPTS, $record->tiiattempts); + $this->assertEquals(get_string('submissiondisplaystatus:unknown', 'plagiarism_turnitinsim'), $record->errormessage); + } + + /** + * Test the submission info status when submission is in complete state. + */ + public function test_handle_submission_info_if_submission_is_complete() { + global $DB; + + $this->resetAfterTest(); + + $params = new stdClass(); + $params->status = TURNITINSIM_SUBMISSION_STATUS_COMPLETE; + + $tssubmission = new plagiarism_turnitinsim_submission(); + $tssubmission->setcm(1); + $tssubmission->setuserid(1); + $tssubmission->setsubmitter(1); + $tssubmission->setstatus(TURNITINSIM_SUBMISSION_STATUS_UPLOADED); + $tssubmission->setidentifier('6be293577b6b42bd04accd034bb40a8ca0b4bdd6'); + $tssubmission->calculate_generation_time(); + $tssubmission->update(); + + $tssubmission->handle_submission_info_response($params); + + $record = $DB->get_record('plagiarism_turnitinsim_sub', ['cm' => 1]); + + $this->assertEquals(TURNITINSIM_SUBMISSION_STATUS_UPLOADED, $record->status); + $this->assertEquals(0, $record->tiiattempts); + $this->assertEquals(0, $record->tiiretrytime); + } + + /** + * Test the submission info status when submission is in error state. + */ + public function test_handle_submission_info_if_submission_is_in_error_state() { + global $DB; + + $this->resetAfterTest(); + + $params = new stdClass(); + $params->status = TURNITINSIM_SUBMISSION_STATUS_ERROR; + $params->error_code = TURNITINSIM_SUBMISSION_STATUS_TOO_LITTLE_TEXT; + + $tssubmission = new plagiarism_turnitinsim_submission(); + $tssubmission->setcm(1); + $tssubmission->setuserid(1); + $tssubmission->setsubmitter(1); + $tssubmission->setstatus(TURNITINSIM_SUBMISSION_STATUS_UPLOADED); + $tssubmission->setidentifier('6be293577b6b42bd04accd034bb40a8ca0b4bdd6'); + $tssubmission->calculate_generation_time(); + $tssubmission->update(); + + $tssubmission->handle_submission_info_response($params); + + $record = $DB->get_record('plagiarism_turnitinsim_sub', ['cm' => 1]); + + $this->assertEquals(TURNITINSIM_SUBMISSION_STATUS_ERROR, $record->status); + $this->assertEquals(TURNITINSIM_REPORT_GEN_MAX_ATTEMPTS, $record->tiiattempts); + $this->assertEquals(0, $record->tiiretrytime); + $this->assertEquals(TURNITINSIM_SUBMISSION_STATUS_TOO_LITTLE_TEXT, $record->errormessage); + } } \ No newline at end of file From a2fc9c0cc7861ae172567bdeecee69d69124c59a Mon Sep 17 00:00:00 2001 From: Grijesh Saini Date: Fri, 29 May 2020 01:19:37 +0530 Subject: [PATCH 17/48] INT-14388 - Improved comment. --- classes/submission.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/submission.class.php b/classes/submission.class.php index 3809909..75a7cfe 100644 --- a/classes/submission.class.php +++ b/classes/submission.class.php @@ -1380,7 +1380,7 @@ private function set_error_with_max_retry_attempts($error, $retry_attempts) { private function update_report_generation_retries() { $this->settiiattempts($this->gettiiattempts() + 1); - // On first attempt set retry time as 10 minutes. + // On first attempt set retry time as 15 minutes. if ($this->gettiiattempts() === 1) { $this->settiiretrytime(time() + TURNITINSIM_REPORT_GEN_FIRST_ATTEMPT_RETRY_WAIT_SECONDS); } else if ($this->gettiiattempts() === TURNITINSIM_REPORT_GEN_MAX_ATTEMPTS) { From 209d401a959c75612d96f1d715bb15fa257ee4d6 Mon Sep 17 00:00:00 2001 From: Grijesh Saini Date: Fri, 29 May 2020 01:22:51 +0530 Subject: [PATCH 18/48] INT-14388 - Added extra assertion. --- tests/classes/tssubmission_test.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/classes/tssubmission_test.php b/tests/classes/tssubmission_test.php index c76e61c..6362e51 100644 --- a/tests/classes/tssubmission_test.php +++ b/tests/classes/tssubmission_test.php @@ -1968,10 +1968,11 @@ public function test_handle_submission_info_if_submission_is_in_processing_state $tssubmission->calculate_generation_time(); $tssubmission->update(); - $tssubmission->handle_submission_info_response($params); + $issubmissioncomplete = $tssubmission->handle_submission_info_response($params); $record = $DB->get_record('plagiarism_turnitinsim_sub', ['cm' => 1]); + $this->assertFalse($issubmissioncomplete); $this->assertEquals(TURNITINSIM_SUBMISSION_STATUS_UPLOADED, $record->status); $this->assertEquals(1, $record->tiiattempts); $this->assertGreaterThan(time(), $record->tiiretrytime); @@ -1980,10 +1981,11 @@ public function test_handle_submission_info_if_submission_is_in_processing_state $tssubmission->settiiattempts(TURNITINSIM_REPORT_GEN_MAX_ATTEMPTS - 1); $tssubmission->update(); - $tssubmission->handle_submission_info_response($params); + $issubmissioncomplete = $tssubmission->handle_submission_info_response($params); $record = $DB->get_record('plagiarism_turnitinsim_sub', ['cm' => 1]); + $this->assertFalse($issubmissioncomplete); $this->assertEquals(TURNITINSIM_SUBMISSION_STATUS_ERROR, $record->status); $this->assertEquals(TURNITINSIM_REPORT_GEN_MAX_ATTEMPTS, $record->tiiattempts); $this->assertEquals(get_string('submissiondisplaystatus:unknown', 'plagiarism_turnitinsim'), $record->errormessage); @@ -2009,10 +2011,11 @@ public function test_handle_submission_info_if_turnitin_returns_error() { $tssubmission->calculate_generation_time(); $tssubmission->update(); - $tssubmission->handle_submission_info_response($params); + $issubmissioncomplete = $tssubmission->handle_submission_info_response($params); $record = $DB->get_record('plagiarism_turnitinsim_sub', ['cm' => 1]); + $this->assertFalse($issubmissioncomplete); $this->assertEquals(TURNITINSIM_SUBMISSION_STATUS_UPLOADED, $record->status); $this->assertEquals(1, $record->tiiattempts); $this->assertGreaterThan(time(), $record->tiiretrytime); @@ -2021,10 +2024,11 @@ public function test_handle_submission_info_if_turnitin_returns_error() { $tssubmission->settiiattempts(TURNITINSIM_REPORT_GEN_MAX_ATTEMPTS - 1); $tssubmission->update(); - $tssubmission->handle_submission_info_response($params); + $issubmissioncomplete = $tssubmission->handle_submission_info_response($params); $record = $DB->get_record('plagiarism_turnitinsim_sub', ['cm' => 1]); + $this->assertFalse($issubmissioncomplete); $this->assertEquals(TURNITINSIM_SUBMISSION_STATUS_ERROR, $record->status); $this->assertEquals(TURNITINSIM_REPORT_GEN_MAX_ATTEMPTS, $record->tiiattempts); $this->assertEquals(get_string('submissiondisplaystatus:unknown', 'plagiarism_turnitinsim'), $record->errormessage); @@ -2050,10 +2054,11 @@ public function test_handle_submission_info_if_submission_is_complete() { $tssubmission->calculate_generation_time(); $tssubmission->update(); - $tssubmission->handle_submission_info_response($params); + $issubmissioncomplete = $tssubmission->handle_submission_info_response($params); $record = $DB->get_record('plagiarism_turnitinsim_sub', ['cm' => 1]); + $this->assertTrue($issubmissioncomplete); $this->assertEquals(TURNITINSIM_SUBMISSION_STATUS_UPLOADED, $record->status); $this->assertEquals(0, $record->tiiattempts); $this->assertEquals(0, $record->tiiretrytime); @@ -2080,13 +2085,14 @@ public function test_handle_submission_info_if_submission_is_in_error_state() { $tssubmission->calculate_generation_time(); $tssubmission->update(); - $tssubmission->handle_submission_info_response($params); + $issubmissioncomplete = $tssubmission->handle_submission_info_response($params); $record = $DB->get_record('plagiarism_turnitinsim_sub', ['cm' => 1]); + $this->assertFalse($issubmissioncomplete); $this->assertEquals(TURNITINSIM_SUBMISSION_STATUS_ERROR, $record->status); $this->assertEquals(TURNITINSIM_REPORT_GEN_MAX_ATTEMPTS, $record->tiiattempts); $this->assertEquals(0, $record->tiiretrytime); $this->assertEquals(TURNITINSIM_SUBMISSION_STATUS_TOO_LITTLE_TEXT, $record->errormessage); } -} \ No newline at end of file +} From 10c79f75136a63cc50ed9287f565c264701250fa Mon Sep 17 00:00:00 2001 From: Grijesh Saini Date: Fri, 29 May 2020 16:58:29 +0530 Subject: [PATCH 19/48] INT-14388 - Added docs. --- classes/submission.class.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/classes/submission.class.php b/classes/submission.class.php index 75a7cfe..6b2d15b 100644 --- a/classes/submission.class.php +++ b/classes/submission.class.php @@ -1369,6 +1369,8 @@ private function reset_retries() { } /** + * Common method to update maximum retry attempts and error Status. + * * @param $error string Error code from Turnitin. * @param $retry_attempts int Maximum retry attempts. */ From f369c461c390e9e2262ceda81cf93d61bfa1db5d Mon Sep 17 00:00:00 2001 From: Grijesh Saini Date: Fri, 29 May 2020 17:23:01 +0530 Subject: [PATCH 20/48] INT-14388 - Added docs. --- classes/submission.class.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/classes/submission.class.php b/classes/submission.class.php index 6b2d15b..d9fd6f9 100644 --- a/classes/submission.class.php +++ b/classes/submission.class.php @@ -1380,6 +1380,9 @@ private function set_error_with_max_retry_attempts($error, $retry_attempts) { $this->setstatus(TURNITINSIM_SUBMISSION_STATUS_ERROR); } + /** + * Update report generation retries limit and time. + */ private function update_report_generation_retries() { $this->settiiattempts($this->gettiiattempts() + 1); // On first attempt set retry time as 15 minutes. From dc6a08256b3fb4d5433d15a6f57cdb3a53416855 Mon Sep 17 00:00:00 2001 From: David Winn Date: Thu, 11 Jun 2020 17:39:17 +0100 Subject: [PATCH 21/48] Handling of turnitinsim_use deprecation --- classes/setup_form.class.php | 3 +- db/install.php | 2 +- db/uninstall.php | 3 +- db/upgrade.php | 13 +++ lib.php | 20 +++++ tests/classes/assign_test.php | 8 +- tests/classes/tssetupform_test.php | 5 +- tests/classes/tssubmission_test.php | 12 +-- tests/lib_test.php | 64 +++++++++----- tests/utilities/handle_deprecation_test.php | 92 +++++++++++++++++++++ utilities/handle_deprecation.php | 51 +++++++++++- version.php | 2 +- 12 files changed, 238 insertions(+), 37 deletions(-) create mode 100644 tests/utilities/handle_deprecation_test.php diff --git a/classes/setup_form.class.php b/classes/setup_form.class.php index c9dc472..f3cc702 100644 --- a/classes/setup_form.class.php +++ b/classes/setup_form.class.php @@ -165,7 +165,8 @@ public function save($data) { $turnitinviewermatchsubinfo = (!empty($data->permissionoptions['turnitinviewermatchsubinfo'])) ? 1 : 0; $turnitinviewersavechanges = (!empty($data->permissionoptions['turnitinviewersavechanges'])) ? 1 : 0; - set_config('turnitinsim_use', $useplugin, 'plagiarism'); + plagiarism_plugin_turnitinsim::enable_plugin($useplugin); + // Loop through all modules that support Plagiarism. $mods = core_component::get_plugin_list('mod'); foreach ($mods as $mod => $modpath) { diff --git a/db/install.php b/db/install.php index c2ce0de..3d084dc 100644 --- a/db/install.php +++ b/db/install.php @@ -37,7 +37,7 @@ function xmldb_plagiarism_turnitinsim_install() { upgrade_from_turnitincheck_plugin("plagiarism_turnitincheck_sub", "plagiarism_turnitinsim_sub"); upgrade_from_turnitincheck_plugin("plagiarism_turnitincheck_usr", "plagiarism_turnitinsim_users"); - set_config('turnitinsim_use', get_config('plagiarism', 'turnitincheck_use'), 'plagiarism'); + plagiarism_plugin_turnitinsim::enable_plugin(get_config('plagiarism', 'turnitincheck_use')); } } diff --git a/db/uninstall.php b/db/uninstall.php index 4f0f5ab..57c7b1a 100644 --- a/db/uninstall.php +++ b/db/uninstall.php @@ -29,8 +29,7 @@ * Configuration to remove on install. */ function xmldb_plagiarism_turnitinsim_uninstall() { - - set_config('turnitinsim_use', null, 'plagiarism'); + plagiarism_plugin_turnitinsim::enable_plugin(null); // Loop through all modules that support Plagiarism. $mods = core_component::get_plugin_list('mod'); diff --git a/db/upgrade.php b/db/upgrade.php index 48866de..131a49c 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -273,5 +273,18 @@ function xmldb_plagiarism_turnitinsim_upgrade($oldversion) { } upgrade_plugin_savepoint(true, 2020041501, 'plagiarism', 'turnitinsim'); } + + if ($oldversion < 2020061104) { + // This line needs to be included in all future upgrade blocks until we drop 3.8 support. + // This is because a user may upgrade Moodle after upgrading to this version. + (new handle_deprecation)->unset_turnitinsim_use(); + + // Convert turnitinsim_use as it is being deprecated. + $turnitinsimuse = get_config('plagiarism', 'turnitinsim_use'); + set_config('enabled', empty($turnitinsimuse) ? 0 : 1, 'plagiarism_turnitin'); + + upgrade_plugin_savepoint(true, 2020061104, 'plagiarism', 'turnitinsim'); + } + return true; } \ No newline at end of file diff --git a/lib.php b/lib.php index 9a6599e..b38da82 100644 --- a/lib.php +++ b/lib.php @@ -711,6 +711,26 @@ public function module_updated($eventdata) { } } + /** + * Wrapper method for Moodle's set_config method for enabling the plugin. + * This is so that when the deprecation is deleted we only need to change one place. + * + * @param int $enabled + */ + public static function enable_plugin($enabled) { + handle_deprecation::set_plugin_enabled($enabled); + } + + /** + * Wrapper method for Moodle's get_config method for checking if the plugin is enabled. + * This is so that when the deprecation is deleted we only need to change one place. + * + * @param int $enabled + * @return mixed + */ + public static function plugin_enabled() { + return handle_deprecation::get_plugin_enabled(); + } } /** diff --git a/tests/classes/assign_test.php b/tests/classes/assign_test.php index 56f0ec7..1cb55c0 100644 --- a/tests/classes/assign_test.php +++ b/tests/classes/assign_test.php @@ -100,7 +100,7 @@ public function test_get_onlinetext() { $assign = new assign($context, $cm, $record->course); // Set plugin config. - set_config('turnitinsim_use', 1, 'plagiarism'); + plagiarism_plugin_turnitinsim::enable_plugin(1); set_config('turnitinmodenabledassign', 1, 'plagiarism_turnitinsim'); // Enable plugin for module. @@ -157,7 +157,7 @@ public function test_get_itemid_returns_correct_itemid() { $assign = new assign($context, $cm, $record->course); // Set plugin config. - set_config('turnitinsim_use', 1, 'plagiarism'); + plagiarism_plugin_turnitinsim::enable_plugin(1); set_config('turnitinmodenabledassign', 1, 'plagiarism_turnitinsim'); // Enable plugin for module. @@ -423,7 +423,7 @@ public function test_create_submission_event_data_returns_correct_data_for_file_ $assign = new assign($context, $cm, $record->course); // Set plugin config. - set_config('turnitinsim_use', 1, 'plagiarism'); + plagiarism_plugin_turnitinsim::enable_plugin(1); set_config('turnitinmodenabledassign', 1, 'plagiarism_turnitinsim'); // Enable plugin for module. @@ -486,7 +486,7 @@ public function test_create_submission_event_data_returns_correct_data_for_text_ $assign = new assign($context, $cm, $record->course); // Set plugin config. - set_config('turnitinsim_use', 1, 'plagiarism'); + plagiarism_plugin_turnitinsim::enable_plugin(1); set_config('turnitinmodenabledassign', 1, 'plagiarism_turnitinsim'); // Enable plugin for module. diff --git a/tests/classes/tssetupform_test.php b/tests/classes/tssetupform_test.php index 1da8dfe..999baa4 100644 --- a/tests/classes/tssetupform_test.php +++ b/tests/classes/tssetupform_test.php @@ -77,7 +77,8 @@ public function test_save_plugin_setup() { $form->save($data); // Check settings have been saved. - $turnitinsimuse = get_config('plagiarism', 'turnitinsim_use'); + $turnitinsimuse = plagiarism_plugin_turnitinsim::plugin_enabled(); + $settings = get_config('plagiarism_turnitinsim'); $this->assertEquals(self::TURNITINSIM_ENABLED, $turnitinsimuse); @@ -105,7 +106,7 @@ public function test_save_plugin_setup_empty() { $form->save($data); // Check settings have been saved. - $turnitinsimuse = get_config('plagiarism', 'turnitinsim_use'); + $turnitinsimuse = plagiarism_plugin_turnitinsim::plugin_enabled(); $settings = get_config('plagiarism_turnitinsim'); $this->assertEquals(self::TURNITINSIM_DISABLED, $turnitinsimuse); diff --git a/tests/classes/tssubmission_test.php b/tests/classes/tssubmission_test.php index 6362e51..ac1e006 100644 --- a/tests/classes/tssubmission_test.php +++ b/tests/classes/tssubmission_test.php @@ -1112,7 +1112,7 @@ public function test_get_submission_details_file() { $assign = new assign($context, $cm, $record->course); // Set plugin config. - set_config('turnitinsim_use', 1, 'plagiarism'); + plagiarism_plugin_turnitinsim::enable_plugin(1); set_config('turnitinmodenabledassign', 1, 'plagiarism_turnitinsim'); // Enable plugin for module. @@ -1176,7 +1176,7 @@ public function test_get_submission_details_text() { $assign = new assign($context, $cm, $record->course); // Set plugin config. - set_config('turnitinsim_use', 1, 'plagiarism'); + plagiarism_plugin_turnitinsim::enable_plugin(1); set_config('turnitinmodenabledassign', 1, 'plagiarism_turnitinsim'); // Enable plugin for module. @@ -1234,7 +1234,7 @@ public function test_set_generationtime_immediate() { $assign = new assign($context, $cm, $record->course); // Set plugin config. - set_config('turnitinsim_use', 1, 'plagiarism'); + plagiarism_plugin_turnitinsim::enable_plugin(1); set_config('turnitinmodenabledassign', 1, 'plagiarism_turnitinsim'); // Enable plugin for module. @@ -1302,7 +1302,7 @@ public function test_set_generationtime_immediate_duedate() { $assign = new assign($context, $cm, $record->course); // Set plugin config. - set_config('turnitinsim_use', 1, 'plagiarism'); + plagiarism_plugin_turnitinsim::enable_plugin(1); set_config('turnitinmodenabledassign', 1, 'plagiarism_turnitinsim'); // Enable plugin for module. @@ -1381,7 +1381,7 @@ public function test_set_generationtime_duedate() { $assign = new assign($context, $cm, $record->course); // Set plugin config. - set_config('turnitinsim_use', 1, 'plagiarism'); + plagiarism_plugin_turnitinsim::enable_plugin(1); set_config('turnitinmodenabledassign', 1, 'plagiarism_turnitinsim'); // Enable plugin for module. @@ -1460,7 +1460,7 @@ public function test_set_generationtime_no_course_module() { $assign = new assign($context, $cm, $record->course); // Set plugin config. - set_config('turnitinsim_use', 1, 'plagiarism'); + plagiarism_plugin_turnitinsim::enable_plugin(1); set_config('turnitinmodenabledassign', 1, 'plagiarism_turnitinsim'); // Enable plugin for module. diff --git a/tests/lib_test.php b/tests/lib_test.php index d26f99e..55edc31 100644 --- a/tests/lib_test.php +++ b/tests/lib_test.php @@ -150,7 +150,7 @@ public function test_save_form_elements() { $this->assertEmpty($settings); // Set plugin as enabled in config for this module type. - set_config('turnitinsim_use', 1, 'plagiarism'); + plagiarism_plugin_turnitinsim::enable_plugin(1); set_config('turnitinmodenabledassign', 1, 'plagiarism_turnitinsim'); $plugin->save_form_elements($data); @@ -170,7 +170,7 @@ public function test_get_links_no_submission() { $this->resetAfterTest(); // Set plugin as enabled in config for this module type. - set_config('turnitinsim_use', 1, 'plagiarism'); + plagiarism_plugin_turnitinsim::enable_plugin(1); set_config('turnitinmodenabledassign', 1, 'plagiarism_turnitinsim'); // Enable plugin for module. @@ -199,7 +199,7 @@ public function test_get_links_student_view_reports() { $this->resetAfterTest(); // Set plugin as enabled in config for this module type. - set_config('turnitinsim_use', 1, 'plagiarism'); + plagiarism_plugin_turnitinsim::enable_plugin(1); set_config('turnitinmodenabledassign', 1, 'plagiarism_turnitinsim'); // Enable plugin for module. @@ -232,7 +232,7 @@ public function test_get_links_with_submission() { $assign = new assign($context, $this->cm, $this->course); // Set plugin config. - set_config('turnitinsim_use', 1, 'plagiarism'); + plagiarism_plugin_turnitinsim::enable_plugin(1); set_config('turnitinmodenabledassign', 1, 'plagiarism_turnitinsim'); // Enable plugin for module. @@ -383,7 +383,7 @@ public function test_is_plugin_active_not_enabled_for_mod_type() { $this->resetAfterTest(); // Set plugin as not enabled in config for this module type. - set_config('turnitinsim_use', 1, 'plagiarism'); + plagiarism_plugin_turnitinsim::enable_plugin(1); set_config('turnitinmodenabledassign', 0, 'plagiarism_turnitinsim'); $plagiarismturnitinsim = new plagiarism_plugin_turnitinsim(); @@ -397,7 +397,7 @@ public function test_is_plugin_active_not_enabled_for_mod() { $this->resetAfterTest(); // Set plugin as enabled in config for this module type. - set_config('turnitinsim_use', 1, 'plagiarism'); + plagiarism_plugin_turnitinsim::enable_plugin(1); set_config('turnitinmodenabledassign', 1, 'plagiarism_turnitinsim'); // Disable plugin for module. @@ -467,7 +467,7 @@ public function test_print_disclosure_display_latest() { $this->resetAfterTest(); // Set plugin as enabled in config for this module type. - set_config('turnitinsim_use', 1, 'plagiarism'); + plagiarism_plugin_turnitinsim::enable_plugin(1); set_config('turnitinmodenabledassign', 1, 'plagiarism_turnitinsim'); // Enable plugin for module. @@ -503,7 +503,7 @@ public function test_print_disclosure_not_display_latest() { $this->resetAfterTest(); // Set plugin as enabled in config for this module type. - set_config('turnitinsim_use', 1, 'plagiarism'); + plagiarism_plugin_turnitinsim::enable_plugin(1); set_config('turnitinmodenabledassign', 1, 'plagiarism_turnitinsim'); // Enable plugin for module. @@ -534,7 +534,7 @@ public function test_print_disclosure_eula_not_displayed_if_not_required() { $this->resetAfterTest(); // Set plugin as enabled in config for this module type. - set_config('turnitinsim_use', 1, 'plagiarism'); + plagiarism_plugin_turnitinsim::enable_plugin(1); set_config('turnitinmodenabledassign', 1, 'plagiarism_turnitinsim'); // Set the features enabled. @@ -626,7 +626,7 @@ public function test_submit_handler_plugin_not_enabled() { ); // Set plugin config. - set_config('turnitinsim_use', 0, 'plagiarism'); + plagiarism_plugin_turnitinsim::enable_plugin(0); set_config('turnitinmodenabledassign', 0, 'plagiarism_turnitinsim'); // Handler should always return true despite plugin not being enabled. @@ -647,7 +647,7 @@ public function test_submit_handler_empty_file_saved() { $this->resetAfterTest(); // Set plugin config. - set_config('turnitinsim_use', 1, 'plagiarism'); + plagiarism_plugin_turnitinsim::enable_plugin(1); set_config('turnitinmodenabledassign', 1, 'plagiarism_turnitinsim'); // Enable plugin for module. @@ -694,7 +694,7 @@ public function test_submit_handler_file_queued_after_accepting_eula() { $this->resetAfterTest(); // Set plugin config. - set_config('turnitinsim_use', 1, 'plagiarism'); + plagiarism_plugin_turnitinsim::enable_plugin(1); set_config('turnitinmodenabledassign', 1, 'plagiarism_turnitinsim'); // Enable plugin for module. @@ -762,7 +762,7 @@ public function test_submit_handler_file_queued_without_requiring_eula() { $this->resetAfterTest(); // Set plugin config. - set_config('turnitinsim_use', 1, 'plagiarism'); + plagiarism_plugin_turnitinsim::enable_plugin(1); set_config('turnitinmodenabledassign', 1, 'plagiarism_turnitinsim'); // Set the features enabled. @@ -826,7 +826,7 @@ public function test_submit_handler_file_queued_and_saves_group_id() { $this->resetAfterTest(); // Set plugin config. - set_config('turnitinsim_use', 1, 'plagiarism'); + plagiarism_plugin_turnitinsim::enable_plugin(1); set_config('turnitinmodenabledassign', 1, 'plagiarism_turnitinsim'); // Create group. @@ -909,7 +909,7 @@ public function test_submit_handler_file_queues_same_file() { $this->resetAfterTest(); // Set plugin config. - set_config('turnitinsim_use', 1, 'plagiarism'); + plagiarism_plugin_turnitinsim::enable_plugin(1); set_config('turnitinmodenabledassign', 1, 'plagiarism_turnitinsim'); // Enable plugin for module. @@ -982,7 +982,7 @@ public function test_submit_handler_file_requeueing_previously_submitted_files() $this->resetAfterTest(); // Set plugin config. - set_config('turnitinsim_use', 1, 'plagiarism'); + plagiarism_plugin_turnitinsim::enable_plugin(1); set_config('turnitinmodenabledassign', 1, 'plagiarism_turnitinsim'); // Enable plugin for module. @@ -1075,7 +1075,7 @@ public function test_submit_handler_text_content_queued() { $this->resetAfterTest(); // Set plugin config. - set_config('turnitinsim_use', 1, 'plagiarism'); + plagiarism_plugin_turnitinsim::enable_plugin(1); set_config('turnitinmodenabledassign', 1, 'plagiarism_turnitinsim'); // Enable plugin for module. @@ -1135,7 +1135,7 @@ public function test_submit_handler_queues_draft() { $this->assign = $this->getDataGenerator()->create_module('assign', $record); // Set plugin config. - set_config('turnitinsim_use', 1, 'plagiarism'); + plagiarism_plugin_turnitinsim::enable_plugin(1); set_config('turnitinmodenabledassign', 1, 'plagiarism_turnitinsim'); // Enable plugin for module. @@ -1211,7 +1211,7 @@ public function test_submit_handler_does_not_queue_draft_but_queues_final_submis $this->assign = $this->getDataGenerator()->create_module('assign', $record); // Set plugin config. - set_config('turnitinsim_use', 1, 'plagiarism'); + plagiarism_plugin_turnitinsim::enable_plugin(1); set_config('turnitinmodenabledassign', 1, 'plagiarism_turnitinsim'); // Enable plugin for module. @@ -1340,4 +1340,30 @@ public function test_module_updated() { $this->assertEquals($duedate, $tssubmission->getgenerationtime()); $this->assertEquals(1, $tssubmission->gettogenerate()); } + + /** + * Test the enable_plugin and plugin_enabled methods. + */ + public function test_enable_plugin() { + $this->resetAfterTest(); + + set_config('branch', 38); + + plagiarism_plugin_turnitinsim::enable_plugin(1); + $this->assertEquals(1, plagiarism_plugin_turnitinsim::plugin_enabled()); + + plagiarism_plugin_turnitinsim::enable_plugin(0); + $this->assertEquals(0, plagiarism_plugin_turnitinsim::plugin_enabled()); + + set_config('branch', 39); + + plagiarism_plugin_turnitinsim::enable_plugin(1); + $this->assertEquals(1, plagiarism_plugin_turnitinsim::plugin_enabled()); + + plagiarism_plugin_turnitinsim::enable_plugin(0); + $this->assertEquals(0, plagiarism_plugin_turnitinsim::plugin_enabled()); + + plagiarism_plugin_turnitinsim::enable_plugin(null); + $this->assertEquals(null, plagiarism_plugin_turnitinsim::plugin_enabled()); + } } diff --git a/tests/utilities/handle_deprecation_test.php b/tests/utilities/handle_deprecation_test.php new file mode 100644 index 0000000..3b6d1f2 --- /dev/null +++ b/tests/utilities/handle_deprecation_test.php @@ -0,0 +1,92 @@ +. + +/** + * Unit tests for (some of) plagiarism/turnitinsim/utilities/handle_deprecations.php. + * + * @package plagiarism_turnitinsim + * @copyright 2020 Turnitin + * @author David Winn + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +global $CFG; +require_once($CFG->dirroot . '/plagiarism/turnitinsim/utilities/handle_deprecation.php'); + +/** + * Tests for handle_deprecations methods. + */ +class plagiarism_turnitinsim_handle_deprecation_testcase extends advanced_testcase { + + /** + * Test the enable_plugin and plugin_enabled methods. + */ + public function test_plugin_enabled() { + $this->resetAfterTest(); + + set_config('branch', 38); + + handle_deprecation::set_plugin_enabled(1); + $this->assertEquals(1, handle_deprecation::get_plugin_enabled()); + + handle_deprecation::set_plugin_enabled(0); + $this->assertEquals(0, handle_deprecation::get_plugin_enabled()); + + set_config('branch', 39); + + handle_deprecation::set_plugin_enabled(1); + $this->assertEquals(1, handle_deprecation::get_plugin_enabled()); + + handle_deprecation::set_plugin_enabled(0); + $this->assertEquals(0, handle_deprecation::get_plugin_enabled()); + + handle_deprecation::set_plugin_enabled(null); + $this->assertEquals(null, handle_deprecation::get_plugin_enabled()); + } + + /** + * Test that unset_turnitinsim_use handled >= Moodle 3.9 correctly. + */ + public function test_unset_turnitinsim_use_unsets_value_in_39() { + $this->resetAfterTest(); + + set_config( 'turnitinsim_use', 1, 'plagiarism'); + + (new handle_deprecation)->unset_turnitinsim_use(); + + $value = get_config('plagiarism', 'turnitinsim_use'); + + $this->assertEmpty($value); + } + + /** + * Test that unset_turnitinsim_use handled < Moodle 3.9 correctly. + */ + public function test_unset_turnitinsim_use_leaves_value_in_38() { + $this->resetAfterTest(); + + set_config('branch', 38); + set_config( 'turnitinsim_use', 1, 'plagiarism'); + + (new handle_deprecation)->unset_turnitinsim_use(); + + $value = get_config('plagiarism', 'turnitinsim_use'); + + $this->assertEquals($value, 1); + } +} diff --git a/utilities/handle_deprecation.php b/utilities/handle_deprecation.php index 5bc4028..1ea1d9e 100644 --- a/utilities/handle_deprecation.php +++ b/utilities/handle_deprecation.php @@ -49,6 +49,55 @@ public function __construct() { * @return string representing a UUID. */ public function create_uuid() { - return ($this->branch < 38) ? generate_uuid() : \core\uuid::generate(); + return $this->branch < 38 ? generate_uuid() : \core\uuid::generate(); + } + + /** + * In Moodle 3.9, the config values for enabling and disabling the plugin were changed. + * turnitinsim_use is now deprecated and replaced with "enabled" for this plugin. + * + * This method handles our support for multiple Moodle versions for unsetting the config value. + * As this can't be unset until after a user has upgraded Moodle, we must run it on future upgrades. + * Until we no longer support 3.8. + * + */ + public function unset_turnitinsim_use() { + global $CFG; + + $turnitinsimuse = get_config('plagiarism', 'turnitinsim_use'); + + if ($CFG->branch >= 39 && !empty($turnitinsimuse)) { + unset_config('turnitinsim_use', 'plagiarism'); + } + } + + /** + * In Moodle 3.9, the config values for enabling and disabling the plugin were changed. + * turnitinsim_use is now deprecated and replaced with "enabled" for this plugin. + * + * This method handles our support for multiple Moodle versions for setting the config value. + * + * @param $enabled 1 if enabled, 0 if not. + */ + public static function set_plugin_enabled($enabled) { + global $CFG; + + $CFG->branch < 39 ? set_config('turnitinsim_use', $enabled, 'plagiarism') + : set_config('enabled', $enabled, 'plagiarism_turnitinsim'); + } + + /** + * In Moodle 3.9, the config values for enabling and disabling the plugin were changed. + * turnitinsim_use is now deprecated and replaced with "enabled" for this plugin. + * + * This method handles our support for multiple Moodle versions for getting the config value. + * + * @param $enabled 1 if enabled, 0 if not. + */ + public static function get_plugin_enabled() { + global $CFG; + + return $CFG->branch < 39 ? get_config('plagiarism', 'turnitinsim_use') + : get_config('plagiarism_turnitinsim', 'enabled'); } } \ No newline at end of file diff --git a/version.php b/version.php index 14a1e6d..7b9a3ef 100644 --- a/version.php +++ b/version.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2020042201; +$plugin->version = 2020061104; $plugin->release = "v1.1"; $plugin->requires = 2017051500; $plugin->component = 'plagiarism_turnitinsim'; From 446771c2a64b7d5c53c63843ef53780cfa9a39f3 Mon Sep 17 00:00:00 2001 From: David Winn Date: Fri, 12 Jun 2020 12:07:55 +0100 Subject: [PATCH 22/48] Fixing issue with upgrade script --- db/upgrade.php | 18 +++++++++++------- version.php | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/db/upgrade.php b/db/upgrade.php index 131a49c..d42a85a 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -274,17 +274,21 @@ function xmldb_plagiarism_turnitinsim_upgrade($oldversion) { upgrade_plugin_savepoint(true, 2020041501, 'plagiarism', 'turnitinsim'); } - if ($oldversion < 2020061104) { + if ($oldversion < 2020061201) { + // Convert turnitinsim_use as it is being deprecated. + $turnitinsimuse = get_config('plagiarism', 'turnitinsim_use'); + set_config('enabled', empty($turnitinsimuse) ? 0 : 1, 'plagiarism_turnitinsim'); + + upgrade_plugin_savepoint(true, 2020061201, 'plagiarism', 'turnitinsim'); + } + + if ($oldversion < 2020061202) { // This line needs to be included in all future upgrade blocks until we drop 3.8 support. // This is because a user may upgrade Moodle after upgrading to this version. (new handle_deprecation)->unset_turnitinsim_use(); - // Convert turnitinsim_use as it is being deprecated. - $turnitinsimuse = get_config('plagiarism', 'turnitinsim_use'); - set_config('enabled', empty($turnitinsimuse) ? 0 : 1, 'plagiarism_turnitin'); - - upgrade_plugin_savepoint(true, 2020061104, 'plagiarism', 'turnitinsim'); + upgrade_plugin_savepoint(true, 2020061202, 'plagiarism', 'turnitinsim'); } - return true; + return true; } \ No newline at end of file diff --git a/version.php b/version.php index 7b9a3ef..2edf066 100644 --- a/version.php +++ b/version.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2020061104; +$plugin->version = 2020061202; $plugin->release = "v1.1"; $plugin->requires = 2017051500; $plugin->component = 'plagiarism_turnitinsim'; From 8ab69bd9d05e81372dd46c44cb94a284354d75ac Mon Sep 17 00:00:00 2001 From: David Winn Date: Mon, 15 Jun 2020 13:57:12 +0100 Subject: [PATCH 23/48] doc checker fixes --- lib.php | 3 +-- utilities/handle_deprecation.php | 5 +---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/lib.php b/lib.php index b38da82..0f53455 100644 --- a/lib.php +++ b/lib.php @@ -715,7 +715,7 @@ public function module_updated($eventdata) { * Wrapper method for Moodle's set_config method for enabling the plugin. * This is so that when the deprecation is deleted we only need to change one place. * - * @param int $enabled + * @param$enabled int 1 if plugin is to be enabled. */ public static function enable_plugin($enabled) { handle_deprecation::set_plugin_enabled($enabled); @@ -725,7 +725,6 @@ public static function enable_plugin($enabled) { * Wrapper method for Moodle's get_config method for checking if the plugin is enabled. * This is so that when the deprecation is deleted we only need to change one place. * - * @param int $enabled * @return mixed */ public static function plugin_enabled() { diff --git a/utilities/handle_deprecation.php b/utilities/handle_deprecation.php index 1ea1d9e..e826183 100644 --- a/utilities/handle_deprecation.php +++ b/utilities/handle_deprecation.php @@ -59,7 +59,6 @@ public function create_uuid() { * This method handles our support for multiple Moodle versions for unsetting the config value. * As this can't be unset until after a user has upgraded Moodle, we must run it on future upgrades. * Until we no longer support 3.8. - * */ public function unset_turnitinsim_use() { global $CFG; @@ -77,7 +76,7 @@ public function unset_turnitinsim_use() { * * This method handles our support for multiple Moodle versions for setting the config value. * - * @param $enabled 1 if enabled, 0 if not. + * @param $enabled int 1 if enabled, 0 if not. */ public static function set_plugin_enabled($enabled) { global $CFG; @@ -91,8 +90,6 @@ public static function set_plugin_enabled($enabled) { * turnitinsim_use is now deprecated and replaced with "enabled" for this plugin. * * This method handles our support for multiple Moodle versions for getting the config value. - * - * @param $enabled 1 if enabled, 0 if not. */ public static function get_plugin_enabled() { global $CFG; From b5217bbf684be31192ed4d2790859b1631b301f6 Mon Sep 17 00:00:00 2001 From: Grijesh Saini Date: Tue, 16 Jun 2020 13:48:28 +0530 Subject: [PATCH 24/48] INT-14441 - Added remote logging call to Plugin. --- callbacks.php | 6 + classes/callback.class.php | 6 + classes/logging_request.class.php | 147 +++++++++++++++++++ classes/logging_request_event_info.class.php | 90 ++++++++++++ classes/logging_request_info.class.php | 124 ++++++++++++++++ classes/request.class.php | 19 ++- classes/submission.class.php | 13 ++ utilities/constants.php | 1 + 8 files changed, 401 insertions(+), 5 deletions(-) create mode 100644 classes/logging_request.class.php create mode 100644 classes/logging_request_event_info.class.php create mode 100644 classes/logging_request_info.class.php diff --git a/callbacks.php b/callbacks.php index 6da8b9a..2b78c51 100644 --- a/callbacks.php +++ b/callbacks.php @@ -28,6 +28,8 @@ require_once(__DIR__."/lib.php"); require_once(__DIR__."/locallib.php"); require_once(__DIR__."/classes/callback.class.php"); +require_once(__DIR__."/classes/logging_request.class.php"); +require_once(__DIR__."/classes/logging_request_event_info.class.php"); $PAGE->set_context(context_system::instance()); @@ -58,6 +60,10 @@ if ($expectedsecret !== $reqheaders['x-turnitin-signature']) { if ($pluginconfig->turnitinenablelogging) { $logger->error(get_string('webhookincorrectsignature', 'plagiarism_turnitinsim')); + + $eventinfo = new logging_request_event_info("callback.php", $reqheaders, $requeststring); + $loggingrequest = new logging_request(get_string('webhookincorrectsignature', 'plagiarism_turnitinsim')); + $loggingrequest->send_error_to_turnitin(null, $eventinfo, true); } echo get_string('webhookincorrectsignature', 'plagiarism_turnitinsim'); diff --git a/classes/callback.class.php b/classes/callback.class.php index 0ebfa34..f45d1f2 100644 --- a/classes/callback.class.php +++ b/classes/callback.class.php @@ -27,6 +27,9 @@ defined('MOODLE_INTERNAL') || die(); +require_once($CFG->dirroot . '/plagiarism/turnitinsim/classes/logging_request.class.php'); +require_once($CFG->dirroot . '/plagiarism/turnitinsim/classes/logging_request_info.class.php'); + /** * Class for handling callbacks from Turnitin. */ @@ -150,6 +153,9 @@ public function create_webhook() { mtrace(get_string('taskoutputwebhookcreated', 'plagiarism_turnitinsim', TURNITINSIM_CALLBACK_URL)); } else { mtrace(get_string('taskoutputwebhooknotcreated', 'plagiarism_turnitinsim', TURNITINSIM_CALLBACK_URL)); + $loggingrequestinfo = new logging_request_info(TURNITINSIM_ENDPOINT_WEBHOOKS, "POST", null, $responsedata->httpstatus, $response); + $loggingrequest = new logging_request(get_string('taskoutputwebhooknotcreated', 'plagiarism_turnitinsim', TURNITINSIM_CALLBACK_URL)); + $loggingrequest->send_error_to_turnitin($loggingrequestinfo); } } catch (Exception $e) { diff --git a/classes/logging_request.class.php b/classes/logging_request.class.php new file mode 100644 index 0000000..e03201e --- /dev/null +++ b/classes/logging_request.class.php @@ -0,0 +1,147 @@ +. + +/** + * Submission class for plagiarism_turnitinsim component. + * + * @package plagiarism_turnitinsim + * @copyright 2017 Turnitin + * @author John McGettrick + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +global $CFG; +require_once($CFG->dirroot . '/plagiarism/turnitinsim/lib.php'); + + +/** + * Class for sending error logs to Turnitin. + */ +class logging_request { + + /** + * @var object The request object. + */ + public $tsrequest; + + /** + * @var array The log object. + */ + public $loggingrequest; + + /** + * @var string The submission id. + */ + private $submissionid; + + /** + * Constructor. + * + * @param $message string The error message. + */ + public function __construct($message = 'Error') { + $this->tsrequest = new plagiarism_turnitinsim_request(); + $this->loggingrequest = array(); + $this->loggingrequest["message"] = $message; + } + + /** + * @param logging_request_info|null $logging_request_info The logging_request_info object. + * @param logging_request_event_info|null $logging_request_event_info The logging_request_event_info object. + * @param bool $send_secrets The boolean value, if true send secrets as part of logs. + */ + public function send_error_to_turnitin(logging_request_info $logging_request_info = null, logging_request_event_info $logging_request_event_info = null, $send_secrets = false) { + $this->set_basic_details(); + + if ($send_secrets) { + $this->set_secrets(); + } + + if ($logging_request_info) { + $this->set_request_info($logging_request_info); + } + + if ($logging_request_event_info) { + $this->set_event_info($logging_request_event_info); + } + + try { + $endpoint = TURNITINSIM_ENDPOINT_LOGGING; + $this->tsrequest->send_request($endpoint, json_encode($this->loggingrequest), 'POST', 'general', true, true); + } catch (Exception $e) { + // Handle silently. + } + } + + /** + * Populate basic and mandatory details. + */ + private function set_basic_details() { + global $CFG; + + $this->loggingrequest["integration_type"] = "Moodle"; + $this->loggingrequest["integration_version"] = get_config('plagiarism_turnitinsim', 'version'); + $this->loggingrequest["lms_version"] = $CFG->version; + $this->loggingrequest["log_level"] = "ERROR"; + $this->loggingrequest["date"] = date("Y-m-d H:i:s"); + $this->loggingrequest["tenant"] = $this->tsrequest->get_apiurl(); + $this->loggingrequest["submission_id"] = $this->submissionid; + } + + /** + * Set secrets. + */ + private function set_secrets() { + $this->loggingrequest["api_key"] = $this->tsrequest->get_apikey(); + $this->loggingrequest["webhook_secret"] = get_config('plagiarism_turnitinsim', 'turnitin_webhook_secret'); + } + + /** + * Set request info details. + * + * @param logging_request_info $logging_request_info The logging_request_info object. + */ + private function set_request_info(logging_request_info $logging_request_info) { + $this->loggingrequest["request"]["url"] = $logging_request_info->get_url(); + $this->loggingrequest["request"]["method"] = $logging_request_info->get_method(); + $this->loggingrequest["request"]["headers"] = $logging_request_info->get_headers(); + $this->loggingrequest["request"]["response_status"] = $logging_request_info->get_response_status(); + $this->loggingrequest["request"]["response_body"] = $logging_request_info->get_response_body(); + } + + /** + * Set event info details. + * + * @param logging_request_event_info $logging_request_event_info The $logging_request_event_info object. + */ + private function set_event_info(logging_request_event_info $logging_request_event_info) { + $this->loggingrequest["event"]["url"] = $logging_request_event_info->get_url(); + $this->loggingrequest["event"]["headers"] = $logging_request_event_info->get_headers(); + $this->loggingrequest["event"]["body"] = $logging_request_event_info->get_body(); + } + + /** + * Set submission id. + * + * @param string $submissionid + */ + public function set_submissionid($submissionid){ + $this->submissionid = $submissionid; + } + +} diff --git a/classes/logging_request_event_info.class.php b/classes/logging_request_event_info.class.php new file mode 100644 index 0000000..f2f0f5f --- /dev/null +++ b/classes/logging_request_event_info.class.php @@ -0,0 +1,90 @@ +. + +/** + * Submission class for plagiarism_turnitinsim component. + * + * @package plagiarism_turnitinsim + * @copyright 2017 Turnitin + * @author John McGettrick + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +global $CFG; +require_once($CFG->dirroot . '/plagiarism/turnitinsim/lib.php'); + + +/** + * Class models event info sent to be logged. + */ +class logging_request_event_info { + + /** + * @var string The url. + */ + private $url; + + /** + * @var array Request headers. + */ + private $headers; + + /** + * @var string The response body. + */ + private $body; + + /** + * logging_request_info constructor. + * @param $url string The url. + * @param $headers array The request headers. + * @param $body string The response body. + */ + public function __construct($url, $headers = null, $body = null) { + $this->url = $url; + $this->headers = $headers; + $this->body = $body; + } + + /** + * Get the url. + * + * @return string + */ + public function get_url() { + return $this->url; + } + + /** + * Get the request headers. + * + * @return array + */ + public function get_headers() { + return $this->headers; + } + + /** + * Get response body. + * + * @return string + */ + public function get_body() { + return $this->body; + } +} diff --git a/classes/logging_request_info.class.php b/classes/logging_request_info.class.php new file mode 100644 index 0000000..3b194e4 --- /dev/null +++ b/classes/logging_request_info.class.php @@ -0,0 +1,124 @@ +. + +/** + * Submission class for plagiarism_turnitinsim component. + * + * @package plagiarism_turnitinsim + * @copyright 2017 Turnitin + * @author John McGettrick + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +global $CFG; +require_once($CFG->dirroot . '/plagiarism/turnitinsim/lib.php'); + + +/** + * Class models request info sent to be logged. + */ +class logging_request_info { + + /** + * @var string The url. + */ + private $url; + + /** + * @var string The Http Method. + */ + private $method; + + /** + * @var array Request headers. + */ + private $headers; + + /** + * @var int Response http status. + */ + private $response_status; + + /** + * @var string The response body. + */ + private $response_body; + + /** + * logging_request_info constructor. + * @param $url + * @param $method + * @param $headers + * @param $response_status + * @param $response_body + */ + public function __construct($url, $method = null, $headers = null, $response_status = null, $response_body = null) { + $this->url = $url; + $this->method = $method; + $this->headers = $headers; + $this->response_status = $response_status; + $this->response_body = $response_body; + } + + + /** + * Get the url. + * + * @return string + */ + public function get_url() { + return $this->url; + } + + /** + * Get the Http Method. + * + * @return string + */ + public function get_method() { + return $this->method; + } + + /** + * Get the request headers. + * + * @return array + */ + public function get_headers() { + return $this->headers; + } + + /** + * Get response status. + * + * @return int + */ + public function get_response_status() { + return $this->response_status; + } + + /** + * Get response body. + * + * @return string + */ + public function get_response_body() { + return $this->response_body; + } + +} \ No newline at end of file diff --git a/classes/request.class.php b/classes/request.class.php index 8dc82ce..76e784a 100644 --- a/classes/request.class.php +++ b/classes/request.class.php @@ -108,9 +108,10 @@ public function add_additional_headers($additionalheaders = array()) { * @param string $requestbody The request body to send. * @param string $method The request method eg GET/POST. * @param string $requesttype The type of request, can be general or submission. + * @param bool $isasync The * @return array|bool|false|mixed|stdClass|string */ - public function send_request($endpoint, $requestbody, $method, $requesttype = 'general') { + public function send_request($endpoint, $requestbody, $method, $requesttype = 'general', $isasync = false, $isloggingrequest = false) { global $CFG; // Attach content type to headers if this is not a submission. @@ -120,8 +121,10 @@ public function send_request($endpoint, $requestbody, $method, $requesttype = 'g } } + $tiiurl = ($isloggingrequest) ? str_replace('/api', '', $this->get_apiurl()) : $this->get_apiurl(); + if ($this->logger) { - $this->logger->info('[' . $method . '] Request to: ' . $this->get_apiurl() . $endpoint); + $this->logger->info('[' . $method . '] Request to: ' . $tiiurl . $endpoint); $this->logger->info('Headers: ', $this->headers); // Don't log the contents of a file submission as it is the raw file contents. @@ -131,12 +134,18 @@ public function send_request($endpoint, $requestbody, $method, $requesttype = 'g } $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $this->get_apiurl() . $endpoint); - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); - curl_setopt($ch, CURLOPT_TIMEOUT, 120); + curl_setopt($ch, CURLOPT_URL, $tiiurl . $endpoint); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + if ($isasync) { + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); + curl_setopt($ch, CURLOPT_TIMEOUT, 5); + } else { + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); + curl_setopt($ch, CURLOPT_TIMEOUT, 120); + } + if ($method == 'POST') { curl_setopt($ch, CURLOPT_POST, true); } diff --git a/classes/submission.class.php b/classes/submission.class.php index d9fd6f9..c814dd8 100644 --- a/classes/submission.class.php +++ b/classes/submission.class.php @@ -31,6 +31,8 @@ require_once($CFG->dirroot . '/plagiarism/turnitinsim/classes/assign.class.php'); require_once($CFG->dirroot . '/plagiarism/turnitinsim/classes/forum.class.php'); require_once($CFG->dirroot . '/plagiarism/turnitinsim/classes/workshop.class.php'); +require_once($CFG->dirroot . '/plagiarism/turnitinsim/classes/logging_request.class.php'); +require_once($CFG->dirroot . '/plagiarism/turnitinsim/classes/logging_request_info.class.php'); /** * Submission class for plagiarism_turnitinsim component. @@ -484,6 +486,9 @@ public function handle_create_submission_response($params) { $this->settiiattempts(TURNITINSIM_SUBMISSION_MAX_SEND_ATTEMPTS); $this->seterrormessage($params->message); mtrace(get_string('taskoutputsubmissionnotcreatedgeneral', 'plagiarism_turnitinsim')); + $loggingrequestinfo = new logging_request_info(TURNITINSIM_ENDPOINT_CREATE_SUBMISSION, "POST", null, $params->httpstatus, json_encode($params)); + $loggingrequest = new logging_request(get_string('taskoutputsubmissionnotcreatedgeneral', 'plagiarism_turnitinsim')); + $loggingrequest->send_error_to_turnitin($loggingrequestinfo); break; } @@ -592,6 +597,10 @@ public function handle_upload_response($params, $filename) { // Save error message if request has errored, otherwise send digital receipts. if ($status == TURNITINSIM_SUBMISSION_STATUS_ERROR) { $this->seterrormessage($params->message); + $loggingrequestinfo = new logging_request_info(TURNITINSIM_ENDPOINT_UPLOAD_SUBMISSION, "POST", null, $params->httpstatus, json_encode($params)); + $loggingrequest = new logging_request('Error while uploading the file'); + $loggingrequest->set_submissionid($this->turnitinid); + $loggingrequest->send_error_to_turnitin($loggingrequestinfo); } else { $this->send_digital_receipts($filename); } @@ -622,6 +631,10 @@ public function handle_submission_info_response($params) { } else { $error = isset($params->error_code) ? $params->error_code : get_string('submissiondisplaystatus:unknown', 'plagiarism_turnitinsim'); $this->set_error_with_max_retry_attempts($error, TURNITINSIM_REPORT_GEN_MAX_ATTEMPTS); + $loggingrequestinfo = new logging_request_info(TURNITINSIM_ENDPOINT_GET_SUBMISSION_INFO, "GET", null, 500, json_encode($params)); + $loggingrequest = new logging_request($error); + $loggingrequest->set_submissionid($this->turnitinid); + $loggingrequest->send_error_to_turnitin($loggingrequestinfo); } $this->update(); diff --git a/utilities/constants.php b/utilities/constants.php index d527f27..e734a3f 100644 --- a/utilities/constants.php +++ b/utilities/constants.php @@ -66,6 +66,7 @@ define('TURNITINSIM_ENDPOINT_GET_WEBHOOK', '/v1/webhooks/{{webhook_id}}'); define('TURNITINSIM_ENDPOINT_GET_LATEST_EULA', '/v1/eula/latest'); define('TURNITINSIM_ENDPOINT_GET_FEATURES_ENABLED', '/v1/features-enabled'); +define('TURNITINSIM_ENDPOINT_LOGGING', '/remote-logging/api/log'); // URLs. define('TURNITINSIM_HELP_LINK', 'https://help.turnitin.com/simcheck/integrations/moodle/moodle-home.htm'); From 1e1fb354ccf0765cb6da16400cc2ef499dc46299 Mon Sep 17 00:00:00 2001 From: Grijesh Saini Date: Tue, 16 Jun 2020 19:34:14 +0530 Subject: [PATCH 25/48] INT-14556 & INT-14441 - Added admin setting to control sending logs to turnitin. Refactored and added test cases. --- callbacks.php | 12 +-- classes/callback.class.php | 2 +- classes/logging_request.class.php | 19 ++-- classes/logging_request_event_info.class.php | 7 +- classes/logging_request_info.class.php | 11 +-- classes/request.class.php | 10 ++- classes/setup_form.class.php | 14 +++ classes/submission.class.php | 10 +-- lang/en/plagiarism_turnitinsim.php | 1 + tests/classes/tscallback_test.php | 1 + tests/classes/tslogging_request_test.php | 92 ++++++++++++++++++++ tests/classes/tssetupform_test.php | 3 + tests/classes/tssubmission_test.php | 14 ++- 13 files changed, 167 insertions(+), 29 deletions(-) create mode 100644 tests/classes/tslogging_request_test.php diff --git a/callbacks.php b/callbacks.php index 2b78c51..f073365 100644 --- a/callbacks.php +++ b/callbacks.php @@ -60,12 +60,12 @@ if ($expectedsecret !== $reqheaders['x-turnitin-signature']) { if ($pluginconfig->turnitinenablelogging) { $logger->error(get_string('webhookincorrectsignature', 'plagiarism_turnitinsim')); - - $eventinfo = new logging_request_event_info("callback.php", $reqheaders, $requeststring); - $loggingrequest = new logging_request(get_string('webhookincorrectsignature', 'plagiarism_turnitinsim')); - $loggingrequest->send_error_to_turnitin(null, $eventinfo, true); } + $eventinfo = new logging_request_event_info("callback.php", $reqheaders, $requeststring); + $loggingrequest = new logging_request('Webhook callback failed as signature is incorrect'); + $loggingrequest->send_error_to_turnitin(null, $eventinfo, true); + echo get_string('webhookincorrectsignature', 'plagiarism_turnitinsim'); exit; } @@ -97,4 +97,6 @@ $tssubmission->handle_similarity_response($params); } -$logger->info('-------- WEBHOOK END --------'); +if ($pluginconfig->turnitinenablelogging) { + $logger->info('-------- WEBHOOK END --------'); +} diff --git a/classes/callback.class.php b/classes/callback.class.php index f45d1f2..e24d44e 100644 --- a/classes/callback.class.php +++ b/classes/callback.class.php @@ -154,7 +154,7 @@ public function create_webhook() { } else { mtrace(get_string('taskoutputwebhooknotcreated', 'plagiarism_turnitinsim', TURNITINSIM_CALLBACK_URL)); $loggingrequestinfo = new logging_request_info(TURNITINSIM_ENDPOINT_WEBHOOKS, "POST", null, $responsedata->httpstatus, $response); - $loggingrequest = new logging_request(get_string('taskoutputwebhooknotcreated', 'plagiarism_turnitinsim', TURNITINSIM_CALLBACK_URL)); + $loggingrequest = new logging_request('Webhook could not be created', $this->tsrequest); $loggingrequest->send_error_to_turnitin($loggingrequestinfo); } diff --git a/classes/logging_request.class.php b/classes/logging_request.class.php index e03201e..751804f 100644 --- a/classes/logging_request.class.php +++ b/classes/logging_request.class.php @@ -52,20 +52,28 @@ class logging_request { /** * Constructor. * - * @param $message string The error message. + * @param string $message The error message. + * @param plagiarism_turnitinsim_request|null $tsrequest Request object. */ - public function __construct($message = 'Error') { - $this->tsrequest = new plagiarism_turnitinsim_request(); + public function __construct($message = 'Error', plagiarism_turnitinsim_request $tsrequest = null) { + $this->tsrequest = ($tsrequest) ? $tsrequest : new plagiarism_turnitinsim_request(); $this->loggingrequest = array(); $this->loggingrequest["message"] = $message; } /** + * Create remote logging request and send to turnitin. + * * @param logging_request_info|null $logging_request_info The logging_request_info object. * @param logging_request_event_info|null $logging_request_event_info The logging_request_event_info object. * @param bool $send_secrets The boolean value, if true send secrets as part of logs. */ public function send_error_to_turnitin(logging_request_info $logging_request_info = null, logging_request_event_info $logging_request_event_info = null, $send_secrets = false) { + + if (!get_config('plagiarism_turnitinsim', 'turnitinenableremotelogging')) { + return; + } + $this->set_basic_details(); if ($send_secrets) { @@ -81,8 +89,7 @@ public function send_error_to_turnitin(logging_request_info $logging_request_inf } try { - $endpoint = TURNITINSIM_ENDPOINT_LOGGING; - $this->tsrequest->send_request($endpoint, json_encode($this->loggingrequest), 'POST', 'general', true, true); + $this->tsrequest->send_request(TURNITINSIM_ENDPOINT_LOGGING, json_encode($this->loggingrequest), 'POST', 'logging', true); } catch (Exception $e) { // Handle silently. } @@ -96,7 +103,7 @@ private function set_basic_details() { $this->loggingrequest["integration_type"] = "Moodle"; $this->loggingrequest["integration_version"] = get_config('plagiarism_turnitinsim', 'version'); - $this->loggingrequest["lms_version"] = $CFG->version; + $this->loggingrequest["lms_version"] = $CFG->branch; $this->loggingrequest["log_level"] = "ERROR"; $this->loggingrequest["date"] = date("Y-m-d H:i:s"); $this->loggingrequest["tenant"] = $this->tsrequest->get_apiurl(); diff --git a/classes/logging_request_event_info.class.php b/classes/logging_request_event_info.class.php index f2f0f5f..56ffbd7 100644 --- a/classes/logging_request_event_info.class.php +++ b/classes/logging_request_event_info.class.php @@ -51,9 +51,10 @@ class logging_request_event_info { /** * logging_request_info constructor. - * @param $url string The url. - * @param $headers array The request headers. - * @param $body string The response body. + * + * @param string $url The url. + * @param array $headers The request headers. + * @param string $body The response body. */ public function __construct($url, $headers = null, $body = null) { $this->url = $url; diff --git a/classes/logging_request_info.class.php b/classes/logging_request_info.class.php index 3b194e4..63ad67c 100644 --- a/classes/logging_request_info.class.php +++ b/classes/logging_request_info.class.php @@ -61,11 +61,12 @@ class logging_request_info { /** * logging_request_info constructor. - * @param $url - * @param $method - * @param $headers - * @param $response_status - * @param $response_body + * + * @param string $url The url. + * @param string $method The Http Method. + * @param array $headers Headers. + * @param int $response_status The response http status. + * @param string $response_body The response body. */ public function __construct($url, $method = null, $headers = null, $response_status = null, $response_body = null) { $this->url = $url; diff --git a/classes/request.class.php b/classes/request.class.php index 76e784a..a6b5fd5 100644 --- a/classes/request.class.php +++ b/classes/request.class.php @@ -108,10 +108,10 @@ public function add_additional_headers($additionalheaders = array()) { * @param string $requestbody The request body to send. * @param string $method The request method eg GET/POST. * @param string $requesttype The type of request, can be general or submission. - * @param bool $isasync The + * @param bool $isasync The flag to define type of http request. * @return array|bool|false|mixed|stdClass|string */ - public function send_request($endpoint, $requestbody, $method, $requesttype = 'general', $isasync = false, $isloggingrequest = false) { + public function send_request($endpoint, $requestbody, $method, $requesttype = 'general', $isasync = false) { global $CFG; // Attach content type to headers if this is not a submission. @@ -121,7 +121,11 @@ public function send_request($endpoint, $requestbody, $method, $requesttype = 'g } } - $tiiurl = ($isloggingrequest) ? str_replace('/api', '', $this->get_apiurl()) : $this->get_apiurl(); + $tiiurl = $this->get_apiurl(); + + if($requesttype === 'logging') { + $tiiurl = str_replace('/api', '', $this->get_apiurl()); + } if ($this->logger) { $this->logger->info('[' . $method . '] Request to: ' . $tiiurl . $endpoint); diff --git a/classes/setup_form.class.php b/classes/setup_form.class.php index c9dc472..b5d7e56 100644 --- a/classes/setup_form.class.php +++ b/classes/setup_form.class.php @@ -79,6 +79,18 @@ public function definition() { array(0, 1) ); + // Toggle Remote Logging. + $mform->addElement( + 'advcheckbox', + 'turnitinenableremotelogging', + get_string('turnitinenableremotelogging', 'plagiarism_turnitinsim'), + '', + null, + array(0, 1) + ); + + $mform->setDefault('turnitinenableremotelogging', 1); + // Toggle Student Data Privacy. $mform->addElement( 'advcheckbox', @@ -160,6 +172,7 @@ public function save($data) { $turnitinapiurl = (!empty($data->turnitinapiurl)) ? $data->turnitinapiurl : ''; $turnitinapikey = (!empty($data->turnitinapikey)) ? $data->turnitinapikey : ''; $turnitinenablelogging = (!empty($data->turnitinenablelogging)) ? $data->turnitinenablelogging : 0; + $turnitinenableremotelogging = (!empty($data->turnitinenableremotelogging)) ? $data->turnitinenableremotelogging : 0; $turnitinhideidentity = (!empty($data->turnitinhideidentity)) ? $data->turnitinhideidentity : 0; $turnitinviewerviewfullsource = (!empty($data->permissionoptions['turnitinviewerviewfullsource'])) ? 1 : 0; $turnitinviewermatchsubinfo = (!empty($data->permissionoptions['turnitinviewermatchsubinfo'])) ? 1 : 0; @@ -176,6 +189,7 @@ public function save($data) { set_config('turnitinapiurl', $turnitinapiurl, 'plagiarism_turnitinsim'); set_config('turnitinapikey', $turnitinapikey, 'plagiarism_turnitinsim'); set_config('turnitinenablelogging', $turnitinenablelogging, 'plagiarism_turnitinsim'); + set_config('turnitinenableremotelogging', $turnitinenableremotelogging, 'plagiarism_turnitinsim'); set_config('turnitinhideidentity', $turnitinhideidentity, 'plagiarism_turnitinsim'); set_config('turnitinviewerviewfullsource', $turnitinviewerviewfullsource, 'plagiarism_turnitinsim'); set_config('turnitinviewermatchsubinfo', $turnitinviewermatchsubinfo, 'plagiarism_turnitinsim'); diff --git a/classes/submission.class.php b/classes/submission.class.php index c814dd8..2ff1173 100644 --- a/classes/submission.class.php +++ b/classes/submission.class.php @@ -487,7 +487,7 @@ public function handle_create_submission_response($params) { $this->seterrormessage($params->message); mtrace(get_string('taskoutputsubmissionnotcreatedgeneral', 'plagiarism_turnitinsim')); $loggingrequestinfo = new logging_request_info(TURNITINSIM_ENDPOINT_CREATE_SUBMISSION, "POST", null, $params->httpstatus, json_encode($params)); - $loggingrequest = new logging_request(get_string('taskoutputsubmissionnotcreatedgeneral', 'plagiarism_turnitinsim')); + $loggingrequest = new logging_request('The submission could not be created in Turnitin'); $loggingrequest->send_error_to_turnitin($loggingrequestinfo); break; } @@ -597,7 +597,7 @@ public function handle_upload_response($params, $filename) { // Save error message if request has errored, otherwise send digital receipts. if ($status == TURNITINSIM_SUBMISSION_STATUS_ERROR) { $this->seterrormessage($params->message); - $loggingrequestinfo = new logging_request_info(TURNITINSIM_ENDPOINT_UPLOAD_SUBMISSION, "POST", null, $params->httpstatus, json_encode($params)); + $loggingrequestinfo = new logging_request_info(TURNITINSIM_ENDPOINT_UPLOAD_SUBMISSION, "POST", null, 500, json_encode($params)); $loggingrequest = new logging_request('Error while uploading the file'); $loggingrequest->set_submissionid($this->turnitinid); $loggingrequest->send_error_to_turnitin($loggingrequestinfo); @@ -632,7 +632,7 @@ public function handle_submission_info_response($params) { $error = isset($params->error_code) ? $params->error_code : get_string('submissiondisplaystatus:unknown', 'plagiarism_turnitinsim'); $this->set_error_with_max_retry_attempts($error, TURNITINSIM_REPORT_GEN_MAX_ATTEMPTS); $loggingrequestinfo = new logging_request_info(TURNITINSIM_ENDPOINT_GET_SUBMISSION_INFO, "GET", null, 500, json_encode($params)); - $loggingrequest = new logging_request($error); + $loggingrequest = new logging_request($error, $this->tsrequest); $loggingrequest->set_submissionid($this->turnitinid); $loggingrequest->send_error_to_turnitin($loggingrequestinfo); } @@ -1384,8 +1384,8 @@ private function reset_retries() { /** * Common method to update maximum retry attempts and error Status. * - * @param $error string Error code from Turnitin. - * @param $retry_attempts int Maximum retry attempts. + * @param string $error Error code from Turnitin. + * @param int $retry_attempts Maximum retry attempts. */ private function set_error_with_max_retry_attempts($error, $retry_attempts) { $this->settiiattempts($retry_attempts); diff --git a/lang/en/plagiarism_turnitinsim.php b/lang/en/plagiarism_turnitinsim.php index e4001f3..05b59af 100644 --- a/lang/en/plagiarism_turnitinsim.php +++ b/lang/en/plagiarism_turnitinsim.php @@ -145,6 +145,7 @@ $string['turnitinsimprivate'] = 'Check against private content'; $string['turnitinconfig'] = 'Plugin configuration'; $string['turnitinenablelogging'] = 'Enable diagnostic mode'; +$string['turnitinenableremotelogging'] = 'Enable remote diagnostic mode'; $string['turnitinfeatures'] = 'Turnitin Integrity features'; $string['turnitinfeatures::header'] = 'Turnitin Integrity features'; $string['turnitinfeatures::moreinfo'] = 'For more information on the enabled features and packages available from Turnitin please see http://www.turnitin.com.'; diff --git a/tests/classes/tscallback_test.php b/tests/classes/tscallback_test.php index ec812f4..16a807e 100644 --- a/tests/classes/tscallback_test.php +++ b/tests/classes/tscallback_test.php @@ -46,6 +46,7 @@ public function setup() { set_config('turnitinapiurl', 'http://www.example.com', 'plagiarism_turnitinsim'); set_config('turnitinapikey', 1234, 'plagiarism_turnitinsim'); set_config('turnitinenablelogging', 0, 'plagiarism_turnitinsim'); + set_config('turnitinenableremotelogging', 0, 'plagiarism_turnitinsim'); $CFG->mtrace_wrapper = 'plagiarism_turnitinsim_mtrace'; } diff --git a/tests/classes/tslogging_request_test.php b/tests/classes/tslogging_request_test.php new file mode 100644 index 0000000..c6e3ba6 --- /dev/null +++ b/tests/classes/tslogging_request_test.php @@ -0,0 +1,92 @@ +. + +/** + * Unit tests for (some of) plagiarism/turnitinsim/classes/submission.class.php. + * + * @package plagiarism_turnitinsim + * @copyright 2017 Turnitin + * @author John McGettrick + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +global $CFG; +require_once($CFG->dirroot . '/plagiarism/turnitinsim/lib.php'); +require_once($CFG->dirroot . '/plagiarism/turnitinsim/tests/utilities.php'); + +/** + * Tests for Turnitin Integrity submission class. + */ +class plagiarism_turnitinsim_logging_request_class_testcase extends advanced_testcase { + + + /** + * Set config for use in the tests. + */ + public function setup() { + // Set plugin as enabled in config for this module type. + set_config('turnitinenableremotelogging', 1, 'plagiarism_turnitinsim'); + set_config('turnitinenablelogging', 0, 'plagiarism_turnitinsim'); + } + + /** + * Test send error to turnitin if remote logging is enabled. + */ + public function test_send_error_to_turnitin_should_send_if_remote_logging_is_enabled() { + $this->resetAfterTest(); + + // Mock API request class. + $tsrequest = $this->getMockBuilder(plagiarism_turnitinsim_request::class) + ->setMethods(['send_request']) + ->getMock(); + + // Mock API send request method. + $tsrequest->expects($this->once()) + ->method('send_request') + ->with(TURNITINSIM_ENDPOINT_LOGGING) + ->willReturn(''); + + $tsloggingrequest = new logging_request('Error', $tsrequest); + + $tsloggingrequest->send_error_to_turnitin(); + } + + /** + * Test send error to turnitin if remote logging is disabled. + */ + public function test_send_error_to_turnitin_should_send_if_remote_logging_is_disabled() { + $this->resetAfterTest(); + + set_config('turnitinenableremotelogging', 0, 'plagiarism_turnitinsim'); + + // Mock API request class. + $tsrequest = $this->getMockBuilder(plagiarism_turnitinsim_request::class) + ->setMethods(['send_request']) + ->getMock(); + + // Mock API send request method. + $tsrequest->expects($this->never()) + ->method('send_request') + ->willReturn(''); + + $tsloggingrequest = new logging_request('Error', $tsrequest); + + $tsloggingrequest->send_error_to_turnitin(); + } + +} \ No newline at end of file diff --git a/tests/classes/tssetupform_test.php b/tests/classes/tssetupform_test.php index 1da8dfe..095f685 100644 --- a/tests/classes/tssetupform_test.php +++ b/tests/classes/tssetupform_test.php @@ -67,6 +67,7 @@ public function test_save_plugin_setup() { $data->turnitinapiurl = self::TEST_API_URL; $data->turnitinapikey = self::TEST_API_KEY; $data->turnitinenablelogging = self::TURNITINSIM_ENABLED; + $data->turnitinenableremotelogging = self::TURNITINSIM_ENABLED; $data->turnitinhideidentity = self::TURNITINSIM_ENABLED; $data->permissionoptions['turnitinviewerviewfullsource'] = self::TURNITINSIM_ENABLED; $data->permissionoptions['turnitinviewermatchsubinfo'] = self::TURNITINSIM_ENABLED; @@ -85,6 +86,7 @@ public function test_save_plugin_setup() { $this->assertEquals(self::TURNITINSIM_ENABLED, $settings->turnitinmodenabledforum); $this->assertEquals(self::TURNITINSIM_ENABLED, $settings->turnitinmodenabledworkshop); $this->assertEquals(self::TURNITINSIM_ENABLED, $settings->turnitinenablelogging); + $this->assertEquals(self::TURNITINSIM_ENABLED, $settings->turnitinenableremotelogging); $this->assertEquals(self::TEST_API_URL, $settings->turnitinapiurl); $this->assertEquals(self::TEST_API_KEY, $settings->turnitinapikey); $this->assertEquals(self::TURNITINSIM_ENABLED, $settings->turnitinhideidentity); @@ -115,6 +117,7 @@ public function test_save_plugin_setup_empty() { $this->assertEquals('', $settings->turnitinapiurl); $this->assertEquals('', $settings->turnitinapikey); $this->assertEquals(self::TURNITINSIM_DISABLED, $settings->turnitinenablelogging); + $this->assertEquals(self::TURNITINSIM_DISABLED, $settings->turnitinenableremotelogging); $this->assertEquals(self::TURNITINSIM_DISABLED, $settings->turnitinhideidentity); $this->assertEquals(self::TURNITINSIM_DISABLED, $settings->turnitinviewerviewfullsource); $this->assertEquals(self::TURNITINSIM_DISABLED, $settings->turnitinviewermatchsubinfo); diff --git a/tests/classes/tssubmission_test.php b/tests/classes/tssubmission_test.php index 6362e51..7c15bd6 100644 --- a/tests/classes/tssubmission_test.php +++ b/tests/classes/tssubmission_test.php @@ -64,6 +64,7 @@ public function setup() { set_config('turnitinapiurl', 'http://www.example.com', 'plagiarism_turnitinsim'); set_config('turnitinapikey', 1234, 'plagiarism_turnitinsim'); set_config('turnitinenablelogging', 0, 'plagiarism_turnitinsim'); + set_config('turnitinenableremotelogging', 1, 'plagiarism_turnitinsim'); // Set webhook details so tests don't create one. set_config('turnitin_webhook_id', 1, 'plagiarism_turnitinsim'); @@ -2072,11 +2073,22 @@ public function test_handle_submission_info_if_submission_is_in_error_state() { $this->resetAfterTest(); + // Mock API request class. + $tsrequest = $this->getMockBuilder(plagiarism_turnitinsim_request::class) + ->setMethods(['send_request']) + ->getMock(); + + // Mock API send request method. + $tsrequest->expects($this->once()) + ->method('send_request') + ->with(TURNITINSIM_ENDPOINT_LOGGING) + ->willReturn(''); + $params = new stdClass(); $params->status = TURNITINSIM_SUBMISSION_STATUS_ERROR; $params->error_code = TURNITINSIM_SUBMISSION_STATUS_TOO_LITTLE_TEXT; - $tssubmission = new plagiarism_turnitinsim_submission(); + $tssubmission = new plagiarism_turnitinsim_submission($tsrequest); $tssubmission->setcm(1); $tssubmission->setuserid(1); $tssubmission->setsubmitter(1); From 16c427eec975daa66ef3e124d0899a6099149131 Mon Sep 17 00:00:00 2001 From: Grijesh Saini Date: Wed, 17 Jun 2020 16:26:39 +0530 Subject: [PATCH 26/48] INT-14556 & INT-14441 - Resolved all the code warnings. --- classes/callback.class.php | 3 +- classes/logging_request.class.php | 57 ++++++++++---------- classes/logging_request_event_info.class.php | 6 +-- classes/logging_request_info.class.php | 26 ++++----- classes/request.class.php | 2 +- classes/submission.class.php | 27 ++++++---- tests/classes/tsrequest_test.php | 13 +++-- 7 files changed, 71 insertions(+), 63 deletions(-) diff --git a/classes/callback.class.php b/classes/callback.class.php index e24d44e..ffb5e00 100644 --- a/classes/callback.class.php +++ b/classes/callback.class.php @@ -153,7 +153,8 @@ public function create_webhook() { mtrace(get_string('taskoutputwebhookcreated', 'plagiarism_turnitinsim', TURNITINSIM_CALLBACK_URL)); } else { mtrace(get_string('taskoutputwebhooknotcreated', 'plagiarism_turnitinsim', TURNITINSIM_CALLBACK_URL)); - $loggingrequestinfo = new logging_request_info(TURNITINSIM_ENDPOINT_WEBHOOKS, "POST", null, $responsedata->httpstatus, $response); + $loggingrequestinfo = new logging_request_info(TURNITINSIM_ENDPOINT_WEBHOOKS, "POST", + null, $responsedata->httpstatus, $response); $loggingrequest = new logging_request('Webhook could not be created', $this->tsrequest); $loggingrequest->send_error_to_turnitin($loggingrequestinfo); } diff --git a/classes/logging_request.class.php b/classes/logging_request.class.php index 751804f..33d99f2 100644 --- a/classes/logging_request.class.php +++ b/classes/logging_request.class.php @@ -18,8 +18,8 @@ * Submission class for plagiarism_turnitinsim component. * * @package plagiarism_turnitinsim - * @copyright 2017 Turnitin - * @author John McGettrick + * @copyright 2020 Turnitin + * @author Grijesh Saini * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -64,11 +64,12 @@ public function __construct($message = 'Error', plagiarism_turnitinsim_request $ /** * Create remote logging request and send to turnitin. * - * @param logging_request_info|null $logging_request_info The logging_request_info object. - * @param logging_request_event_info|null $logging_request_event_info The logging_request_event_info object. - * @param bool $send_secrets The boolean value, if true send secrets as part of logs. + * @param logging_request_info|null $loggingrequestinfo The logging_request_info object. + * @param logging_request_event_info|null $loggingrequesteventinfo The logging_request_event_info object. + * @param bool $sendsecrets The boolean value, if true send secrets as part of logs. */ - public function send_error_to_turnitin(logging_request_info $logging_request_info = null, logging_request_event_info $logging_request_event_info = null, $send_secrets = false) { + public function send_error_to_turnitin(logging_request_info $loggingrequestinfo = null, + logging_request_event_info $loggingrequesteventinfo = null, $sendsecrets = false) { if (!get_config('plagiarism_turnitinsim', 'turnitinenableremotelogging')) { return; @@ -76,22 +77,24 @@ public function send_error_to_turnitin(logging_request_info $logging_request_inf $this->set_basic_details(); - if ($send_secrets) { - $this->set_secrets(); + if ($sendsecrets) { + $this->set_secrets(); } - if ($logging_request_info) { - $this->set_request_info($logging_request_info); + if ($loggingrequestinfo) { + $this->set_request_info($loggingrequestinfo); } - if ($logging_request_event_info) { - $this->set_event_info($logging_request_event_info); + if ($loggingrequesteventinfo) { + $this->set_event_info($loggingrequesteventinfo); } try { - $this->tsrequest->send_request(TURNITINSIM_ENDPOINT_LOGGING, json_encode($this->loggingrequest), 'POST', 'logging', true); + $this->tsrequest->send_request(TURNITINSIM_ENDPOINT_LOGGING, json_encode($this->loggingrequest), + 'POST', 'logging', true); } catch (Exception $e) { - // Handle silently. + $logger = new plagiarism_turnitinsim_logger(); + $logger->error('Error while sending logs'); } } @@ -121,25 +124,25 @@ private function set_secrets() { /** * Set request info details. * - * @param logging_request_info $logging_request_info The logging_request_info object. + * @param logging_request_info $loggingrequestinfo The logging_request_info object. */ - private function set_request_info(logging_request_info $logging_request_info) { - $this->loggingrequest["request"]["url"] = $logging_request_info->get_url(); - $this->loggingrequest["request"]["method"] = $logging_request_info->get_method(); - $this->loggingrequest["request"]["headers"] = $logging_request_info->get_headers(); - $this->loggingrequest["request"]["response_status"] = $logging_request_info->get_response_status(); - $this->loggingrequest["request"]["response_body"] = $logging_request_info->get_response_body(); + private function set_request_info(logging_request_info $loggingrequestinfo) { + $this->loggingrequest["request"]["url"] = $loggingrequestinfo->get_url(); + $this->loggingrequest["request"]["method"] = $loggingrequestinfo->get_method(); + $this->loggingrequest["request"]["headers"] = $loggingrequestinfo->get_headers(); + $this->loggingrequest["request"]["response_status"] = $loggingrequestinfo->get_responsestatus(); + $this->loggingrequest["request"]["response_body"] = $loggingrequestinfo->get_responsebody(); } /** * Set event info details. * - * @param logging_request_event_info $logging_request_event_info The $logging_request_event_info object. + * @param logging_request_event_info $loggingrequesteventinfo The $logging_request_event_info object. */ - private function set_event_info(logging_request_event_info $logging_request_event_info) { - $this->loggingrequest["event"]["url"] = $logging_request_event_info->get_url(); - $this->loggingrequest["event"]["headers"] = $logging_request_event_info->get_headers(); - $this->loggingrequest["event"]["body"] = $logging_request_event_info->get_body(); + private function set_event_info(logging_request_event_info $loggingrequesteventinfo) { + $this->loggingrequest["event"]["url"] = $loggingrequesteventinfo->get_url(); + $this->loggingrequest["event"]["headers"] = $loggingrequesteventinfo->get_headers(); + $this->loggingrequest["event"]["body"] = $loggingrequesteventinfo->get_body(); } /** @@ -147,7 +150,7 @@ private function set_event_info(logging_request_event_info $logging_request_even * * @param string $submissionid */ - public function set_submissionid($submissionid){ + public function set_submissionid($submissionid) { $this->submissionid = $submissionid; } diff --git a/classes/logging_request_event_info.class.php b/classes/logging_request_event_info.class.php index 56ffbd7..377ce45 100644 --- a/classes/logging_request_event_info.class.php +++ b/classes/logging_request_event_info.class.php @@ -18,8 +18,8 @@ * Submission class for plagiarism_turnitinsim component. * * @package plagiarism_turnitinsim - * @copyright 2017 Turnitin - * @author John McGettrick + * @copyright 2020 Turnitin + * @author Grijesh Saini * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -51,7 +51,7 @@ class logging_request_event_info { /** * logging_request_info constructor. - * + * * @param string $url The url. * @param array $headers The request headers. * @param string $body The response body. diff --git a/classes/logging_request_info.class.php b/classes/logging_request_info.class.php index 63ad67c..6cec848 100644 --- a/classes/logging_request_info.class.php +++ b/classes/logging_request_info.class.php @@ -18,8 +18,8 @@ * Submission class for plagiarism_turnitinsim component. * * @package plagiarism_turnitinsim - * @copyright 2017 Turnitin - * @author John McGettrick + * @copyright 2020 Turnitin + * @author Grijesh Saini * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -52,12 +52,12 @@ class logging_request_info { /** * @var int Response http status. */ - private $response_status; + private $responsestatus; /** * @var string The response body. */ - private $response_body; + private $responsebody; /** * logging_request_info constructor. @@ -65,15 +65,15 @@ class logging_request_info { * @param string $url The url. * @param string $method The Http Method. * @param array $headers Headers. - * @param int $response_status The response http status. - * @param string $response_body The response body. + * @param int $responsestatus The response http status. + * @param string $responsebody The response body. */ - public function __construct($url, $method = null, $headers = null, $response_status = null, $response_body = null) { + public function __construct($url, $method = null, $headers = null, $responsestatus = null, $responsebody = null) { $this->url = $url; $this->method = $method; $this->headers = $headers; - $this->response_status = $response_status; - $this->response_body = $response_body; + $this->responsestatus = $responsestatus; + $this->responsebody = $responsebody; } @@ -109,8 +109,8 @@ public function get_headers() { * * @return int */ - public function get_response_status() { - return $this->response_status; + public function get_responsestatus() { + return $this->responsestatus; } /** @@ -118,8 +118,8 @@ public function get_response_status() { * * @return string */ - public function get_response_body() { - return $this->response_body; + public function get_responsebody() { + return $this->responsebody; } } \ No newline at end of file diff --git a/classes/request.class.php b/classes/request.class.php index a6b5fd5..d9ae356 100644 --- a/classes/request.class.php +++ b/classes/request.class.php @@ -123,7 +123,7 @@ public function send_request($endpoint, $requestbody, $method, $requesttype = 'g $tiiurl = $this->get_apiurl(); - if($requesttype === 'logging') { + if ($requesttype === 'logging') { $tiiurl = str_replace('/api', '', $this->get_apiurl()); } diff --git a/classes/submission.class.php b/classes/submission.class.php index 2ff1173..ae16592 100644 --- a/classes/submission.class.php +++ b/classes/submission.class.php @@ -486,7 +486,8 @@ public function handle_create_submission_response($params) { $this->settiiattempts(TURNITINSIM_SUBMISSION_MAX_SEND_ATTEMPTS); $this->seterrormessage($params->message); mtrace(get_string('taskoutputsubmissionnotcreatedgeneral', 'plagiarism_turnitinsim')); - $loggingrequestinfo = new logging_request_info(TURNITINSIM_ENDPOINT_CREATE_SUBMISSION, "POST", null, $params->httpstatus, json_encode($params)); + $loggingrequestinfo = new logging_request_info(TURNITINSIM_ENDPOINT_CREATE_SUBMISSION, + "POST", null, $params->httpstatus, json_encode($params)); $loggingrequest = new logging_request('The submission could not be created in Turnitin'); $loggingrequest->send_error_to_turnitin($loggingrequestinfo); break; @@ -597,7 +598,8 @@ public function handle_upload_response($params, $filename) { // Save error message if request has errored, otherwise send digital receipts. if ($status == TURNITINSIM_SUBMISSION_STATUS_ERROR) { $this->seterrormessage($params->message); - $loggingrequestinfo = new logging_request_info(TURNITINSIM_ENDPOINT_UPLOAD_SUBMISSION, "POST", null, 500, json_encode($params)); + $loggingrequestinfo = new logging_request_info(TURNITINSIM_ENDPOINT_UPLOAD_SUBMISSION, + "POST", null, 500, json_encode($params)); $loggingrequest = new logging_request('Error while uploading the file'); $loggingrequest->set_submissionid($this->turnitinid); $loggingrequest->send_error_to_turnitin($loggingrequestinfo); @@ -616,10 +618,10 @@ public function handle_upload_response($params, $filename) { public function handle_submission_info_response($params) { $issubmissioncomplete = false; - //Handle scenario if Turnitin API is returning error. - //Set status as processing, so it will be retried. + // Handle scenario if Turnitin API is returning error. + // Set status as processing, so it will be retried. if (!empty($params->httpstatus) && ($params->httpstatus !== TURNITINSIM_HTTP_OK)) { - $params->status=TURNITINSIM_SUBMISSION_STATUS_PROCESSING; + $params->status = TURNITINSIM_SUBMISSION_STATUS_PROCESSING; } // On success, reset retries. On error, never retry. @@ -629,9 +631,11 @@ public function handle_submission_info_response($params) { } else if ($params->status === TURNITINSIM_SUBMISSION_STATUS_PROCESSING) { $this->update_report_generation_retries(); } else { - $error = isset($params->error_code) ? $params->error_code : get_string('submissiondisplaystatus:unknown', 'plagiarism_turnitinsim'); + $error = isset($params->error_code) ? $params->error_code : + get_string('submissiondisplaystatus:unknown', 'plagiarism_turnitinsim'); $this->set_error_with_max_retry_attempts($error, TURNITINSIM_REPORT_GEN_MAX_ATTEMPTS); - $loggingrequestinfo = new logging_request_info(TURNITINSIM_ENDPOINT_GET_SUBMISSION_INFO, "GET", null, 500, json_encode($params)); + $loggingrequestinfo = new logging_request_info(TURNITINSIM_ENDPOINT_GET_SUBMISSION_INFO, + "GET", null, 500, json_encode($params)); $loggingrequest = new logging_request($error, $this->tsrequest); $loggingrequest->set_submissionid($this->turnitinid); $loggingrequest->send_error_to_turnitin($loggingrequestinfo); @@ -1385,10 +1389,10 @@ private function reset_retries() { * Common method to update maximum retry attempts and error Status. * * @param string $error Error code from Turnitin. - * @param int $retry_attempts Maximum retry attempts. + * @param int $retryattempts Maximum retry attempts. */ - private function set_error_with_max_retry_attempts($error, $retry_attempts) { - $this->settiiattempts($retry_attempts); + private function set_error_with_max_retry_attempts($error, $retryattempts) { + $this->settiiattempts($retryattempts); $this->seterrormessage($error); $this->setstatus(TURNITINSIM_SUBMISSION_STATUS_ERROR); } @@ -1402,7 +1406,8 @@ private function update_report_generation_retries() { if ($this->gettiiattempts() === 1) { $this->settiiretrytime(time() + TURNITINSIM_REPORT_GEN_FIRST_ATTEMPT_RETRY_WAIT_SECONDS); } else if ($this->gettiiattempts() === TURNITINSIM_REPORT_GEN_MAX_ATTEMPTS) { - $this->set_error_with_max_retry_attempts(get_string('submissiondisplaystatus:unknown', 'plagiarism_turnitinsim'), TURNITINSIM_REPORT_GEN_MAX_ATTEMPTS); + $this->set_error_with_max_retry_attempts(get_string('submissiondisplaystatus:unknown', 'plagiarism_turnitinsim'), + TURNITINSIM_REPORT_GEN_MAX_ATTEMPTS); } else { $this->settiiretrytime(time() + ($this->gettiiattempts() * TURNITINSIM_REPORT_GEN_RETRY_WAIT_SECONDS)); } diff --git a/tests/classes/tsrequest_test.php b/tests/classes/tsrequest_test.php index 6fffaad..c890e3e 100644 --- a/tests/classes/tsrequest_test.php +++ b/tests/classes/tsrequest_test.php @@ -61,32 +61,31 @@ public function test_connection_test() { ->setConstructorArgs([TURNITINSIM_ENDPOINT_WEBHOOKS]) ->getMock(); - //Test connection should return failed if url is missing. + // Test connection should return failed if url is missing. $result = $tsrequest->test_connection("", "key"); $responsesuccessparsed = (array)json_decode($result); $this->assertEquals(TURNITINSIM_HTTP_BAD_REQUEST, $responsesuccessparsed['connection_status']); - //Test connection should return failed if key is missing. + // Test connection should return failed if key is missing. $result = $tsrequest->test_connection("url", ""); $responsesuccessparsed = (array)json_decode($result); $this->assertEquals(TURNITINSIM_HTTP_BAD_REQUEST, $responsesuccessparsed['connection_status']); - //Test connection should return failed if url is invalid TII url. + // Test connection should return failed if url is invalid TII url. $result = $tsrequest->test_connection("http://abcd.tii.com", "key"); $responsesuccessparsed = (array)json_decode($result); $this->assertEquals(TURNITINSIM_HTTP_BAD_REQUEST, $responsesuccessparsed['connection_status']); - //Test connection should return failed if url doesn't end with /api. + // Test connection should return failed if url doesn't end with /api. $result = $tsrequest->test_connection("http://abcd.turnitin.com", "key"); $responsesuccessparsed = (array)json_decode($result); $this->assertEquals(TURNITINSIM_HTTP_BAD_REQUEST, $responsesuccessparsed['connection_status']); - - // Mock API send request method. $tsrequest->expects($this->exactly(6)) ->method('send_request') - ->willReturnOnConsecutiveCalls($responsesuccess, $responsesuccess, $responsesuccess, $responsesuccess, $responsesuccess, $responsefailure); + ->willReturnOnConsecutiveCalls($responsesuccess, $responsesuccess, $responsesuccess, $responsesuccess, + $responsesuccess, $responsefailure); // Test connection. $result = $tsrequest->test_connection("http://test.turnitin.com/api", "key"); From 6ffee392d1aa1653160ab92f1fe59fbc503cf084 Mon Sep 17 00:00:00 2001 From: David Winn Date: Wed, 17 Jun 2020 14:38:23 +0100 Subject: [PATCH 27/48] phpdoc fixes --- lib.php | 2 +- utilities/handle_deprecation.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib.php b/lib.php index 0f53455..85b7b81 100644 --- a/lib.php +++ b/lib.php @@ -715,7 +715,7 @@ public function module_updated($eventdata) { * Wrapper method for Moodle's set_config method for enabling the plugin. * This is so that when the deprecation is deleted we only need to change one place. * - * @param$enabled int 1 if plugin is to be enabled. + * @param int $enabled 1 if plugin is to be enabled. */ public static function enable_plugin($enabled) { handle_deprecation::set_plugin_enabled($enabled); diff --git a/utilities/handle_deprecation.php b/utilities/handle_deprecation.php index e826183..93e21aa 100644 --- a/utilities/handle_deprecation.php +++ b/utilities/handle_deprecation.php @@ -76,7 +76,7 @@ public function unset_turnitinsim_use() { * * This method handles our support for multiple Moodle versions for setting the config value. * - * @param $enabled int 1 if enabled, 0 if not. + * @param int $enabled 1 if enabled, 0 if not. */ public static function set_plugin_enabled($enabled) { global $CFG; From 04c1d3e823b78eb1c5803a6a347e488759d3c98a Mon Sep 17 00:00:00 2001 From: Grijesh Saini Date: Mon, 22 Jun 2020 19:01:37 +0530 Subject: [PATCH 28/48] INT-14488 - Regenerating report on due date. --- classes/submission.class.php | 10 +++- classes/task.class.php | 5 +- tests/classes/tssubmission_test.php | 81 +++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 3 deletions(-) diff --git a/classes/submission.class.php b/classes/submission.class.php index ae16592..093ef91 100644 --- a/classes/submission.class.php +++ b/classes/submission.class.php @@ -694,8 +694,9 @@ public function send_digital_receipts($filename) { /** * Request a Turnitin report to be generated. + * @param bool $regenerateonduedate if true then set to generate to 0 else calculate generation time. */ - public function request_turnitin_report_generation() { + public function request_turnitin_report_generation($regenerateonduedate = false) { // Get module settings. $plugin = new plagiarism_plugin_turnitinsim(); $modulesettings = $plugin->get_settings($this->getcm()); @@ -750,7 +751,12 @@ public function request_turnitin_report_generation() { } $this->setrequestedtime(time()); - $this->calculate_generation_time(true); + + if ($regenerateonduedate) { + $this->settogenerate(0); + } else { + $this->calculate_generation_time(true); + } $this->update(); } catch (Exception $e) { $this->tsrequest->handle_exception($e, 'taskoutputfailedreportrequest', $this->getturnitinid()); diff --git a/classes/task.class.php b/classes/task.class.php index 339b519..8d26f26 100644 --- a/classes/task.class.php +++ b/classes/task.class.php @@ -171,7 +171,10 @@ public function get_reports() { if ($tssubmission->handle_submission_info_response($tssubmission->get_submission_info())) { $tssubmission->request_turnitin_report_generation(); } - } else if ($tssubmission->getstatus() != TURNITINSIM_SUBMISSION_STATUS_UPLOADED + } else if ($tssubmission->getstatus() === TURNITINSIM_SUBMISSION_STATUS_COMPLETE) { + $tssubmission->request_turnitin_report_generation(true); + } else if ($tssubmission->getstatus() != TURNITINSIM_SUBMISSION_STATUS_COMPLETE + && $tssubmission->getstatus() != TURNITINSIM_SUBMISSION_STATUS_UPLOADED && $tssubmission->getrequestedtime() < (time() - $this->get_report_gen_score_delay())) { $tssubmission->request_turnitin_report_score(); } diff --git a/tests/classes/tssubmission_test.php b/tests/classes/tssubmission_test.php index 379cd0a..8095e6b 100644 --- a/tests/classes/tssubmission_test.php +++ b/tests/classes/tssubmission_test.php @@ -789,6 +789,87 @@ public function test_request_turnitin_report_generation_success() { $this->assertEquals(TURNITINSIM_SUBMISSION_STATUS_REQUESTED, $tssubmission->getstatus()); } + /** + * Test successful report generation request on due date. + */ + public function test_request_turnitin_report_generation_success_on_due_date() { + $this->resetAfterTest(); + + // Get the response for a successfully created submission. + $reportgenresponse = file_get_contents(__DIR__ . '/../fixtures/request_report_generation_success.json'); + + // Mock API create submission request class and send call. + $tsrequest = $this->getMockBuilder(plagiarism_turnitinsim_request::class) + ->setMethods(['send_request']) + ->getMock(); + + // Add submission ID to endpoint. + $endpoint = TURNITINSIM_ENDPOINT_SIMILARITY_REPORT; + $endpoint = str_replace('{{submission_id}}', self::VALID_SUBMISSION_ID, $endpoint); + + // Mock send request method for upload. + $tsrequest->expects($this->once()) + ->method('send_request') + ->with($endpoint) + ->willReturn($reportgenresponse); + + // Log student in. + $this->setUser($this->student1); + $usercontext = context_user::instance($this->student1->id); + + // Create assign module. + $record = new stdClass(); + $record->course = $this->course; + $record->submissiondrafts = 0; + $module = $this->getDataGenerator()->create_module('assign', $record); + + // Get course module data. + $cm = get_coursemodule_from_instance('assign', $module->id); + $context = context_module::instance($cm->id); + $assign = new assign($context, $cm, $record->course); + + // Create assignment submission. + $submission = $assign->get_user_submission($this->student1->id, true); + $data = new stdClass(); + $plugin = $assign->get_submission_plugin_by_type('file'); + $plugin->save($submission, $data); + + $file = create_test_file($submission->id, $usercontext->id, 'mod_assign', 'submissions'); + + // Create data object for cm assignment. + $data = new stdClass(); + $data->coursemodule = $cm->id; + $data->turnitinenabled = 1; + $data->checkinternet = 1; + $data->checkprivate = 1; + + // Save Module Settings. + $form = new plagiarism_turnitinsim_settings(); + $form->save_module_settings($data); + + // Create submission object. + $tssubmission = new plagiarism_turnitinsim_submission($tsrequest); + $tssubmission->setcm($cm->id); + $tssubmission->setuserid($this->student1->id); + $tssubmission->setsubmitter($this->student1->id); + $tssubmission->setidentifier($file->get_pathnamehash()); + $tssubmission->setitemid($submission->id); + $tssubmission->setturnitinid(self::VALID_SUBMISSION_ID); + $tssubmission->setstatus(TURNITINSIM_SUBMISSION_STATUS_UPLOADED); + $tssubmission->settype(TURNITINSIM_SUBMISSION_TYPE_FILE); + + $currenttime = time(); + $tssubmission->setgenerationtime($currenttime); + + // Request report generation. + $tssubmission->request_turnitin_report_generation(true); + + // Test that the submission status is uploaded. + $this->assertEquals(TURNITINSIM_SUBMISSION_STATUS_REQUESTED, $tssubmission->getstatus()); + $this->assertEquals(0, $tssubmission->gettogenerate()); + $this->assertEquals($currenttime, $tssubmission->getgenerationtime()); + } + /** * Test report generation request failure with invalid ID. */ From 5a69c43a40b9d590b42b507b965c0fcaa7933737 Mon Sep 17 00:00:00 2001 From: David Winn Date: Mon, 22 Jun 2020 17:30:47 +0100 Subject: [PATCH 29/48] Set defaults for messaging for EULA message so that it does not email by default --- db/install.php | 2 ++ db/messages.php | 7 ++++++- db/uninstall.php | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/db/install.php b/db/install.php index 3d084dc..5451274 100644 --- a/db/install.php +++ b/db/install.php @@ -25,6 +25,8 @@ defined('MOODLE_INTERNAL') || die(); +require_once($CFG->dirroot . '/plagiarism/turnitinsim/lib.php'); + /** * Configuration to update on install. */ diff --git a/db/messages.php b/db/messages.php index 10757f4..c589dc8 100644 --- a/db/messages.php +++ b/db/messages.php @@ -37,5 +37,10 @@ 'capability' => 'moodle/site:config' ), // Notify all Turnitin users with a link to accept the new EULA. - 'new_eula' => array () + 'new_eula' => array ( + 'defaults' => [ + 'popup' => MESSAGE_PERMITTED, + 'email' => MESSAGE_PERMITTED + ], + ) ); \ No newline at end of file diff --git a/db/uninstall.php b/db/uninstall.php index 57c7b1a..35844ae 100644 --- a/db/uninstall.php +++ b/db/uninstall.php @@ -25,6 +25,8 @@ defined('MOODLE_INTERNAL') || die(); +require_once($CFG->dirroot . '/plagiarism/turnitinsim/lib.php'); + /** * Configuration to remove on install. */ From 605c177c6d54b944d68c77b7cce8d2c301b753a9 Mon Sep 17 00:00:00 2001 From: David Winn Date: Tue, 23 Jun 2020 10:21:30 +0100 Subject: [PATCH 30/48] Addition of unit test fix in 3.8 --- tests/utilities/handle_deprecation_test.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/utilities/handle_deprecation_test.php b/tests/utilities/handle_deprecation_test.php index 3b6d1f2..8f9ae1d 100644 --- a/tests/utilities/handle_deprecation_test.php +++ b/tests/utilities/handle_deprecation_test.php @@ -65,6 +65,8 @@ public function test_plugin_enabled() { public function test_unset_turnitinsim_use_unsets_value_in_39() { $this->resetAfterTest(); + set_config('branch', 39); + set_config( 'turnitinsim_use', 1, 'plagiarism'); (new handle_deprecation)->unset_turnitinsim_use(); From 80cc642ac22c98f90928866a887392fb39fb638d Mon Sep 17 00:00:00 2001 From: Grijesh Saini Date: Tue, 23 Jun 2020 16:41:54 +0530 Subject: [PATCH 31/48] INT-14488 - Renamed logging classes and refactored test. --- callbacks.php | 4 ++-- classes/callback.class.php | 4 ++-- classes/logging_request.class.php | 18 +++++++++--------- classes/logging_request_event_info.class.php | 2 +- classes/logging_request_info.class.php | 2 +- classes/submission.class.php | 13 +++++++------ tests/classes/tslogging_request_test.php | 4 ++-- tests/classes/tssubmission_test.php | 5 +---- 8 files changed, 25 insertions(+), 27 deletions(-) diff --git a/callbacks.php b/callbacks.php index f073365..8dec07a 100644 --- a/callbacks.php +++ b/callbacks.php @@ -62,8 +62,8 @@ $logger->error(get_string('webhookincorrectsignature', 'plagiarism_turnitinsim')); } - $eventinfo = new logging_request_event_info("callback.php", $reqheaders, $requeststring); - $loggingrequest = new logging_request('Webhook callback failed as signature is incorrect'); + $eventinfo = new plagiarism_turnitinsim_logging_request_event_info("callback.php", $reqheaders, $requeststring); + $loggingrequest = new plagiarism_turnitinsim_logging_request('Webhook callback failed as signature is incorrect'); $loggingrequest->send_error_to_turnitin(null, $eventinfo, true); echo get_string('webhookincorrectsignature', 'plagiarism_turnitinsim'); diff --git a/classes/callback.class.php b/classes/callback.class.php index ffb5e00..2448530 100644 --- a/classes/callback.class.php +++ b/classes/callback.class.php @@ -153,9 +153,9 @@ public function create_webhook() { mtrace(get_string('taskoutputwebhookcreated', 'plagiarism_turnitinsim', TURNITINSIM_CALLBACK_URL)); } else { mtrace(get_string('taskoutputwebhooknotcreated', 'plagiarism_turnitinsim', TURNITINSIM_CALLBACK_URL)); - $loggingrequestinfo = new logging_request_info(TURNITINSIM_ENDPOINT_WEBHOOKS, "POST", + $loggingrequestinfo = new plagiarism_turnitinsim_logging_request_info(TURNITINSIM_ENDPOINT_WEBHOOKS, "POST", null, $responsedata->httpstatus, $response); - $loggingrequest = new logging_request('Webhook could not be created', $this->tsrequest); + $loggingrequest = new plagiarism_turnitinsim_logging_request('Webhook could not be created', $this->tsrequest); $loggingrequest->send_error_to_turnitin($loggingrequestinfo); } diff --git a/classes/logging_request.class.php b/classes/logging_request.class.php index 33d99f2..38cd2eb 100644 --- a/classes/logging_request.class.php +++ b/classes/logging_request.class.php @@ -32,7 +32,7 @@ /** * Class for sending error logs to Turnitin. */ -class logging_request { +class plagiarism_turnitinsim_logging_request { /** * @var object The request object. @@ -64,12 +64,12 @@ public function __construct($message = 'Error', plagiarism_turnitinsim_request $ /** * Create remote logging request and send to turnitin. * - * @param logging_request_info|null $loggingrequestinfo The logging_request_info object. - * @param logging_request_event_info|null $loggingrequesteventinfo The logging_request_event_info object. + * @param plagiarism_turnitinsim_logging_request_info|null $loggingrequestinfo The logging_request_info object. + * @param plagiarism_turnitinsim_logging_request_event_info|null $loggingrequesteventinfo The logging_request_event_info object. * @param bool $sendsecrets The boolean value, if true send secrets as part of logs. */ - public function send_error_to_turnitin(logging_request_info $loggingrequestinfo = null, - logging_request_event_info $loggingrequesteventinfo = null, $sendsecrets = false) { + public function send_error_to_turnitin(plagiarism_turnitinsim_logging_request_info $loggingrequestinfo = null, + plagiarism_turnitinsim_logging_request_event_info $loggingrequesteventinfo = null, $sendsecrets = false) { if (!get_config('plagiarism_turnitinsim', 'turnitinenableremotelogging')) { return; @@ -124,9 +124,9 @@ private function set_secrets() { /** * Set request info details. * - * @param logging_request_info $loggingrequestinfo The logging_request_info object. + * @param plagiarism_turnitinsim_logging_request_info $loggingrequestinfo The logging_request_info object. */ - private function set_request_info(logging_request_info $loggingrequestinfo) { + private function set_request_info(plagiarism_turnitinsim_logging_request_info $loggingrequestinfo) { $this->loggingrequest["request"]["url"] = $loggingrequestinfo->get_url(); $this->loggingrequest["request"]["method"] = $loggingrequestinfo->get_method(); $this->loggingrequest["request"]["headers"] = $loggingrequestinfo->get_headers(); @@ -137,9 +137,9 @@ private function set_request_info(logging_request_info $loggingrequestinfo) { /** * Set event info details. * - * @param logging_request_event_info $loggingrequesteventinfo The $logging_request_event_info object. + * @param plagiarism_turnitinsim_logging_request_event_info $loggingrequesteventinfo The $logging_request_event_info object. */ - private function set_event_info(logging_request_event_info $loggingrequesteventinfo) { + private function set_event_info(plagiarism_turnitinsim_logging_request_event_info $loggingrequesteventinfo) { $this->loggingrequest["event"]["url"] = $loggingrequesteventinfo->get_url(); $this->loggingrequest["event"]["headers"] = $loggingrequesteventinfo->get_headers(); $this->loggingrequest["event"]["body"] = $loggingrequesteventinfo->get_body(); diff --git a/classes/logging_request_event_info.class.php b/classes/logging_request_event_info.class.php index 377ce45..88590c1 100644 --- a/classes/logging_request_event_info.class.php +++ b/classes/logging_request_event_info.class.php @@ -32,7 +32,7 @@ /** * Class models event info sent to be logged. */ -class logging_request_event_info { +class plagiarism_turnitinsim_logging_request_event_info { /** * @var string The url. diff --git a/classes/logging_request_info.class.php b/classes/logging_request_info.class.php index 6cec848..1dce609 100644 --- a/classes/logging_request_info.class.php +++ b/classes/logging_request_info.class.php @@ -32,7 +32,7 @@ /** * Class models request info sent to be logged. */ -class logging_request_info { +class plagiarism_turnitinsim_logging_request_info { /** * @var string The url. diff --git a/classes/submission.class.php b/classes/submission.class.php index 093ef91..b679bad 100644 --- a/classes/submission.class.php +++ b/classes/submission.class.php @@ -486,9 +486,9 @@ public function handle_create_submission_response($params) { $this->settiiattempts(TURNITINSIM_SUBMISSION_MAX_SEND_ATTEMPTS); $this->seterrormessage($params->message); mtrace(get_string('taskoutputsubmissionnotcreatedgeneral', 'plagiarism_turnitinsim')); - $loggingrequestinfo = new logging_request_info(TURNITINSIM_ENDPOINT_CREATE_SUBMISSION, + $loggingrequestinfo = new plagiarism_turnitinsim_logging_request_info(TURNITINSIM_ENDPOINT_CREATE_SUBMISSION, "POST", null, $params->httpstatus, json_encode($params)); - $loggingrequest = new logging_request('The submission could not be created in Turnitin'); + $loggingrequest = new plagiarism_turnitinsim_logging_request('The submission could not be created in Turnitin'); $loggingrequest->send_error_to_turnitin($loggingrequestinfo); break; } @@ -598,9 +598,9 @@ public function handle_upload_response($params, $filename) { // Save error message if request has errored, otherwise send digital receipts. if ($status == TURNITINSIM_SUBMISSION_STATUS_ERROR) { $this->seterrormessage($params->message); - $loggingrequestinfo = new logging_request_info(TURNITINSIM_ENDPOINT_UPLOAD_SUBMISSION, + $loggingrequestinfo = new plagiarism_turnitinsim_logging_request_info(TURNITINSIM_ENDPOINT_UPLOAD_SUBMISSION, "POST", null, 500, json_encode($params)); - $loggingrequest = new logging_request('Error while uploading the file'); + $loggingrequest = new plagiarism_turnitinsim_logging_request('Error while uploading the file'); $loggingrequest->set_submissionid($this->turnitinid); $loggingrequest->send_error_to_turnitin($loggingrequestinfo); } else { @@ -634,9 +634,9 @@ public function handle_submission_info_response($params) { $error = isset($params->error_code) ? $params->error_code : get_string('submissiondisplaystatus:unknown', 'plagiarism_turnitinsim'); $this->set_error_with_max_retry_attempts($error, TURNITINSIM_REPORT_GEN_MAX_ATTEMPTS); - $loggingrequestinfo = new logging_request_info(TURNITINSIM_ENDPOINT_GET_SUBMISSION_INFO, + $loggingrequestinfo = new plagiarism_turnitinsim_logging_request_info(TURNITINSIM_ENDPOINT_GET_SUBMISSION_INFO, "GET", null, 500, json_encode($params)); - $loggingrequest = new logging_request($error, $this->tsrequest); + $loggingrequest = new plagiarism_turnitinsim_logging_request($error, $this->tsrequest); $loggingrequest->set_submissionid($this->turnitinid); $loggingrequest->send_error_to_turnitin($loggingrequestinfo); } @@ -754,6 +754,7 @@ public function request_turnitin_report_generation($regenerateonduedate = false) if ($regenerateonduedate) { $this->settogenerate(0); + $this->setgenerationtime(time()); } else { $this->calculate_generation_time(true); } diff --git a/tests/classes/tslogging_request_test.php b/tests/classes/tslogging_request_test.php index c6e3ba6..209e296 100644 --- a/tests/classes/tslogging_request_test.php +++ b/tests/classes/tslogging_request_test.php @@ -61,7 +61,7 @@ public function test_send_error_to_turnitin_should_send_if_remote_logging_is_ena ->with(TURNITINSIM_ENDPOINT_LOGGING) ->willReturn(''); - $tsloggingrequest = new logging_request('Error', $tsrequest); + $tsloggingrequest = new plagiarism_turnitinsim_logging_request('Error', $tsrequest); $tsloggingrequest->send_error_to_turnitin(); } @@ -84,7 +84,7 @@ public function test_send_error_to_turnitin_should_send_if_remote_logging_is_dis ->method('send_request') ->willReturn(''); - $tsloggingrequest = new logging_request('Error', $tsrequest); + $tsloggingrequest = new plagiarism_turnitinsim_logging_request('Error', $tsrequest); $tsloggingrequest->send_error_to_turnitin(); } diff --git a/tests/classes/tssubmission_test.php b/tests/classes/tssubmission_test.php index 8095e6b..e603117 100644 --- a/tests/classes/tssubmission_test.php +++ b/tests/classes/tssubmission_test.php @@ -858,16 +858,13 @@ public function test_request_turnitin_report_generation_success_on_due_date() { $tssubmission->setstatus(TURNITINSIM_SUBMISSION_STATUS_UPLOADED); $tssubmission->settype(TURNITINSIM_SUBMISSION_TYPE_FILE); - $currenttime = time(); - $tssubmission->setgenerationtime($currenttime); - // Request report generation. $tssubmission->request_turnitin_report_generation(true); // Test that the submission status is uploaded. $this->assertEquals(TURNITINSIM_SUBMISSION_STATUS_REQUESTED, $tssubmission->getstatus()); $this->assertEquals(0, $tssubmission->gettogenerate()); - $this->assertEquals($currenttime, $tssubmission->getgenerationtime()); + $this->assertLessThanOrEqual(time(), $tssubmission->getgenerationtime()); } /** From a8fac2ea7fed932b98ef6dab5c03d2bc4e40b170 Mon Sep 17 00:00:00 2001 From: Grijesh Saini Date: Tue, 23 Jun 2020 16:43:49 +0530 Subject: [PATCH 32/48] INT-14488 - Addressed code checker warnings. --- classes/logging_request.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/classes/logging_request.class.php b/classes/logging_request.class.php index 38cd2eb..718f817 100644 --- a/classes/logging_request.class.php +++ b/classes/logging_request.class.php @@ -69,7 +69,8 @@ public function __construct($message = 'Error', plagiarism_turnitinsim_request $ * @param bool $sendsecrets The boolean value, if true send secrets as part of logs. */ public function send_error_to_turnitin(plagiarism_turnitinsim_logging_request_info $loggingrequestinfo = null, - plagiarism_turnitinsim_logging_request_event_info $loggingrequesteventinfo = null, $sendsecrets = false) { + plagiarism_turnitinsim_logging_request_event_info $loggingrequesteventinfo = null, + $sendsecrets = false) { if (!get_config('plagiarism_turnitinsim', 'turnitinenableremotelogging')) { return; From 6af7309f031ae3a703671efcd75ded27a5775dc1 Mon Sep 17 00:00:00 2001 From: Grijesh Saini Date: Tue, 23 Jun 2020 20:31:37 +0530 Subject: [PATCH 33/48] INT-14488 - Fixed headers for Logging request. --- classes/request.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/request.class.php b/classes/request.class.php index d9ae356..eeef2fd 100644 --- a/classes/request.class.php +++ b/classes/request.class.php @@ -115,7 +115,7 @@ public function send_request($endpoint, $requestbody, $method, $requesttype = 'g global $CFG; // Attach content type to headers if this is not a submission. - if ($requesttype == 'general') { + if ($requesttype == 'general' || $requesttype === 'logging') { if (!in_array('Content-Type: application/json', $this->headers)) { $this->headers[] = 'Content-Type: application/json'; } From bb8ca7fc305f3a0deade26b35b7c88468020acd5 Mon Sep 17 00:00:00 2001 From: David Winn Date: Wed, 24 Jun 2020 15:24:02 +0100 Subject: [PATCH 34/48] Fix for handling of deleted activities --- classes/submission.class.php | 2 +- classes/task.class.php | 14 +++++++++----- lang/en/plagiarism_turnitinsim.php | 3 ++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/classes/submission.class.php b/classes/submission.class.php index b679bad..3621d08 100644 --- a/classes/submission.class.php +++ b/classes/submission.class.php @@ -1398,7 +1398,7 @@ private function reset_retries() { * @param string $error Error code from Turnitin. * @param int $retryattempts Maximum retry attempts. */ - private function set_error_with_max_retry_attempts($error, $retryattempts) { + public function set_error_with_max_retry_attempts($error, $retryattempts) { $this->settiiattempts($retryattempts); $this->seterrormessage($error); $this->setstatus(TURNITINSIM_SUBMISSION_STATUS_ERROR); diff --git a/classes/task.class.php b/classes/task.class.php index 8d26f26..40f5f29 100644 --- a/classes/task.class.php +++ b/classes/task.class.php @@ -102,16 +102,20 @@ public function send_queued_submissions() { // Create each submission in Turnitin and upload submission. foreach ($submissions as $submission) { - // Skip if the course doesn't exist or the course is pending deletion. - if (!$DB->get_record('course_modules', array('id' => $submission->cm, 'deletioninprogress' => 0))) { - continue; - } - // Reset headers. $this->tsrequest->set_headers(); $tssubmission = new plagiarism_turnitinsim_submission($this->tsrequest, $submission->id); + // Skip if the course module doesn't exist or the course is pending deletion. + if (!$DB->get_record('course_modules', array('id' => $submission->cm, 'deletioninprogress' => 0))) { + $error = get_string('errorprocessingdeletedsubmission', 'plagiarism_turnitinsim'); + $tssubmission->set_error_with_max_retry_attempts($error, TURNITINSIM_REPORT_GEN_MAX_ATTEMPTS); + $tssubmission->update(); + + continue; + } + if ($tssubmission->getstatus() == TURNITINSIM_SUBMISSION_STATUS_QUEUED) { $tssubmission->create_submission_in_turnitin(); } diff --git a/lang/en/plagiarism_turnitinsim.php b/lang/en/plagiarism_turnitinsim.php index 05b59af..636d74c 100644 --- a/lang/en/plagiarism_turnitinsim.php +++ b/lang/en/plagiarism_turnitinsim.php @@ -193,4 +193,5 @@ $string['privacy:metadata:plagiarism_turnitinsim_client:submission_content'] = 'Please be aware that the content of a file/submission is sent to Turnitin for processing.'; $string['errorenabledfeatures'] = 'Could not get the list of enabled features.'; -$string['errorgettingsubmissioninfo'] = 'There was an error attempting to get the submission info.'; \ No newline at end of file +$string['errorgettingsubmissioninfo'] = 'There was an error attempting to get the submission info.'; +$string['errorprocessingdeletedsubmission'] = 'This submission belongs to a deleted assignment and cannot be processed.'; \ No newline at end of file From 696bfde501c9936f03ae2a582b73ae9d2fd9d709 Mon Sep 17 00:00:00 2001 From: Grijesh Saini Date: Fri, 26 Jun 2020 17:02:48 +0530 Subject: [PATCH 35/48] INT-13565 - Not showing Turnitin Plugin when disabled at admin level. --- lib.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib.php b/lib.php index 85b7b81..73923d6 100644 --- a/lib.php +++ b/lib.php @@ -60,6 +60,14 @@ public function get_form_elements_module($mform, $context, $modulename = "") { $location = ($context == context_system::instance()) ? 'defaults' : 'module'; + // Get whether plugin is enabled for this module. + $moduletiienabled = empty($modulename) ? "0" : get_config('plagiarism_turnitinsim', 'turnitinmodenabled'.substr($modulename, 4)); + + // Exit if Turnitin is not being used for this activity type and location is not default. + if ($location === 'module' && $moduletiienabled === "0") { + return; + } + $form = new plagiarism_turnitinsim_settings(); $form->add_settings_to_module($mform, $location, $modulename); From 2162dd92ebf8bbb76543079f407c55f51efa9ad8 Mon Sep 17 00:00:00 2001 From: Grijesh Saini Date: Mon, 29 Jun 2020 16:43:16 +0530 Subject: [PATCH 36/48] INT-134602 - Added tool tip for remote logging settings. --- classes/setup_form.class.php | 2 ++ lang/en/plagiarism_turnitinsim.php | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/classes/setup_form.class.php b/classes/setup_form.class.php index 1c3ef40..fbd6f8a 100644 --- a/classes/setup_form.class.php +++ b/classes/setup_form.class.php @@ -89,6 +89,8 @@ public function definition() { array(0, 1) ); + // Add tool tip. + $mform->addHelpButton('turnitinenableremotelogging', 'turnitinenableremotelogging', 'plagiarism_turnitinsim'); $mform->setDefault('turnitinenableremotelogging', 1); // Toggle Student Data Privacy. diff --git a/lang/en/plagiarism_turnitinsim.php b/lang/en/plagiarism_turnitinsim.php index 05b59af..49667f5 100644 --- a/lang/en/plagiarism_turnitinsim.php +++ b/lang/en/plagiarism_turnitinsim.php @@ -145,7 +145,8 @@ $string['turnitinsimprivate'] = 'Check against private content'; $string['turnitinconfig'] = 'Plugin configuration'; $string['turnitinenablelogging'] = 'Enable diagnostic mode'; -$string['turnitinenableremotelogging'] = 'Enable remote diagnostic mode'; +$string['turnitinenableremotelogging'] = 'Send logs to Turnitin'; +$string['turnitinenableremotelogging_help'] = 'Logs will automatically be sent to Turnitin for diagnostic purposes. No private data is transferred. We recommend this setting remains enabled so we can quickly provide support if needed. However, logs can still be found in your Moodle environment to manually send to Turnitin.'; $string['turnitinfeatures'] = 'Turnitin Integrity features'; $string['turnitinfeatures::header'] = 'Turnitin Integrity features'; $string['turnitinfeatures::moreinfo'] = 'For more information on the enabled features and packages available from Turnitin please see http://www.turnitin.com.'; From f12b0925671bf2c6ddf12c33107f21ecc5b28ce3 Mon Sep 17 00:00:00 2001 From: David Winn Date: Wed, 1 Jul 2020 10:47:58 +0100 Subject: [PATCH 37/48] Updating English help link --- classes/settings.class.php | 2 +- lang/en/plagiarism_turnitinsim.php | 3 ++- utilities/constants.php | 1 - 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/classes/settings.class.php b/classes/settings.class.php index b03a681..f530cfb 100644 --- a/classes/settings.class.php +++ b/classes/settings.class.php @@ -140,7 +140,7 @@ public function add_settings_to_module($mform, $context = 'module', $modulename // Show link to guides. $link = html_writer::link( - TURNITINSIM_HELP_LINK, + get_string('helplink', 'plagiarism_turnitinsim'), get_string('settingslearnmore', 'plagiarism_turnitinsim'), array('target' => '_blank') ); diff --git a/lang/en/plagiarism_turnitinsim.php b/lang/en/plagiarism_turnitinsim.php index 65e8e4e..6534682 100644 --- a/lang/en/plagiarism_turnitinsim.php +++ b/lang/en/plagiarism_turnitinsim.php @@ -195,4 +195,5 @@ $string['errorenabledfeatures'] = 'Could not get the list of enabled features.'; $string['errorgettingsubmissioninfo'] = 'There was an error attempting to get the submission info.'; -$string['errorprocessingdeletedsubmission'] = 'This submission belongs to a deleted assignment and cannot be processed.'; \ No newline at end of file +$string['errorprocessingdeletedsubmission'] = 'This submission belongs to a deleted assignment and cannot be processed.'; +$string['helplink'] = 'https://help.turnitin.com/integrity/administrator/moodle.htm#step-four'; \ No newline at end of file diff --git a/utilities/constants.php b/utilities/constants.php index e734a3f..b74ed6f 100644 --- a/utilities/constants.php +++ b/utilities/constants.php @@ -69,7 +69,6 @@ define('TURNITINSIM_ENDPOINT_LOGGING', '/remote-logging/api/log'); // URLs. -define('TURNITINSIM_HELP_LINK', 'https://help.turnitin.com/simcheck/integrations/moodle/moodle-home.htm'); define('TURNITINSIM_EULA', '/plagiarism/turnitinsim/eula.php?cmd=displayeula'); define('TURNITINSIM_CALLBACK_URL', $CFG->wwwroot.'/plagiarism/turnitinsim/callbacks.php'); From 0be50393018b9f40bfe8d66120d50c0041b977be Mon Sep 17 00:00:00 2001 From: David Winn Date: Wed, 1 Jul 2020 11:51:18 +0100 Subject: [PATCH 38/48] Adding help links for other languages --- classes/settings.class.php | 2 +- lang/da/plagiarism_turnitinsim.php | 28 +++++++++++++++++++++++++++ lang/de/plagiarism_turnitinsim.php | 28 +++++++++++++++++++++++++++ lang/en/plagiarism_turnitinsim.php | 2 +- lang/es_mx/plagiarism_turnitinsim.php | 28 +++++++++++++++++++++++++++ lang/fr/plagiarism_turnitinsim.php | 28 +++++++++++++++++++++++++++ lang/nl/plagiarism_turnitinsim.php | 28 +++++++++++++++++++++++++++ lang/no/plagiarism_turnitinsim.php | 28 +++++++++++++++++++++++++++ lang/pt_br/plagiarism_turnitinsim.php | 28 +++++++++++++++++++++++++++ lang/sv/plagiarism_turnitinsim.php | 28 +++++++++++++++++++++++++++ 10 files changed, 226 insertions(+), 2 deletions(-) create mode 100644 lang/da/plagiarism_turnitinsim.php create mode 100644 lang/de/plagiarism_turnitinsim.php create mode 100644 lang/es_mx/plagiarism_turnitinsim.php create mode 100644 lang/fr/plagiarism_turnitinsim.php create mode 100644 lang/nl/plagiarism_turnitinsim.php create mode 100644 lang/no/plagiarism_turnitinsim.php create mode 100644 lang/pt_br/plagiarism_turnitinsim.php create mode 100644 lang/sv/plagiarism_turnitinsim.php diff --git a/classes/settings.class.php b/classes/settings.class.php index f530cfb..f74bd0a 100644 --- a/classes/settings.class.php +++ b/classes/settings.class.php @@ -140,7 +140,7 @@ public function add_settings_to_module($mform, $context = 'module', $modulename // Show link to guides. $link = html_writer::link( - get_string('helplink', 'plagiarism_turnitinsim'), + get_string('help_link', 'plagiarism_turnitinsim'), get_string('settingslearnmore', 'plagiarism_turnitinsim'), array('target' => '_blank') ); diff --git a/lang/da/plagiarism_turnitinsim.php b/lang/da/plagiarism_turnitinsim.php new file mode 100644 index 0000000..71fedd7 --- /dev/null +++ b/lang/da/plagiarism_turnitinsim.php @@ -0,0 +1,28 @@ +. + +/** + * Strings for plagiarism_turnitinsim component, language: Danish. + * + * This file should only contain *_link strings as other strings are handling through AMOS. + * + * @package plagiarism_turnitinsim + * @copyright 2017 Turnitin + * @author David Winn + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +$string['help_link'] = 'https://help.turnitin.com/da/integrity/administrator/moodle.htm#step-four'; diff --git a/lang/de/plagiarism_turnitinsim.php b/lang/de/plagiarism_turnitinsim.php new file mode 100644 index 0000000..c727d12 --- /dev/null +++ b/lang/de/plagiarism_turnitinsim.php @@ -0,0 +1,28 @@ +. + +/** + * Strings for plagiarism_turnitinsim component, language: German. + * + * This file should only contain *_link strings as other strings are handling through AMOS. + * + * @package plagiarism_turnitinsim + * @copyright 2017 Turnitin + * @author David Winn + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +$string['help_link'] = 'https://help.turnitin.com/de/integrity/administratoren/verwenden-von-turnitin-mit-moodle.htm#step-four'; diff --git a/lang/en/plagiarism_turnitinsim.php b/lang/en/plagiarism_turnitinsim.php index 6534682..0f4f53e 100644 --- a/lang/en/plagiarism_turnitinsim.php +++ b/lang/en/plagiarism_turnitinsim.php @@ -196,4 +196,4 @@ $string['errorenabledfeatures'] = 'Could not get the list of enabled features.'; $string['errorgettingsubmissioninfo'] = 'There was an error attempting to get the submission info.'; $string['errorprocessingdeletedsubmission'] = 'This submission belongs to a deleted assignment and cannot be processed.'; -$string['helplink'] = 'https://help.turnitin.com/integrity/administrator/moodle.htm#step-four'; \ No newline at end of file +$string['help_link'] = 'https://help.turnitin.com/integrity/administrator/moodle.htm#step-four'; diff --git a/lang/es_mx/plagiarism_turnitinsim.php b/lang/es_mx/plagiarism_turnitinsim.php new file mode 100644 index 0000000..eccb08a --- /dev/null +++ b/lang/es_mx/plagiarism_turnitinsim.php @@ -0,0 +1,28 @@ +. + +/** + * Strings for plagiarism_turnitinsim component, language: Mexican Spanish. + * + * This file should only contain *_link strings as other strings are handling through AMOS. + * + * @package plagiarism_turnitinsim + * @copyright 2017 Turnitin + * @author David Winn + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +$string['help_link'] = 'https://help.turnitin.com/es/integrity/administrador/moodle.htm#step-four'; diff --git a/lang/fr/plagiarism_turnitinsim.php b/lang/fr/plagiarism_turnitinsim.php new file mode 100644 index 0000000..773725c --- /dev/null +++ b/lang/fr/plagiarism_turnitinsim.php @@ -0,0 +1,28 @@ +. + +/** + * Strings for plagiarism_turnitinsim component, language: French. + * + * This file should only contain *_link strings as other strings are handling through AMOS. + * + * @package plagiarism_turnitinsim + * @copyright 2017 Turnitin + * @author David Winn + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +$string['help_link'] = 'https://help.turnitin.com/fr/integrity/administrateur/moodle.htm#step-four'; diff --git a/lang/nl/plagiarism_turnitinsim.php b/lang/nl/plagiarism_turnitinsim.php new file mode 100644 index 0000000..d9bd54c --- /dev/null +++ b/lang/nl/plagiarism_turnitinsim.php @@ -0,0 +1,28 @@ +. + +/** + * Strings for plagiarism_turnitinsim component, language: Dutch. + * + * This file should only contain *_link strings as other strings are handling through AMOS. + * + * @package plagiarism_turnitinsim + * @copyright 2017 Turnitin + * @author David Winn + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +$string['help_link'] = 'https://help.turnitin.com/nl/integrity/beheerder/moodle.htm#step-four'; diff --git a/lang/no/plagiarism_turnitinsim.php b/lang/no/plagiarism_turnitinsim.php new file mode 100644 index 0000000..fe4f77f --- /dev/null +++ b/lang/no/plagiarism_turnitinsim.php @@ -0,0 +1,28 @@ +. + +/** + * Strings for plagiarism_turnitinsim component, language: Norwegian. + * + * This file should only contain *_link strings as other strings are handling through AMOS. + * + * @package plagiarism_turnitinsim + * @copyright 2017 Turnitin + * @author David Winn + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +$string['help_link'] = 'https://help.turnitin.com/nb/integrity/administrer/moodle.htm#step-four'; diff --git a/lang/pt_br/plagiarism_turnitinsim.php b/lang/pt_br/plagiarism_turnitinsim.php new file mode 100644 index 0000000..e203f76 --- /dev/null +++ b/lang/pt_br/plagiarism_turnitinsim.php @@ -0,0 +1,28 @@ +. + +/** + * Strings for plagiarism_turnitinsim component, language: Brazilian Portuguese. + * + * This file should only contain *_link strings as other strings are handling through AMOS. + * + * @package plagiarism_turnitinsim + * @copyright 2017 Turnitin + * @author David Winn + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +$string['help_link'] = 'https://help.turnitin.com/pt-br/integrity/administrador/moodle.htm#step-four'; diff --git a/lang/sv/plagiarism_turnitinsim.php b/lang/sv/plagiarism_turnitinsim.php new file mode 100644 index 0000000..270db51 --- /dev/null +++ b/lang/sv/plagiarism_turnitinsim.php @@ -0,0 +1,28 @@ +. + +/** + * Strings for plagiarism_turnitinsim component, language: Swedish. + * + * This file should only contain *_link strings as other strings are handling through AMOS. + * + * @package plagiarism_turnitinsim + * @copyright 2017 Turnitin + * @author David Winn + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +$string['help_link'] = 'https://help.turnitin.com/sv/integrity/administrator/moodle.htm#step-four'; From efaa26a7da9c9960fde9a885b52c549f77faebe3 Mon Sep 17 00:00:00 2001 From: David Winn Date: Wed, 1 Jul 2020 11:53:32 +0100 Subject: [PATCH 39/48] Correct year --- lang/da/plagiarism_turnitinsim.php | 2 +- lang/de/plagiarism_turnitinsim.php | 2 +- lang/en/plagiarism_turnitinsim.php | 2 +- lang/es_mx/plagiarism_turnitinsim.php | 2 +- lang/fr/plagiarism_turnitinsim.php | 2 +- lang/nl/plagiarism_turnitinsim.php | 2 +- lang/no/plagiarism_turnitinsim.php | 2 +- lang/pt_br/plagiarism_turnitinsim.php | 2 +- lang/sv/plagiarism_turnitinsim.php | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lang/da/plagiarism_turnitinsim.php b/lang/da/plagiarism_turnitinsim.php index 71fedd7..69cdff9 100644 --- a/lang/da/plagiarism_turnitinsim.php +++ b/lang/da/plagiarism_turnitinsim.php @@ -20,7 +20,7 @@ * This file should only contain *_link strings as other strings are handling through AMOS. * * @package plagiarism_turnitinsim - * @copyright 2017 Turnitin + * @copyright 2020 Turnitin * @author David Winn * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/lang/de/plagiarism_turnitinsim.php b/lang/de/plagiarism_turnitinsim.php index c727d12..49a6503 100644 --- a/lang/de/plagiarism_turnitinsim.php +++ b/lang/de/plagiarism_turnitinsim.php @@ -20,7 +20,7 @@ * This file should only contain *_link strings as other strings are handling through AMOS. * * @package plagiarism_turnitinsim - * @copyright 2017 Turnitin + * @copyright 2020 Turnitin * @author David Winn * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/lang/en/plagiarism_turnitinsim.php b/lang/en/plagiarism_turnitinsim.php index 0f4f53e..8de96b0 100644 --- a/lang/en/plagiarism_turnitinsim.php +++ b/lang/en/plagiarism_turnitinsim.php @@ -18,7 +18,7 @@ * Strings for plagiarism_turnitinsim component, language 'en' * * @package plagiarism_turnitinsim - * @copyright 2017 Turnitin + * @copyright 2020 Turnitin * @author John McGettrick * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/lang/es_mx/plagiarism_turnitinsim.php b/lang/es_mx/plagiarism_turnitinsim.php index eccb08a..2d888e8 100644 --- a/lang/es_mx/plagiarism_turnitinsim.php +++ b/lang/es_mx/plagiarism_turnitinsim.php @@ -20,7 +20,7 @@ * This file should only contain *_link strings as other strings are handling through AMOS. * * @package plagiarism_turnitinsim - * @copyright 2017 Turnitin + * @copyright 2020 Turnitin * @author David Winn * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/lang/fr/plagiarism_turnitinsim.php b/lang/fr/plagiarism_turnitinsim.php index 773725c..5c60025 100644 --- a/lang/fr/plagiarism_turnitinsim.php +++ b/lang/fr/plagiarism_turnitinsim.php @@ -20,7 +20,7 @@ * This file should only contain *_link strings as other strings are handling through AMOS. * * @package plagiarism_turnitinsim - * @copyright 2017 Turnitin + * @copyright 2020 Turnitin * @author David Winn * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/lang/nl/plagiarism_turnitinsim.php b/lang/nl/plagiarism_turnitinsim.php index d9bd54c..f445164 100644 --- a/lang/nl/plagiarism_turnitinsim.php +++ b/lang/nl/plagiarism_turnitinsim.php @@ -20,7 +20,7 @@ * This file should only contain *_link strings as other strings are handling through AMOS. * * @package plagiarism_turnitinsim - * @copyright 2017 Turnitin + * @copyright 2020 Turnitin * @author David Winn * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/lang/no/plagiarism_turnitinsim.php b/lang/no/plagiarism_turnitinsim.php index fe4f77f..e2bfe98 100644 --- a/lang/no/plagiarism_turnitinsim.php +++ b/lang/no/plagiarism_turnitinsim.php @@ -20,7 +20,7 @@ * This file should only contain *_link strings as other strings are handling through AMOS. * * @package plagiarism_turnitinsim - * @copyright 2017 Turnitin + * @copyright 2020 Turnitin * @author David Winn * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/lang/pt_br/plagiarism_turnitinsim.php b/lang/pt_br/plagiarism_turnitinsim.php index e203f76..965a22d 100644 --- a/lang/pt_br/plagiarism_turnitinsim.php +++ b/lang/pt_br/plagiarism_turnitinsim.php @@ -20,7 +20,7 @@ * This file should only contain *_link strings as other strings are handling through AMOS. * * @package plagiarism_turnitinsim - * @copyright 2017 Turnitin + * @copyright 2020 Turnitin * @author David Winn * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/lang/sv/plagiarism_turnitinsim.php b/lang/sv/plagiarism_turnitinsim.php index 270db51..63e5a4c 100644 --- a/lang/sv/plagiarism_turnitinsim.php +++ b/lang/sv/plagiarism_turnitinsim.php @@ -20,7 +20,7 @@ * This file should only contain *_link strings as other strings are handling through AMOS. * * @package plagiarism_turnitinsim - * @copyright 2017 Turnitin + * @copyright 2020 Turnitin * @author David Winn * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ From 4a30f8a778351d1781680e6c88c9b7ef6a04beb0 Mon Sep 17 00:00:00 2001 From: David Winn Date: Wed, 1 Jul 2020 19:57:15 +0100 Subject: [PATCH 40/48] Implementing 3.9 form handling methods --- lib.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib.php b/lib.php index 73923d6..08dbd51 100644 --- a/lib.php +++ b/lib.php @@ -47,6 +47,9 @@ class plagiarism_plugin_turnitinsim extends plagiarism_plugin { /** * Get the fields to be used in the form to configure each module's Turnitin settings. * + * TODO: This code needs to be moved for 4.3 as the method will be completely removed from core. + * See https://tracker.moodle.org/browse/MDL-67526 + * * @param object $mform - Moodle form * @param object $context - current context * @param string $modulename - Name of the module @@ -104,6 +107,9 @@ public function get_form_elements_module($mform, $context, $modulename = "") { /** * Save the data associated with the plugin from the module's mod_form. * + * TODO: This code needs to be moved for 4.3 as the method will be completely removed from core. + * See https://tracker.moodle.org/browse/MDL-67526 + * * @param object $data the form data to save * @throws dml_exception */ @@ -740,6 +746,30 @@ public static function plugin_enabled() { } } +/** + * Add the Turnitin settings form to an add/edit activity page + * + * @param moodleform $formwrapper Moodleform wrapper + * @param MoodleQuickForm $mform Moodle Mform that we want to add our code to. + */ +function plagiarism_turnitinsim_coursemodule_standard_elements($formwrapper, $mform) { + $context = context_course::instance($formwrapper->get_course()->id); + + (new plagiarism_plugin_turnitinsim())->get_form_elements_module($mform, $context); +} + +/** + * Handle saving data from the Turnitin settings form.. + * + * @param stdClass $data The form data. + * @param stdClass $course The course the call is made from. + */ +function plagiarism_turnitinsim_coursemodule_edit_post_actions($data, $course) { + (new plagiarism_plugin_turnitinsim())->save_form_elements($data); + + return $data; +} + /** * Override Moodle's mtrace function for methods shared with tasks. * From c8e3c268c40bbbf45544582b02d0d02bf2110f2f Mon Sep 17 00:00:00 2001 From: Grijesh Saini Date: Wed, 8 Jul 2020 18:40:37 +0530 Subject: [PATCH 41/48] INT-14635 - Learner will not see full matches and will not have permission to exclude matches. --- classes/submission.class.php | 14 +++---- tests/classes/tssubmission_test.php | 65 ++++++++++++++++++++++++++++- 2 files changed, 70 insertions(+), 9 deletions(-) diff --git a/classes/submission.class.php b/classes/submission.class.php index 3621d08..fa261df 100644 --- a/classes/submission.class.php +++ b/classes/submission.class.php @@ -920,7 +920,7 @@ public function create_report_viewer_permissions() { return array( 'may_view_submission_full_source' => (!empty($turnitinviewerviewfullsource)) ? true : false, - 'may_view_match_submission_info' => (!empty($turnitinviewermatchsubinfo)) ? true : false, + 'may_view_match_submission_info' => (!empty($turnitinviewermatchsubinfo)) && !$this->is_submission_anonymous() ? true : false, 'may_view_save_viewer_changes' => (!empty($turnitinviewersavechanges)) ? true : false ); } @@ -930,10 +930,11 @@ public function create_report_viewer_permissions() { * * These are true but may be configurable in the future. * + * @param $viewer_default_permission_set string The user role. * @return array * @throws dml_exception */ - public function create_similarity_overrides() { + public function create_similarity_overrides($viewer_default_permission_set) { $turnitinviewersavechanges = get_config('plagiarism_turnitinsim', 'turnitinviewersavechanges'); return array( @@ -942,7 +943,7 @@ public function create_similarity_overrides() { 'all_sources' => true ), "view_settings" => array( - "save_changes" => (!empty($turnitinviewersavechanges)) ? true : false + "save_changes" => (!empty($turnitinviewersavechanges) && $viewer_default_permission_set !== TURNITINSIM_ROLE_LEARNER) ? true : false ) ); } @@ -977,15 +978,14 @@ public function request_cv_launch_url() { // Send correct user role in request. if (has_capability('plagiarism/turnitinsim:viewfullreport', context_module::instance($this->getcm()))) { $request['viewer_default_permission_set'] = TURNITINSIM_ROLE_INSTRUCTOR; + // Override viewer permissions depending on admin options. + $request['viewer_permissions'] = $this->create_report_viewer_permissions(); } else { $request['viewer_default_permission_set'] = TURNITINSIM_ROLE_LEARNER; } - // Override viewer permissions depending on admin options. - $request['viewer_permissions'] = $this->create_report_viewer_permissions(); - // Add similarity overrides - all true for now but this may change in future. - $request['similarity'] = $this->create_similarity_overrides(); + $request['similarity'] = $this->create_similarity_overrides($request['viewer_default_permission_set']); // Make request to get Cloud Viewer URL. try { diff --git a/tests/classes/tssubmission_test.php b/tests/classes/tssubmission_test.php index e603117..174d357 100644 --- a/tests/classes/tssubmission_test.php +++ b/tests/classes/tssubmission_test.php @@ -1745,6 +1745,37 @@ public function test_viewer_permissions_false_if_not_enabled() { $this->assertEquals(false, $permissions['may_view_match_submission_info']); } + /** + * Test that the viewer permissions returned are true if enabled. + */ + public function test_viewer_permissions_may_view_match_info_false_if_anonymous() { + $this->resetAfterTest(); + + set_config('turnitinviewerviewfullsource', 1, 'plagiarism_turnitinsim'); + set_config('turnitinviewermatchsubinfo', 1, 'plagiarism_turnitinsim'); + + // Create assign module with blind marking on. + $record = new stdClass(); + $record->course = $this->course; + $record->blindmarking = 1; + + $module = $this->getDataGenerator()->create_module('assign', $record); + + // Get course module data. + $cm = get_coursemodule_from_instance('assign', $module->id); + // Create submission object. + $tssubmission = new plagiarism_turnitinsim_submission(); + $tssubmission->setcm($cm->id); + $tssubmission->setuserid($this->student1->id); + + + // Verify that viewer permissions are true as the config values are set to true. + $permissions = $tssubmission->create_report_viewer_permissions(); + $this->assertEquals(true, $tssubmission->is_submission_anonymous()); + $this->assertEquals(true, $permissions['may_view_submission_full_source']); + $this->assertEquals(false, $permissions['may_view_match_submission_info']); + } + /** * Test that the similarity overrides are true when configured as such. */ @@ -1766,7 +1797,7 @@ public function test_similarity_overrides_are_true() { $tssubmission->setcm($cm->id); // Verify that viewer permissions are true as the config values are set to true. - $overrides = $tssubmission->create_similarity_overrides(); + $overrides = $tssubmission->create_similarity_overrides(TURNITINSIM_ROLE_INSTRUCTOR); $this->assertTrue($overrides['modes']['match_overview']); $this->assertTrue($overrides['modes']['all_sources']); $this->assertTrue($overrides['view_settings']['save_changes']); @@ -1793,7 +1824,37 @@ public function test_similarity_overrides_are_false() { $tssubmission->setcm($cm->id); // Verify that viewer permissions are true as the config values are set to true. - $overrides = $tssubmission->create_similarity_overrides(); + $overrides = $tssubmission->create_similarity_overrides(TURNITINSIM_ROLE_INSTRUCTOR); + $this->assertTrue($overrides['modes']['match_overview']); + $this->assertTrue($overrides['modes']['all_sources']); + $this->assertFalse($overrides['view_settings']['save_changes']); + } + + + /** + * Test that the similarity overrides are true when configured as such. + */ + public function test_similarity_overrides_save_change_is_false_when_role_is_learner() { + $this->resetAfterTest(); + + set_config('turnitinviewersavechanges', 1, 'plagiarism_turnitinsim'); + + // Create assign module. + $record = new stdClass(); + $record->course = $this->course; + $module = $this->getDataGenerator()->create_module('assign', $record); + + // Get course module data. + $cm = get_coursemodule_from_instance('assign', $module->id); + + // Create submission object. + $tssubmission = new plagiarism_turnitinsim_submission(); + $tssubmission->setcm($cm->id); + + // Verify that viewer permissions are true as the config values are set to true. + $overrides = $tssubmission->create_similarity_overrides(TURNITINSIM_ROLE_LEARNER); + $this->assertTrue($overrides['modes']['match_overview']); + $this->assertTrue($overrides['modes']['all_sources']); $this->assertFalse($overrides['view_settings']['save_changes']); } From 080ff3367aa4866a33f36fcc861ead04dfe22101 Mon Sep 17 00:00:00 2001 From: Grijesh Saini Date: Wed, 8 Jul 2020 19:19:53 +0530 Subject: [PATCH 42/48] INT-14635 - Fixed code check warnings. --- classes/submission.class.php | 10 ++++++---- lib.php | 3 ++- tests/classes/tssubmission_test.php | 1 - 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/classes/submission.class.php b/classes/submission.class.php index fa261df..e8eadcf 100644 --- a/classes/submission.class.php +++ b/classes/submission.class.php @@ -920,7 +920,8 @@ public function create_report_viewer_permissions() { return array( 'may_view_submission_full_source' => (!empty($turnitinviewerviewfullsource)) ? true : false, - 'may_view_match_submission_info' => (!empty($turnitinviewermatchsubinfo)) && !$this->is_submission_anonymous() ? true : false, + 'may_view_match_submission_info' => (!empty($turnitinviewermatchsubinfo)) && + !$this->is_submission_anonymous() ? true : false, 'may_view_save_viewer_changes' => (!empty($turnitinviewersavechanges)) ? true : false ); } @@ -930,11 +931,11 @@ public function create_report_viewer_permissions() { * * These are true but may be configurable in the future. * - * @param $viewer_default_permission_set string The user role. + * @param string $viewerdefaultpermissionset The user role. * @return array * @throws dml_exception */ - public function create_similarity_overrides($viewer_default_permission_set) { + public function create_similarity_overrides($viewerdefaultpermissionset) { $turnitinviewersavechanges = get_config('plagiarism_turnitinsim', 'turnitinviewersavechanges'); return array( @@ -943,7 +944,8 @@ public function create_similarity_overrides($viewer_default_permission_set) { 'all_sources' => true ), "view_settings" => array( - "save_changes" => (!empty($turnitinviewersavechanges) && $viewer_default_permission_set !== TURNITINSIM_ROLE_LEARNER) ? true : false + "save_changes" => (!empty($turnitinviewersavechanges) && + $viewerdefaultpermissionset !== TURNITINSIM_ROLE_LEARNER) ? true : false ) ); } diff --git a/lib.php b/lib.php index 08dbd51..8b649e5 100644 --- a/lib.php +++ b/lib.php @@ -64,7 +64,8 @@ public function get_form_elements_module($mform, $context, $modulename = "") { $location = ($context == context_system::instance()) ? 'defaults' : 'module'; // Get whether plugin is enabled for this module. - $moduletiienabled = empty($modulename) ? "0" : get_config('plagiarism_turnitinsim', 'turnitinmodenabled'.substr($modulename, 4)); + $moduletiienabled = empty($modulename) ? "0" : get_config('plagiarism_turnitinsim', + 'turnitinmodenabled'.substr($modulename, 4)); // Exit if Turnitin is not being used for this activity type and location is not default. if ($location === 'module' && $moduletiienabled === "0") { diff --git a/tests/classes/tssubmission_test.php b/tests/classes/tssubmission_test.php index 174d357..7d71208 100644 --- a/tests/classes/tssubmission_test.php +++ b/tests/classes/tssubmission_test.php @@ -1768,7 +1768,6 @@ public function test_viewer_permissions_may_view_match_info_false_if_anonymous() $tssubmission->setcm($cm->id); $tssubmission->setuserid($this->student1->id); - // Verify that viewer permissions are true as the config values are set to true. $permissions = $tssubmission->create_report_viewer_permissions(); $this->assertEquals(true, $tssubmission->is_submission_anonymous()); From c1136279ba2fad11105f7fb5611afdd4a38072e2 Mon Sep 17 00:00:00 2001 From: David Winn Date: Mon, 20 Jul 2020 14:54:15 +0100 Subject: [PATCH 43/48] Implementing fix for assignment settings to prevent duplicate settings and correctly show settings --- lib.php | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lib.php b/lib.php index 8b649e5..8e14fd5 100644 --- a/lib.php +++ b/lib.php @@ -53,11 +53,18 @@ class plagiarism_plugin_turnitinsim extends plagiarism_plugin { * @param object $mform - Moodle form * @param object $context - current context * @param string $modulename - Name of the module + * @param bool $moodle39plus - True if being called from Moodle 3.9+ * @return void of settings fields. * @throws coding_exception * @throws dml_exception */ - public function get_form_elements_module($mform, $context, $modulename = "") { + public function get_form_elements_module($mform, $context, $modulename = "", $moodle39plus = false) { + global $CFG; + + // Return in 3.9+ unless being called by the new 3.9+ method - to avoid showing the settings twice. + if ($CFG->branch >= 39 && !$moodle39plus) { + return; + } $cmid = optional_param('update', 0, PARAM_INT); @@ -754,9 +761,21 @@ public static function plugin_enabled() { * @param MoodleQuickForm $mform Moodle Mform that we want to add our code to. */ function plagiarism_turnitinsim_coursemodule_standard_elements($formwrapper, $mform) { + global $CFG; + + // Continue using the 3.8 method if we detect an older version of Moodle. + if ($CFG->branch < 39) { + return; + } + $context = context_course::instance($formwrapper->get_course()->id); - (new plagiarism_plugin_turnitinsim())->get_form_elements_module($mform, $context); + (new plagiarism_plugin_turnitinsim())->get_form_elements_module( + $mform, + $context, + isset($formwrapper->get_current()->modulename) ? 'mod_'.$formwrapper->get_current()->modulename : '', + true + ); } /** From 0d0cd5e6cd0bc49a4cabde6e36f0c052b4a1d28e Mon Sep 17 00:00:00 2001 From: David Winn Date: Mon, 20 Jul 2020 15:10:07 +0100 Subject: [PATCH 44/48] Refactoring to do this better --- lib.php | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/lib.php b/lib.php index 8e14fd5..60ee186 100644 --- a/lib.php +++ b/lib.php @@ -53,16 +53,15 @@ class plagiarism_plugin_turnitinsim extends plagiarism_plugin { * @param object $mform - Moodle form * @param object $context - current context * @param string $modulename - Name of the module - * @param bool $moodle39plus - True if being called from Moodle 3.9+ * @return void of settings fields. * @throws coding_exception * @throws dml_exception */ - public function get_form_elements_module($mform, $context, $modulename = "", $moodle39plus = false) { - global $CFG; - - // Return in 3.9+ unless being called by the new 3.9+ method - to avoid showing the settings twice. - if ($CFG->branch >= 39 && !$moodle39plus) { + public function get_form_elements_module($mform, $context, $modulename = "") { + // This is a bit of a hack and untidy way to ensure the form elements aren't displayed twice. + // TODO: Remove once this method is removed. + static $hassettings; + if ($hassettings) { return; } @@ -110,6 +109,8 @@ public function get_form_elements_module($mform, $context, $modulename = "", $mo $mform->setDefault($element, $value); } } + // TODO: Remove once this method is removed. + $hassettings = true; } /** @@ -761,20 +762,12 @@ public static function plugin_enabled() { * @param MoodleQuickForm $mform Moodle Mform that we want to add our code to. */ function plagiarism_turnitinsim_coursemodule_standard_elements($formwrapper, $mform) { - global $CFG; - - // Continue using the 3.8 method if we detect an older version of Moodle. - if ($CFG->branch < 39) { - return; - } - $context = context_course::instance($formwrapper->get_course()->id); (new plagiarism_plugin_turnitinsim())->get_form_elements_module( $mform, $context, - isset($formwrapper->get_current()->modulename) ? 'mod_'.$formwrapper->get_current()->modulename : '', - true + isset($formwrapper->get_current()->modulename) ? 'mod_'.$formwrapper->get_current()->modulename : '' ); } From e25aba5b681f9bf03ff11b0e75bf9124953dc89f Mon Sep 17 00:00:00 2001 From: David Winn Date: Tue, 21 Jul 2020 15:09:37 +0100 Subject: [PATCH 45/48] Release v2020072101 --- CHANGELOG.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ db/upgrade.php | 2 +- version.php | 4 ++-- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8778b0..5ff067f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,48 @@ +### Date: 2020-July-21 +### Release: v2020072101 + +#### :zap: What's new + +--- + +#### We now support Moodle 3.9 + +You can find out more about Moodle 3.9 via Moodle's [release notes](https://docs.moodle.org/dev/Moodle_3.9_release_notes). + +#### EULA update notifications will no longer automatically email users + +When we make an update to our EULA, we send a Moodle message to users so they can read any changes and make sure they are comfortable with them before continuing to use Turnitin. Moodle messages had defaulted to also send an email when these messages were received. After user feedback, we’ve changed how the Turnitin Integrity Plugin interacts with the Moodle Message API to default this setting to Off and making emails now opt-in. + +If you’d like your users to continue getting an email when these changes happen, navigate to Site administration > Messaging > Notification settings and enable the setting for your integration. + +This change will only apply to users created after this plugin update. + +#### Multi-task with submissions from the same student + +Students in a Moodle assignment can upload up to 20 files to the same assignment. As a part of your grading workflow, you may want to view some of these documents side-by-side to compare them directly. We’ve enabled this option so that you’ll be able to open multiple windows with submissions from the same student at the same time. + +#### :wrench: Fixes and enhancements + +#### Collusion check on Due Date + +A bug had prevented some collusion checks from running on the due date. Collusion checks will now work as intended and a new report is generated for all submissions in a Moodle assignment once the due date has passed. This will only apply when the setting to regenerate on due date is turned on. + +#### Submit on behalf of a student when they have rejected the Turnitin EULA + +When a student rejects the Turnitin EULA, we provide a message saying the EULA has not been accepted rather than process the file for Similarity and return a 451 error. However, when an instructor then tried to submit a file on behalf of that student using the resubmit link, the file would be queued for processing but then return a 451 error. + +We recommend checking your institution's privacy policies and determine the copyright status of the student’s file first, but instructors will now be able to resubmit on behalf of a student when they have rejected the EULA. + +#### More reliable API connection check + +As a part of the plugin configuration, we run a quick check of the details your provide to make sure they connection correctly to Turnitin. We’ve improved this checker to ensure that it is constantly reliable and accurately shows your connection status. + +#### Turn off Turnitin for Forums and Workshops at the global level + +When disabled on the global configuration page, plagiarism/turnitincheck/settings.php it had been possible to still add Turnitin to a Workshop or Forum. We’ve now made sure this setting will update the permission settings when adding one of these settings so you can turn off Turnitin when you need to. + +--- + ### Date: 2020-April-22 ### Release: v2020042201 diff --git a/db/upgrade.php b/db/upgrade.php index d42a85a..6845846 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -290,5 +290,5 @@ function xmldb_plagiarism_turnitinsim_upgrade($oldversion) { upgrade_plugin_savepoint(true, 2020061202, 'plagiarism', 'turnitinsim'); } - return true; + return true; } \ No newline at end of file diff --git a/version.php b/version.php index 2edf066..56efc12 100644 --- a/version.php +++ b/version.php @@ -25,8 +25,8 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2020061202; -$plugin->release = "v1.1"; +$plugin->version = 2020072101; +$plugin->release = "v1.2"; $plugin->requires = 2017051500; $plugin->component = 'plagiarism_turnitinsim'; $plugin->maturity = MATURITY_STABLE; From ba69fc495dc61961748d3b927f7aac68e2da2796 Mon Sep 17 00:00:00 2001 From: David Winn Date: Tue, 21 Jul 2020 15:12:10 +0100 Subject: [PATCH 46/48] Adding line --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ff067f..c8e92a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,8 @@ Students in a Moodle assignment can upload up to 20 files to the same assignment #### :wrench: Fixes and enhancements +--- + #### Collusion check on Due Date A bug had prevented some collusion checks from running on the due date. Collusion checks will now work as intended and a new report is generated for all submissions in a Moodle assignment once the due date has passed. This will only apply when the setting to regenerate on due date is turned on. From 9f0d85c7813b82b35ea173c456327bbc6cb27204 Mon Sep 17 00:00:00 2001 From: David Winn Date: Tue, 21 Jul 2020 15:22:37 +0100 Subject: [PATCH 47/48] Release note fix --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8e92a7..a3c1902 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,7 +33,7 @@ A bug had prevented some collusion checks from running on the due date. Collusio When a student rejects the Turnitin EULA, we provide a message saying the EULA has not been accepted rather than process the file for Similarity and return a 451 error. However, when an instructor then tried to submit a file on behalf of that student using the resubmit link, the file would be queued for processing but then return a 451 error. -We recommend checking your institution's privacy policies and determine the copyright status of the student’s file first, but instructors will now be able to resubmit on behalf of a student when they have rejected the EULA. +Now, when a student rejects the EULA, no option to resubmit will be shown. #### More reliable API connection check From 89fabe018040bdb6249a85056140e288e93b704e Mon Sep 17 00:00:00 2001 From: David Winn Date: Tue, 21 Jul 2020 15:29:36 +0100 Subject: [PATCH 48/48] Release note update --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3c1902..36dc583 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,7 @@ Students in a Moodle assignment can upload up to 20 files to the same assignment A bug had prevented some collusion checks from running on the due date. Collusion checks will now work as intended and a new report is generated for all submissions in a Moodle assignment once the due date has passed. This will only apply when the setting to regenerate on due date is turned on. -#### Submit on behalf of a student when they have rejected the Turnitin EULA +#### Resubmit link removed when a student rejects the Turnitin EULA When a student rejects the Turnitin EULA, we provide a message saying the EULA has not been accepted rather than process the file for Similarity and return a 451 error. However, when an instructor then tried to submit a file on behalf of that student using the resubmit link, the file would be queued for processing but then return a 451 error.