AutorÃa | Ultima modificación | Ver Log |
{"version":3,"file":"validate_quiz_access.min.js","sources":["../src/validate_quiz_access.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Validate Safe Exam Browser access keys.\n *\n * @module quizaccess_seb/validate_quiz_access\n * @author Andrew Madden <andrewmadden@catalyst-au.net>\n * @copyright 2021 Catalyst IT\n * @license
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Ajax from 'core/ajax';\nimport Config from 'core/config';\nimport Notification from \"core/notification\";\nimport * as View from 'quizaccess_seb/view';\n\n// SafeExamBrowser object will be automatically initialized if using the SafeExamBrowser application.\nwindow.SafeExamBrowser = window.SafeExamBrowser || null;\n\n/**\n * Once the keys are fetched, action checking access.\n *\n * @param {init} cmid Value of course module id of the quiz.\n * @param {boolean} autoreconfigure Value of Moodle setting: quizaccess_seb/autoreconfigureseb.\n */\nconst safeExamBrowserKeysUpdated = (cmid, autoreconfigure = false) => {\n // Action opening up the quiz.\n isQuizAccessValid(cmid).then((response) => {\n // Show the alert for an extra second to allow user to see it.\n setTimeout(View.clearLoadingAlert, 1000);\n\n if (response.configkey && response.browserexamkey) {\n View.allowAccess();\n } else {\n
// If autoreconfigureseb is enabled, attempt to reconfigure page with quiz settings.\n if (autoreconfigure === true && response.configkey === false) {\n reconfigureSafeExamBrowser(cmid);\n }\n setTimeout(View.showValidationFailedModal, 1000);\n }\n\n return response;\n }).catch(err => {\n Notification.exception(err);\n });\n};\n\n/**\n * Validate keys in Moodle backend.\n *\n * @param {init} cmid Value of course module id of the quiz.\n * @return {Promise}\n */\nconst isQuizAccessValid = (cmid) => {\n const request = {\n methodname: 'quizaccess_seb_validate_quiz_keys',\n args: {\n cmid: cmid,\n url: window.location.href,\n configkey: window.SafeExamBrowser.security.configKey,\n browserexamkey: window.SafeExamBrowser.security.browserExamKey\n },\n };\n\n return Ajax.call([request])[0];\n};\n\n/**\n * Check if the key is not yet set.\n *\n * @param {strin
g} key config key or browser exam key.\n * @return {boolean}\n */\nconst isKeyEmpty = (key) => {\n // If the SafeExamBrowser object is defined, the default 'empty' value of the configKey and browserExamKey is ':'.\n return key === \":\";\n};\n\n/**\n * Reload Safe Exam Browser with current quiz configuration.\n *\n * @param {init} cmid Value of course module id of the quiz.\n */\nconst reconfigureSafeExamBrowser = (cmid) => {\n const domain = Config.wwwroot.replace(/^http/i, 'seb');\n const redirecturl = domain + '/mod/quiz/accessrule/seb/config.php?cmid=' + cmid;\n document.location.replace(redirecturl);\n};\n\n/**\n * Initialize the process of fetching the keys.\n *\n * @param {init} cmid Value of course module id of the quiz.\n * @param {boolean} autoreconfigure Value of Moodle setting: quizaccess_seb/autoreconfigureseb.\n */\nexport const init = async(cmid, autoreconfigure = false) => {\n // If the SafeExamBrowser object is instantiated, try and use it to fetch the access keys.\n if
(window.SafeExamBrowser !== null) {\n await View.addLoadingAlert();\n // If the SEB keys are already set, we can call our callback directly.\n\n if (!isKeyEmpty(window.SafeExamBrowser.security.configKey) || !isKeyEmpty(window.SafeExamBrowser.security.browserExamKey)) {\n safeExamBrowserKeysUpdated(cmid, autoreconfigure);\n } else {\n window.SafeExamBrowser.security.updateKeys(safeExamBrowserKeysUpdated);\n }\n }\n};\n"],"names":["window","SafeExamBrowser","safeExamBrowserKeysUpdated","cmid","autoreconfigure","isQuizAccessValid","then","response","setTimeout","View","clearLoadingAlert","configkey","browserexamkey","allowAccess","reconfigureSafeExamBrowser","showValidationFailedModal","catch","err","exception","request","methodname","args","url","location","href","security","configKey","browserExamKey","Ajax","call","isKeyEmpty","key","redirecturl","Config","wwwroot","replace","document","async","addLoadingAlert","updateKeys"],"mappings":";;;;;;;;02BA
8BAA,OAAOC,gBAAkBD,OAAOC,iBAAmB,WAQ7CC,2BAA6B,SAACC,UAAMC,wEAEtCC,kBAAkBF,MAAMG,MAAMC,WAE1BC,WAAWC,KAAKC,kBAAmB,KAE/BH,SAASI,WAAaJ,SAASK,eAC/BH,KAAKI,gBAGmB,IAApBT,kBAAmD,IAAvBG,SAASI,WACrCG,2BAA2BX,MAE/BK,WAAWC,KAAKM,0BAA2B,MAGxCR,YACRS,OAAMC,4BACQC,UAAUD,SAUzBZ,kBAAqBF,aACjBgB,QAAU,CACZC,WAAY,oCACZC,KAAM,CACFlB,KAAMA,KACNmB,IAAKtB,OAAOuB,SAASC,KACrBb,UAAWX,OAAOC,gBAAgBwB,SAASC,UAC3Cd,eAAgBZ,OAAOC,gBAAgBwB,SAASE,wBAIjDC,cAAKC,KAAK,CAACV,UAAU,IAS1BW,WAAcC,KAED,MAARA,IAQLjB,2BAA8BX,aAE1B6B,YADSC,gBAAOC,QAAQC,QAAQ,SAAU,OACnB,4CAA8ChC,KAC3EiC,SAASb,SAASY,QAAQH,4BASVK,eAAMlC,UAAMC,wEAEG,OAA3BJ,OAAOC,wBACDQ,KAAK6B,kBAGNR,WAAW9B,OAAOC,gBAAgBwB,SAASC,YAAeI,WAAW9B,OAAOC,gBAAgBwB,SAASE,gBAGtG3B,OAAOC,gBAAgBwB,SAASc,WAAWrC,4BAF3CA,2BAA2BC,KAAMC"}