Skip to content

Commit

Permalink
MDL-76665: Prevent duplication and restoration of disabled SEB template.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Kotlyar committed Jul 8, 2024
1 parent 7d7a871 commit e0ccb84
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

use quizaccess_seb\seb_quiz_settings;
use quizaccess_seb\{seb_quiz_settings, settings_provider, template};

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

Expand Down Expand Up @@ -73,7 +73,14 @@ public function process_quizaccess_seb_quizsettings($data) {
unset($data->id);
$data->timecreated = $data->timemodified = time();
$data->usermodified = $USER->id;
$DB->insert_record(quizaccess_seb\seb_quiz_settings::TABLE, $data);

// Do not use template if it is no longer enabled.
if (!$DB->record_exists(template::TABLE, ['id' => $data->templateid, 'enabled' => '1'])) {
$data->templateid = 0;
$data->requiresafeexambrowser = settings_provider::USE_SEB_NO;
}

$DB->insert_record(seb_quiz_settings::TABLE, $data);

// Process attached files.
$this->add_related_files('quizaccess_seb', 'filemanager_sebconfigfile', null);
Expand Down Expand Up @@ -112,7 +119,10 @@ public function process_quizaccess_seb_template($data) {
}

// Update the restored quiz settings to use restored template.
$DB->set_field(\quizaccess_seb\seb_quiz_settings::TABLE, 'templateid', $template->get('id'), ['quizid' => $quizid]);
// Check if template is enabled before using it.
if ($template->get('enabled')) {
$DB->set_field(seb_quiz_settings::TABLE, 'templateid', $template->get('id'), ['quizid' => $quizid]);
}
}

}
Expand Down
16 changes: 15 additions & 1 deletion mod/quiz/accessrule/seb/classes/settings_provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,22 @@ public static function get_requiresafeexambrowser_options(\context $context): ar
* @return array
*/
protected static function get_template_options(): array {
global $DB, $PAGE;
$templates = [];
$records = template::get_records(['enabled' => 1], 'name');
$templatest = template::TABLE;
$sebquizsettingst = seb_quiz_settings::TABLE;
$cmid = $PAGE->cm->id ?? -1;

$sql = "SELECT *
FROM {{$templatest}} t
WHERE enabled = 1
OR EXISTS (
SELECT 1
FROM {{$sebquizsettingst}}
WHERE templateid = t.id
AND cmid = ?
)";
$records = $DB->get_records_sql($sql, [$cmid]);
if ($records) {
foreach ($records as $record) {
$templates[$record->get('id')] = $record->get('name');
Expand Down

0 comments on commit e0ccb84

Please sign in to comment.