From 78adf6f63aae69334d917782152eaa78795369de Mon Sep 17 00:00:00 2001 From: Dmitrii Metelkin Date: Thu, 27 Feb 2020 12:04:37 +1100 Subject: [PATCH] MDL-67850 quizaccess: remove the old quizaccess_safebrowser Co-authored-by: Nicholas Hoobin Co-authored-by: Andrew Madden --- admin/settings/development.php | 1 - lang/en/admin.php | 2 - lib/classes/plugin_manager.php | 2 +- lib/db/upgrade.php | 8 ++ lib/upgrade.txt | 2 + .../safebrowser/classes/privacy/provider.php | 46 ---------- .../lang/en/quizaccess_safebrowser.php | 34 ------- mod/quiz/accessrule/safebrowser/rule.php | 92 ------------------- .../safebrowser/tests/rule_test.php | 63 ------------- mod/quiz/accessrule/safebrowser/version.php | 32 ------- .../backup/moodle2/restore_quiz_stepslib.php | 46 +++++++++- version.php | 2 +- 12 files changed, 56 insertions(+), 274 deletions(-) delete mode 100644 mod/quiz/accessrule/safebrowser/classes/privacy/provider.php delete mode 100644 mod/quiz/accessrule/safebrowser/lang/en/quizaccess_safebrowser.php delete mode 100644 mod/quiz/accessrule/safebrowser/rule.php delete mode 100644 mod/quiz/accessrule/safebrowser/tests/rule_test.php delete mode 100644 mod/quiz/accessrule/safebrowser/version.php diff --git a/admin/settings/development.php b/admin/settings/development.php index f8a5ceb0792..46206fcc8f8 100644 --- a/admin/settings/development.php +++ b/admin/settings/development.php @@ -10,7 +10,6 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page $temp = new admin_settingpage('experimentalsettings', new lang_string('experimentalsettings', 'admin')); //TODO: Re-enable cc-import once re-implemented in 2.0.x //$temp->add(new admin_setting_configcheckbox('enableimsccimport', new lang_string('enable_cc_import', 'imscc'), new lang_string('enable_cc_import_description', 'imscc'), 0)); - $temp->add(new admin_setting_configcheckbox('enablesafebrowserintegration', new lang_string('enablesafebrowserintegration', 'admin'), new lang_string('configenablesafebrowserintegration', 'admin'), 0)); $temp->add(new admin_setting_configcheckbox('dndallowtextandlinks', new lang_string('dndallowtextandlinks', 'admin'), new lang_string('configdndallowtextandlinks', 'admin'), 0)); diff --git a/lang/en/admin.php b/lang/en/admin.php index b736c9b9dde..e86452b9729 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -236,7 +236,6 @@ $string['configenablemobilewebservice'] = 'Enable mobile service for the officia $string['configenablerssfeeds'] = 'If enabled, RSS feeds are generated by various features across the site, such as blogs, forums, database activities and glossaries. Note that RSS feeds also need to be enabled for the particular activity modules.'; $string['configenablerssfeedsdisabled'] = 'It is not available because RSS feeds are disabled in all the Site. To enable them, go to the Variables settings under Admin Configuration.'; $string['configenablerssfeedsdisabled2'] = 'RSS feeds are currently disabled at site level. They may be enabled in Advanced features in the Site administration.'; -$string['configenablesafebrowserintegration'] = 'This adds the choice \'Require Safe Exam Browser\' to the \'Browser security\' field on the quiz settings form. See https://www.safeexambrowser.org/ for more information.'; $string['configenablestats'] = 'If you choose \'yes\' here, Moodle\'s cronjob will process the logs and gather some statistics. Depending on the amount of traffic on your site, this can take awhile. If you enable this, you will be able to see some interesting graphs and statistics about each of your courses, or on a sitewide basis.'; $string['configenabletrusttext'] = 'By default Moodle will always thoroughly clean text that comes from users to remove any possible bad scripts, media etc that could be a security risk. The Trusted Content system is a way of giving particular users that you trust the ability to include these advanced features in their content without interference. To enable this system, you need to first enable this setting, and then grant the Trusted Content permission to a specific Moodle role. Texts created or uploaded by such users will be marked as trusted and will not be cleaned before display.'; $string['configenablewebservices'] = 'Web services enable other systems, such as the Moodle app, to log in to the site and perform operations. For extra security, the setting should be disabled if you are not using the app, or an external tool/service that requires integration via web services.'; @@ -545,7 +544,6 @@ $string['enablemoodlenet'] = 'Enable integration with MoodleNet instances'; $string['enablemoodlenet_desc'] = 'If enabled, and provided the MoodleNet plugin is installed, users can import content from MoodleNet into this site.'; $string['enablerecordcache'] = 'Enable record cache'; $string['enablerssfeeds'] = 'Enable RSS feeds'; -$string['enablesafebrowserintegration'] = 'Enable Safe Exam Browser integration'; $string['enablesearchareas'] = 'Enable search areas'; $string['enablestats'] = 'Enable statistics'; $string['enabletrusttext'] = 'Enable trusted content'; diff --git a/lib/classes/plugin_manager.php b/lib/classes/plugin_manager.php index 61536ec87ea..962bc3e933b 100644 --- a/lib/classes/plugin_manager.php +++ b/lib/classes/plugin_manager.php @@ -1960,7 +1960,7 @@ class core_plugin_manager { 'quizaccess' => array( 'delaybetweenattempts', 'ipaddress', 'numattempts', 'offlineattempts', 'openclosedate', - 'password', 'safebrowser', 'securewindow', 'timelimit' + 'password', 'seb', 'securewindow', 'timelimit' ), 'report' => array( diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index f71d4d488e8..0b5f9e4a4c2 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -2306,5 +2306,13 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2020041700.01); } + if ($oldversion < 2020042800.01) { + // Delete obsolete config value. + unset_config('enablesafebrowserintegration'); + // Clean up config of the old plugin. + unset_all_config_for_plugin('quizaccess_safebrowser'); + + upgrade_main_savepoint(true, 2020042800.01); + } return true; } diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 158eaac8830..eb04ddcbad5 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -2,6 +2,8 @@ This files describes API changes in core libraries and APIs, information provided here is intended especially for developers. === 3.9 === +* Old Safe Exam Browser quiz access rule (quizaccess_safebrowser) replaced by new Safe Exam Browser access rule (quizaccess_seb). + Experimental setting enablesafebrowserintegration was deleted. * New CFPropertyList library has been added to Moodle core in /lib/plist. * behat_data_generators::the_following_exist() has been removed, please use behat_data_generators::the_following_entities_exist() instead. See MDL-67691 for more info. diff --git a/mod/quiz/accessrule/safebrowser/classes/privacy/provider.php b/mod/quiz/accessrule/safebrowser/classes/privacy/provider.php deleted file mode 100644 index 75e91fa168f..00000000000 --- a/mod/quiz/accessrule/safebrowser/classes/privacy/provider.php +++ /dev/null @@ -1,46 +0,0 @@ -. - -/** - * Privacy Subsystem implementation for quizaccess_safebrowser. - * - * @package quizaccess_safebrowser - * @copyright 2018 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -namespace quizaccess_safebrowser\privacy; - -defined('MOODLE_INTERNAL') || die(); - -/** - * Privacy Subsystem for quizaccess_safebrowser implementing null_provider. - * - * @copyright 2018 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class provider implements \core_privacy\local\metadata\null_provider { - - /** - * Get the language string identifier with the component's language - * file to explain why this plugin stores no data. - * - * @return string - */ - public static function get_reason() : string { - return 'privacy:metadata'; - } -} diff --git a/mod/quiz/accessrule/safebrowser/lang/en/quizaccess_safebrowser.php b/mod/quiz/accessrule/safebrowser/lang/en/quizaccess_safebrowser.php deleted file mode 100644 index f92976b22c5..00000000000 --- a/mod/quiz/accessrule/safebrowser/lang/en/quizaccess_safebrowser.php +++ /dev/null @@ -1,34 +0,0 @@ -. - -/** - * Strings for the quizaccess_plagiarismcheckbox plugin. - * - * @package quizaccess - * @subpackage plagiarismcheckbox - * @copyright 2011 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - - -defined('MOODLE_INTERNAL') || die(); - - -$string['pluginname'] = 'Safe Exam Browser quiz access rule'; -$string['privacy:metadata'] = 'The Safe Exam Browser quiz access rule plugin does not store any personal data.'; -$string['requiresafeexambrowser'] = 'Require the use of Safe Exam Browser'; -$string['safebrowsererror'] = 'This quiz has been set up so that it may only be attempted using the Safe Exam Browser. You cannot attempt it from this web browser.'; -$string['safebrowsernotice'] = 'This quiz has been configured so that students may only attempt it using the Safe Exam Browser.'; diff --git a/mod/quiz/accessrule/safebrowser/rule.php b/mod/quiz/accessrule/safebrowser/rule.php deleted file mode 100644 index 763acdc0286..00000000000 --- a/mod/quiz/accessrule/safebrowser/rule.php +++ /dev/null @@ -1,92 +0,0 @@ -. - -/** - * Implementaton of the quizaccess_safebrowser plugin. - * - * @package quizaccess - * @subpackage safebrowser - * @copyright 2011 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - - -defined('MOODLE_INTERNAL') || die(); - -require_once($CFG->dirroot . '/mod/quiz/accessrule/accessrulebase.php'); - - -/** - * A rule representing the safe browser check. - * - * @copyright 2009 Oliver Rahs - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class quizaccess_safebrowser extends quiz_access_rule_base { - - public static function make(quiz $quizobj, $timenow, $canignoretimelimits) { - - if ($quizobj->get_quiz()->browsersecurity !== 'safebrowser') { - return null; - } - - return new self($quizobj, $timenow); - } - - public function prevent_access() { - if (!$this->check_safe_browser()) { - return get_string('safebrowsererror', 'quizaccess_safebrowser'); - } else { - return false; - } - } - - public function description() { - return get_string('safebrowsernotice', 'quizaccess_safebrowser'); - } - - public function setup_attempt_page($page) { - $page->set_title($this->quizobj->get_course()->shortname . ': ' . $page->title); - $page->set_cacheable(false); - $page->set_popup_notification_allowed(false); // Prevent message notifications. - $page->set_heading($page->title); - $page->set_pagelayout('secure'); - } - - /** - * Checks if browser is safe browser - * - * @return true, if browser is safe browser else false - */ - public function check_safe_browser() { - return strpos($_SERVER['HTTP_USER_AGENT'], 'SEB') !== false; - } - - /** - * @return array key => lang string any choices to add to the quiz Browser - * security settings menu. - */ - public static function get_browser_security_choices() { - global $CFG; - - if (empty($CFG->enablesafebrowserintegration)) { - return array(); - } - - return array('safebrowser' => - get_string('requiresafeexambrowser', 'quizaccess_safebrowser')); - } -} diff --git a/mod/quiz/accessrule/safebrowser/tests/rule_test.php b/mod/quiz/accessrule/safebrowser/tests/rule_test.php deleted file mode 100644 index 09f1d570018..00000000000 --- a/mod/quiz/accessrule/safebrowser/tests/rule_test.php +++ /dev/null @@ -1,63 +0,0 @@ -. - -/** - * Unit tests for the quizaccess_safebrowser plugin. - * - * @package quizaccess - * @subpackage safebrowser - * @category phpunit - * @copyright 2008 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - - -defined('MOODLE_INTERNAL') || die(); - -global $CFG; -require_once($CFG->dirroot . '/mod/quiz/accessrule/safebrowser/rule.php'); - - -/** - * Unit tests for the quizaccess_safebrowser plugin. - * - * @copyright 2008 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class quizaccess_safebrowser_testcase extends basic_testcase { - // Nothing very testable in this class, just test that it obeys the general access rule contact. - public function test_safebrowser_access_rule() { - $quiz = new stdClass(); - $quiz->browsersecurity = 'safebrowser'; - $cm = new stdClass(); - $cm->id = 0; - $quizobj = new quiz($quiz, $cm, null); - $rule = new quizaccess_safebrowser($quizobj, 0); - $attempt = new stdClass(); - - // This next test assumes the unit tests are not being run using Safe Exam Browser! - $_SERVER['HTTP_USER_AGENT'] = 'unknonw browser'; - $this->assertEquals(get_string('safebrowsererror', 'quizaccess_safebrowser'), - $rule->prevent_access()); - - $this->assertEquals(get_string('safebrowsernotice', 'quizaccess_safebrowser'), - $rule->description()); - $this->assertFalse($rule->prevent_new_attempt(0, $attempt)); - $this->assertFalse($rule->is_finished(0, $attempt)); - $this->assertFalse($rule->end_time($attempt)); - $this->assertFalse($rule->time_left_display($attempt, 0)); - } -} diff --git a/mod/quiz/accessrule/safebrowser/version.php b/mod/quiz/accessrule/safebrowser/version.php deleted file mode 100644 index 325ce3dcdd1..00000000000 --- a/mod/quiz/accessrule/safebrowser/version.php +++ /dev/null @@ -1,32 +0,0 @@ -. - -/** - * Version information for the quizaccess_safebrowser plugin. - * - * @package quizaccess - * @subpackage safebrowser - * @copyright 2011 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - - -defined('MOODLE_INTERNAL') || die(); - - -$plugin->version = 2019111800; -$plugin->requires = 2019111200; -$plugin->component = 'quizaccess_safebrowser'; diff --git a/mod/quiz/backup/moodle2/restore_quiz_stepslib.php b/mod/quiz/backup/moodle2/restore_quiz_stepslib.php index aafaa3a6adb..6bdb81376ff 100644 --- a/mod/quiz/backup/moodle2/restore_quiz_stepslib.php +++ b/mod/quiz/backup/moodle2/restore_quiz_stepslib.php @@ -97,7 +97,7 @@ class restore_quiz_activity_structure_step extends restore_questions_activity_st } protected function process_quiz($data) { - global $CFG, $DB; + global $CFG, $DB, $USER; $data = (object)$data; $oldid = $data->id; @@ -231,11 +231,17 @@ class restore_quiz_activity_structure_step extends restore_questions_activity_st } else if ($data->popup == 1) { $data->browsersecurity = 'securewindow'; } else if ($data->popup == 2) { - $data->browsersecurity = 'safebrowser'; + // Since 3.9 quizaccess_safebrowser replaced with a new quizaccess_seb. + $data->browsersecurity = '-'; + $addsebrule = true; } else { $data->preferredbehaviour = '-'; } unset($data->popup); + } else if ($data->browsersecurity == 'safebrowser') { + // Since 3.9 quizaccess_safebrowser replaced with a new quizaccess_seb. + $data->browsersecurity = '-'; + $addsebrule = true; } if (!isset($data->overduehandling)) { @@ -250,6 +256,42 @@ class restore_quiz_activity_structure_step extends restore_questions_activity_st $newitemid = $DB->insert_record('quiz', $data); // Immediately after inserting "activity" record, call this. $this->apply_activity_instance($newitemid); + + // Process Safe Exam Browser settings for backups taken in Moodle < 3.9. + if (!empty($addsebrule)) { + $sebsettings = new stdClass(); + + $sebsettings->quizid = $newitemid; + $sebsettings->cmid = $this->task->get_moduleid(); + $sebsettings->templateid = 0; + $sebsettings->requiresafeexambrowser = \quizaccess_seb\settings_provider::USE_SEB_CLIENT_CONFIG; + $sebsettings->showsebtaskbar = null; + $sebsettings->showwificontrol = null; + $sebsettings->showreloadbutton = null; + $sebsettings->showtime = null; + $sebsettings->showkeyboardlayout = null; + $sebsettings->allowuserquitseb = null; + $sebsettings->quitpassword = null; + $sebsettings->linkquitseb = null; + $sebsettings->userconfirmquit = null; + $sebsettings->enableaudiocontrol = null; + $sebsettings->muteonstartup = null; + $sebsettings->allowspellchecking = null; + $sebsettings->allowreloadinexam = null; + $sebsettings->activateurlfiltering = null; + $sebsettings->filterembeddedcontent = null; + $sebsettings->expressionsallowed = null; + $sebsettings->regexallowed = null; + $sebsettings->expressionsblocked = null; + $sebsettings->regexblocked = null; + $sebsettings->allowedbrowserexamkeys = null; + $sebsettings->showsebdownloadlink = 1; + $sebsettings->usermodified = $USER->id; + $sebsettings->timecreated = time(); + $sebsettings->timemodified = time(); + + $DB->insert_record('quizaccess_seb_quizsettings', $sebsettings); + } } protected function process_quiz_question_instance($data) { diff --git a/version.php b/version.php index b1e77ff4627..9e956712845 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2020042800.00; // YYYYMMDD = weekly release date of this DEV branch. +$version = 2020042800.01; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes. $release = '3.9dev+ (Build: 20200428)'; // Human-friendly version name