Skip to content

Commit

Permalink
Task change secure browser url (#49)
Browse files Browse the repository at this point in the history
* Update AI proctoring type in dropdown to Recorded

* updated the version

* removed AI proctored string

* version update

* Change API requests to use Moodle_curl_class

* Update version.php

* resolved coderabbit comments

* Change TSB to SB

* Update version.php

* Update version.php

* version update
  • Loading branch information
rohansharmasitoula authored Apr 24, 2024
1 parent 461bf5e commit 1843ce9
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 60 deletions.
84 changes: 33 additions & 51 deletions classes/observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,77 +122,59 @@ public static function store(\core\event\base $event)
throw new CustomException("Auth Token Not generated");
return;
}
$token = json_decode($auth_response)->access_token;
$token = $auth_response['access_token'];
$response = self::send_quiz_details($api_base_url, $token, $eventdata);
} catch (\Throwable $err) {
self::capture_error($err);
}

}


private static function generate_auth_token($api_base_url, $payload)
{
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => $api_base_url . '/auth',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($payload),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
global $CFG;
require_once($CFG->libdir . '/filelib.php');
$curl = new curl();
$headers = array('Content-Type: application/json');
$curl->setHeader($headers);
$request_url = $api_base_url . '/auth';
$json_payload = json_encode($payload);
try {
$response = curl_exec($curl);
$err = curl_error($curl);
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if ($err) {
throw new CustomException($err);
} elseif ($response && $httpcode != 200) {
throw new CustomException($response);
} else {
return $response;
$response = $curl->post($request_url, $json_payload);
if ($curl->get_errno()) {
$error_msg = $curl->error;
throw new moodle_exception('errorapirequest', 'quizaccess_proctor', '', $error_msg);
}
$decoded_response = json_decode($response, true);
if (!isset($decoded_response['access_token'])) {
throw new CustomException("Auth Token Not generated");
}
return $decoded_response;
} catch (\Throwable $err) {
self::capture_error($err);
}
}

private static function send_quiz_details($api_base_url, $token, $eventdata)
{
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => $api_base_url . '/quiz',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($eventdata),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer " . $token,
"Content-Type: application/json"
],
]);
global $CFG;
require_once($CFG->libdir . '/filelib.php');
$curl = new curl();
$headers = array(
'Authorization: Bearer ' . $token,
'Content-Type: application/json'
);
$curl->setHeader($headers);
$request_url = $api_base_url . '/quiz';
$json_eventdata = json_encode($eventdata);
try {
$response = curl_exec($curl);
$err = curl_error($curl);
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if ($err) {
throw new CustomException($err);
} elseif ($response && $httpcode != 201) {
throw new CustomException($response);
} else {
return $response;
$response = $curl->post($request_url, $json_eventdata);
if ($curl->get_errno()) {
$error_msg = $curl->error;
throw new moodle_exception('errorapirequest', 'quizaccess_proctor', '', $error_msg);
}
$decoded_response = json_decode($response, true);
return $decoded_response;
} catch (\Throwable $err) {
self::capture_error($err);
}
Expand Down
2 changes: 1 addition & 1 deletion classes/settings_provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public static function get_proctor_options(\context $context): array

$options[''] = get_string('selectproctor', 'quizaccess_proctor');
$options['noproctor'] = get_string('noproctor', 'quizaccess_proctor');
$options['ai_proctor'] = get_string('aiproctor', 'quizaccess_proctor');
$options['ai_proctor'] = get_string('recorded', 'quizaccess_proctor');
$options['record_and_review'] = get_string('recordandreview', 'quizaccess_proctor');
$options['live_proctor'] = get_string('liveproctor', 'quizaccess_proctor');

Expand Down
6 changes: 3 additions & 3 deletions lang/en/quizaccess_proctor.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
$string['privacy:metadata:quizid'] = 'Quiz ID';
$string['proctortype'] = 'Proctoring Type';
$string['proctortype_help'] = 'The type of proctoring applies to the quiz.';
$string['tsbenable'] = 'Enable Talview Secure Browser';
$string['tsbenable'] = 'Enable Secure Browser';
$string['selectproctor'] = 'Select Proctoring Type';
$string['noproctor'] = 'No Proctoring';
$string['aiproctor'] = 'AI Proctoring';
$string['recordandreview'] = 'Record and Review Proctoring';
$string['recorded'] = 'Recorded';
$string['recordandreview'] = 'Record and Review';
$string['liveproctor'] = 'Live Proctoring';
$string['pluginname'] = 'Proctoring Settings';
$string['invalidproctor'] = 'Invalid Proctoring';
Expand Down
4 changes: 2 additions & 2 deletions rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ public function redirect_to_tsb_link()
$baseUrl = $CFG->wwwroot;
$path = "/mod/quiz/view.php?id=" . $PAGE->cm->id;
$redirectURL = $baseUrl . $path;
$tsblink = "https://pages.talview.com/tsb/index.html?redirect_url=" . urlencode($redirectURL) . "&user=" . urlencode($_SERVER['HTTP_USER_AGENT']);
$PAGE->requires->js_amd_inline('
$tsblink = "https://pages.talview.com/securebrowser/index.html?redirect_url=" . urlencode($redirectURL) . "&user=" . urlencode($_SERVER['HTTP_USER_AGENT']);
$PAGE->requires->js_amd_inline('
require(["jquery"], function($) {
$(document).ready(function() {
window.location.href = "' . $tsblink . '";
Expand Down
5 changes: 2 additions & 3 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@
*/

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

$plugin->version = 2023120801;
$plugin->version = 2024042401;
$plugin->requires = 2020061500;
$plugin->release = '1.3.1 (Build: 2023120801)';
$plugin->release = '1.4.0 (Build: 2024042401)';
$plugin->component = 'quizaccess_proctor';
$plugin->maturity = MATURITY_STABLE;

Expand Down

0 comments on commit 1843ce9

Please sign in to comment.