Skip to content

Commit

Permalink
Merge pull request #108 from talview/fix/sb-without-proctoring
Browse files Browse the repository at this point in the history
fix/sb without proctoring
  • Loading branch information
devang1281 authored Oct 28, 2024
2 parents 916431f + 5a52200 commit c4256ce
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
7 changes: 4 additions & 3 deletions classes/local/api/tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ private static function redirect_to_wrapper($proctoring_payload, $quiz)
{
// TODO Add check if wrapper URL already exists
$wrapper_response = self::create_sb_wrapper($proctoring_payload, $quiz);
redirect($wrapper_response->signed_short_url);
// redirect($wrapper_response->signed_short_url);
echo "<script> window.location='$wrapper_response->signed_url';</script>";
return;
}

Expand All @@ -113,7 +114,7 @@ private static function create_sb_wrapper($proctoring_payload, $quiz)
'expiry' => date(DATE_ISO8601, $quiz->timeclose == 0 ? strtotime("+3 days") : $quiz->timeclose ),
'is_secure_browser' => true
);
var_dump($data);
// var_dump($data);
try {
$curl->setHeader(array('Content-Type: application/json', 'Authorization: Bearer ' . $auth_token));
$response = $curl->post($url, json_encode($data));
Expand Down Expand Up @@ -151,7 +152,7 @@ private static function generate_auth_token($api_base_url, $payload)

private static function capture_error(\Throwable $err)
{
\Sentry\init(['dsn' => 'https://61facdc5414c4c73ab2b17fe902bf9ba@o286634.ingest.sentry.io/5304587']);
\Sentry\init(['dsn' => 'https://577c4f60f7bd37671bdd8ad626d63a7d@sentry.talview.org/149']);
\Sentry\captureException($err);
}

Expand Down
13 changes: 6 additions & 7 deletions classes/local/injector.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,15 @@ public static function inject() {
if ($PAGE->cm) {
$quiz = $DB->get_record('quiz', array('id' => $PAGE->cm->instance));
$quizaccess_proctor_setting = $DB->get_record('quizaccess_proctor', array('quizid' => $quiz->id));
//Logic for launching Secure Browser without Proctoring Starts
if ((!$quizaccess_proctor_setting) ||
($quizaccess_proctor_setting && $quizaccess_proctor_setting->proctortype == 'noproctor')) {
if (($quizaccess_proctor_setting->tsbenabled && strpos($_SERVER ['HTTP_USER_AGENT'], "Proview-SB") === FALSE)) {
$t = new api\tracker();
$t::insert_tracking();
return;
}
($quizaccess_proctor_setting && $quizaccess_proctor_setting->proctortype == 'noproctor' && $quizaccess_proctor_setting->tsbenabled)) {
$t = new api\tracker();
$t::insert_tracking();
self::inject_password($PAGE, $quiz);
return;
}
//Logic for launching Secure Browser without Proctoring Ends
}
// Logic for enabling proview for course level and quiz level ends.

Expand Down Expand Up @@ -131,7 +130,7 @@ public static function inject() {
$t::insert_tracking();
return;
} catch (\Throwable $error) {
\Sentry\init(['dsn' => 'https://61facdc5414c4c73ab2b17fe902bf9ba@o286634.ingest.sentry.io/5304587' ]);
\Sentry\init(['dsn' => 'https://577c4f60f7bd37671bdd8ad626d63a7d@sentry.talview.org/149' ]);
\Sentry\captureException($error);
die;
?>
Expand Down
2 changes: 1 addition & 1 deletion frame.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<script>
var childOrigin = '*';
Sentry.init({
dsn: 'https://61facdc5414c4c73ab2b17fe902bf9ba@o286634.ingest.sentry.io/5304587'
dsn: 'https://577c4f60f7bd37671bdd8ad626d63a7d@sentry.talview.org/149'
});
// Defining function for event handling on postMessage from any window
function receiveMessage(event) {
Expand Down
18 changes: 16 additions & 2 deletions templates/tracker.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
parent.postMessage({type: 'stopProview',url: window.location.href}, childOrigin);
}
})
if( window.self == window.top) {
if( window.self == window.top && '{{session_type}}' !== 'noproctor') {
let params = new URLSearchParams({
url: current,
clear: false,
Expand All @@ -97,6 +97,20 @@
});
window.location.href = '{{root_dir}}local/proview/frame.php?'+params.toString();
}
// Hide back Button from quiz if exam is launched in SB Starts
// NOTE: This will only work for English Language due to string matching
if (window.navigator.userAgent.match(/Proview-SB/)) {
console.log("User Agent: ", window.navigator.userAgent);
document.querySelectorAll('a').forEach(link => {
const urlContainsIndex = link.href.includes('moodle/mod/quiz/view.php');
const textContainsBack = link.textContent.trim().toLowerCase().includes('back');
if (urlContainsIndex && textContainsBack) {
// Hide the element by setting its display style to none
link.style.display = 'none';
}
});
}
// Hide back Button from quiz if exam is launched in SB Starts
}
if(current.match('mod/quiz/view') ) {
if(window.self != window.top && window.parent.previousUrl) { //checking if the request is coming from summary
Expand All @@ -108,7 +122,7 @@
let div = document.getElementsByClassName("singlebutton quizstartbuttondiv");
div[0].getElementsByTagName("*")[3].addEventListener("click", function(event){
$(".moodle-dialogue-base").hide();
if( window.self == window.top) {
if( window.self == window.top && '{{session_type}}' !== 'noproctor') {
let params = new URLSearchParams({
url : current,
clear : false,
Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@

defined('MOODLE_INTERNAL') || die;

$plugin->version = 2024102401;
$plugin->version = 2024102805;
$plugin->requires = 2020061500;
$plugin->release = '3.3.6 (Build: 2024102401)';
$plugin->release = '3.3.7 (Build: 2024102805)';
$plugin->maturity = MATURITY_STABLE;
$plugin->component = 'local_proview';

Expand Down

0 comments on commit c4256ce

Please sign in to comment.