Skip to content

Commit

Permalink
Take additional SB Config from FE (#52)
Browse files Browse the repository at this point in the history
* Take additional SB Config from FE

* Add support for additional secure browser configurations

- Renamed and added new fields for blacklisted software and secure browser settings.
- Updated database schema and upgrade script to include new fields.
- Modified form elements and validation rules to accommodate new settings.
- Adjusted language strings for new field names and help texts.
- Updated observer and settings classes to handle new configurations.
- Incremented plugin version to 1.5.0.

* downgrade ckeditor

---------

Co-authored-by: Rohan Sharma Sitoula <[email protected]>
  • Loading branch information
devang1281 and rohansharmasitoula authored Oct 15, 2024
1 parent 2caa0e6 commit 046d8de
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 5 deletions.
4 changes: 4 additions & 0 deletions classes/observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ public static function store(\core\event\base $event)
$eventdata->proctoring_enabled = !($quiz_proctor_settings->proctortype == 'noproctor');
$eventdata->proctoring_type = ($quiz_proctor_settings->proctortype == 'noproctor') ? NULL : $quiz_proctor_settings->proctortype;
$eventdata->tsb_enabled = boolval($quiz_proctor_settings->tsbenabled);
$eventdata->blacklisted_windows_softwares = $quiz_proctor_settings->blacklisted_softwares_win;
$eventdata->blacklisted_mac_softwares = $quiz_proctor_settings->blacklisted_softwares_mac;
$eventdata->minimize_permitted = boolval($quiz_proctor_settings->sb_kiosk_mode);
$eventdata->screen_protection = boolval($quiz_proctor_settings->sb_content_protection);
$eventdata->attempts = 0;
$eventdata->timeopen = (int)$quiz->timeopen;
$eventdata->timeclose = (int)$quiz->timeclose;
Expand Down
17 changes: 16 additions & 1 deletion classes/quiz_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,22 @@ protected static function define_properties(): array
'type' => PARAM_RAW,
'default' => '',
],

'blacklisted_softwares_win' => [
'type' => PARAM_TEXT,
'default' => '',
],
'blacklisted_softwares_mac' => [
'type' => PARAM_TEXT,
'default' => '',
],
'sb_kiosk_mode' => [
'type' => PARAM_INT,
'default' => 0,
],
'sb_content_protection' => [
'type' => PARAM_INT,
'default' => 1,
],
];
}

Expand Down
44 changes: 44 additions & 0 deletions classes/settings_provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,50 @@ protected static function add_proctor_usage_options(\mod_quiz_mod_form $quizform
'tsbenabled',
get_string('tsbenable', 'quizaccess_proctor'));
self::insert_element($quizform, $mform, $tsb_enable_element);

$sb_blacklisted_software_mac_element = $mform->createElement(
'textarea',
'blacklisted_softwares_mac',
get_string('blacklisted_softwares_mac', 'quizaccess_proctor'),
['style' => 'width: 100%;']
);

self::insert_element($quizform, $mform, $sb_blacklisted_software_mac_element);
self::set_type($quizform, $mform, 'blacklisted_softwares_mac', PARAM_TEXT);
self::set_default($quizform, $mform, 'blacklisted_softwares_mac', '');
self::add_help_button($quizform, $mform, 'blacklisted_softwares_mac');


$sb_blacklisted_software_windows_element = $mform->createElement(
'textarea',
'blacklisted_softwares_win',
get_string('blacklisted_softwares_win', 'quizaccess_proctor'),
['style' => 'width: 100%;']
);

self::insert_element($quizform, $mform, $sb_blacklisted_software_windows_element);
self::set_type($quizform, $mform, 'blacklisted_softwares_win', PARAM_TEXT);
self::set_default($quizform, $mform, 'blacklisted_softwares_win', '');
self::add_help_button($quizform, $mform, 'blacklisted_softwares_win');

$sb_kiosk_mode_enable_element = $mform->createElement(
'checkbox',
'sb_kiosk_mode',
get_string('sb_kiosk_mode_enable', 'quizaccess_proctor'));
self::insert_element($quizform, $mform, $sb_kiosk_mode_enable_element);

$sb_content_protection_enable_element = $mform->createElement(
'checkbox',
'sb_content_protection',
get_string('sb_content_protection_enable', 'quizaccess_proctor'));
self::insert_element($quizform, $mform, $sb_content_protection_enable_element);
self::set_default($quizform, $mform, 'sb_content_protection', 1);

$mform->hideIf('blacklisted_softwares_mac', 'tsbenabled', 'notchecked');
$mform->hideIf('blacklisted_softwares_win', 'tsbenabled', 'notchecked');
$mform->hideIf('sb_kiosk_mode', 'tsbenabled', 'notchecked');
$mform->hideIf('sb_content_protection', 'tsbenabled', 'notchecked');

}

/**
Expand Down
4 changes: 4 additions & 0 deletions db/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ function xmldb_quizaccess_proctor_install() {
$proctorsettings->timecreated = time();
$proctorsettings->timemodified = time();
$proctorsettings->reference_link = '';
$proctorsettings->blacklisted_softwares_win = '';
$proctorsettings->blacklisted_softwares_mac = '';
$proctorsettings->sb_kiosk_mode = 0;
$proctorsettings->sb_content_protection = 1;

$DB->insert_record('quizaccess_proctor', $proctorsettings);

Expand Down
4 changes: 4 additions & 0 deletions db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="reference_link" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="instructions" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="blacklisted_softwares_win" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="blacklisted_softwares_mac" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="sb_kiosk_mode" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="sb_content_protection" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="1" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
Expand Down
34 changes: 34 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,39 @@ function xmldb_quizaccess_proctor_upgrade($oldversion) {
// Automatically generated Moodle v4.0.0 release upgrade line.
// Put any upgrade step following this.

if ($oldversion < 2024092605) {
// Define the table and fields to be added to quizaccess_proctor.
$table = new xmldb_table('quizaccess_proctor');
$fields = [
new xmldb_field('blacklisted_softwares_win', XMLDB_TYPE_TEXT, null, null, null, null, null, 'reference_link'),
new xmldb_field('blacklisted_softwares_mac', XMLDB_TYPE_TEXT, null, null, null, null, null, 'blacklisted_softwares_win'),
new xmldb_field('sb_kiosk_mode', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'blacklisted_softwares_mac'),
new xmldb_field('sb_content_protection', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '1', 'sb_kiosk_mode'),
];

// Conditionally launch add fields.
foreach ($fields as $field) {
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
}

// Update existing records if the first field has been added.
if ($dbman->field_exists($table, $fields[0])) {
$records = $DB->get_records('quizaccess_proctor');
foreach ($records as $record) {
$record->sb_blacklisted_software_windows = '';
$record->sb_blacklisted_software_mac = '';
$record->sb_kiosk_mode_enable = 0;
$record->sb_content_protection_enable = 0;
$DB->update_record('quizaccess_proctor', $record);
}
}

// Proctor savepoint reached.
upgrade_plugin_savepoint(true, 2024092605, 'quizaccess', 'proctor');
}


return true;
}
8 changes: 7 additions & 1 deletion lang/en/quizaccess_proctor.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,10 @@
$string['reference_link'] = 'Reference Link';
$string['reference_link_help'] = 'Kindly provide the reference links in the format `[caption](url)`. For example, `[moodle](https://www.moodle.com)` one per line.';
$string['invalid_reference_links'] = 'Please enter valid reference links in the format [caption](url). For example, [moodle](https://www.moodle.com) one per line.';
$string['instructions'] = 'Instructions';
$string['blacklisted_softwares_mac'] = 'Blacklisted Softwares (Mac)';
$string['blacklisted_softwares_win'] = 'Blacklisted Softwares (Windows)';
$string['sb_kiosk_mode_enable'] = 'Enable Kiosk Mode';
$string['sb_content_protection_enable'] = 'Enable Content Protection';
$string['instructions'] = 'Instructions';
$string['blacklisted_softwares_win_help'] = 'Kindly provide the list of blacklisted softwares for Windows in comma separated format. For example Teams, Zoom, etc.';
$string['blacklisted_softwares_mac_help'] = 'Kindly provide the list of blacklisted softwares for Mac in comma separated format. For example, Teams, Zoom, etc.';
16 changes: 15 additions & 1 deletion rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ public static function save_settings($quiz)
$settings->instructions = $quizsettings->get('instructions');
$settings->tsbenabled = $quizsettings->get('tsbenabled');
$settings->reference_link = $quizsettings->get('reference_link');
$settings->blacklisted_softwares_win = $quizsettings->get('blacklisted_softwares_win');
$settings->blacklisted_softwares_mac = $quizsettings->get('blacklisted_softwares_mac');
$settings->sb_kiosk_mode = $quizsettings->get('sb_kiosk_mode');
$settings->sb_content_procetion = $quizsettings->get('sb_content_protection');
}
if (empty($quizsettings)) {
$quizsettings = new quiz_settings(0, $settings);
Expand All @@ -173,6 +177,12 @@ public static function save_settings($quiz)
$proctordata->tsbenabled = (isset($quiz->tsbenabled) && $quiz->tsbenabled) ? 1 : 0;
$proctordata->usermodified = $USER->id;
$proctordata->reference_link = $quiz->reference_link;
$proctordata->blacklisted_softwares_win = $quiz->blacklisted_softwares_win;
$proctordata->blacklisted_softwares_mac = $quiz->blacklisted_softwares_mac;
$proctordata->sb_kiosk_mode = (isset($quiz->sb_kiosk_mode) && $quiz->sb_kiosk_mode) ? 1 : 0;
$proctordata->sb_content_protection = (isset($quiz->sb_content_protection) && $quiz->sb_content_protection) ? 1 : 0;

// Add remaining SB params after updating DB
if ($proctor = $DB->get_record('quizaccess_proctor', array('quizid' => $quiz->id))) {
$proctordata->id = $proctor->id;
$proctordata->timemodified = time();
Expand Down Expand Up @@ -227,7 +237,11 @@ public static function get_settings_sql($quizid): array
'proctor.proctortype AS proctortype, '
. 'proctor.tsbenabled AS tsbenabled, '
. 'proctor.instructions AS instructions,'
. 'proctor.reference_link AS reference_link '
. 'proctor.reference_link AS reference_link, '
. 'proctor.blacklisted_softwares_win AS blacklisted_softwares_win, '
. 'proctor.blacklisted_softwares_mac AS blacklisted_softwares_mac, '
. 'proctor.sb_kiosk_mode AS sb_kiosk_mode, '
. 'proctor.sb_content_protection AS sb_content_protection '
, 'LEFT JOIN {quizaccess_proctor} proctor ON proctor.quizid = quiz.id '
, []
];
Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
*/

defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042401;
$plugin->version = 2024101501;
$plugin->requires = 2020061500;
$plugin->release = '1.4.0 (Build: 2024042401)';
$plugin->release = '1.5.0 (Build: 2024101501)';
$plugin->component = 'quizaccess_proctor';
$plugin->maturity = MATURITY_STABLE;

Expand Down

0 comments on commit 046d8de

Please sign in to comment.