From 4e0d95289a5d77fde9f95d9103ed6315350da815 Mon Sep 17 00:00:00 2001 From: abhigyanghosh30 Date: Wed, 13 Dec 2023 01:26:54 +0530 Subject: [PATCH] fix: adds automatic redirect to exam survey --- templates/credentials/exam.html | 18 ++++++++++++++++++ webapp/app.py | 2 ++ webapp/shop/cred/views.py | 7 ++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/templates/credentials/exam.html b/templates/credentials/exam.html index 8afdad3ac32..cac876b37c3 100644 --- a/templates/credentials/exam.html +++ b/templates/credentials/exam.html @@ -37,6 +37,24 @@ document.addEventListener('click', refocusIframe); document.addEventListener('keydown', refocusIframe); + + // ping TruCredential every 1 minute to check if exam is over + async function checkExamStatus(){ + fetch("/credentials/exam/{{assessment_id}}/status", { + method: "GET", + headers: { + "Content-Type": "application/json", + "Accept": "application/json" + } + }) + .then((r)=>r.json()) + .then((data)=>{ + if(data.assessment.ended === true){ + window.location.href = "/credentials/exit-survey"; + } + }); + } + setInterval(checkExamStatus, 1000); {% endblock content%} diff --git a/webapp/app.py b/webapp/app.py index 28ea104bc62..5256bd512a4 100644 --- a/webapp/app.py +++ b/webapp/app.py @@ -69,6 +69,7 @@ cred_beta_activation, cred_cancel_exam, cred_exam, + cred_exam_status, cred_home, cred_redeem_code, cred_schedule, @@ -866,6 +867,7 @@ def takeovers_index(): app.add_url_rule("/credentials/cancel-exam", view_func=cred_cancel_exam) app.add_url_rule("/credentials/assessments", view_func=cred_assessments) app.add_url_rule("/credentials/exam", view_func=cred_exam) +app.add_url_rule("/credentials/exam//status", view_func=cred_exam_status) app.add_url_rule( "/credentials//products", view_func=get_cue_products, diff --git a/webapp/shop/cred/views.py b/webapp/shop/cred/views.py index 50ab6117d1e..bb223e50c1c 100644 --- a/webapp/shop/cred/views.py +++ b/webapp/shop/cred/views.py @@ -398,8 +398,13 @@ def cred_exam(trueability_api, **_): return flask.abort(403) url = trueability_api.get_assessment_redirect(assessment_id) - return flask.render_template("credentials/exam.html", url=url) + return flask.render_template("credentials/exam.html", url=url, assessment_id=assessment_id) +@shop_decorator(area="cred", permission="user", response="json") +def cred_exam_status(trueability_api, **kwargs): + assessment_id = kwargs.get("exam_id") + assessment = trueability_api.get_assessment(assessment_id) + return flask.jsonify(assessment) @shop_decorator(area="cred", permission="user", response="html") def cred_syllabus_data(**_):