first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,3 @@
define("quizaccess_seb/managetemplates",["jquery","core/ajax","core/str","core/notification"],(function($,ajax,str,notification){var manager={removeTemplate:function(e){e.preventDefault();var targetUrl=$(e.currentTarget).attr("href");str.get_strings([{key:"confirmtemplateremovaltitle",component:"quizaccess_seb"},{key:"confirmtemplateremovalquestion",component:"quizaccess_seb"},{key:"yes",component:"moodle"},{key:"no",component:"moodle"}]).then((function(s){notification.confirm(s[0],s[1],s[2],s[3],(function(){window.location=targetUrl}))})).catch()},setup:function(){$("body").delegate('[data-action="delete"]',"click",manager.removeTemplate)}};return{setup:manager.setup}}));
//# sourceMappingURL=managetemplates.min.js.map
@@ -0,0 +1 @@
{"version":3,"file":"managetemplates.min.js","sources":["../src/managetemplates.js"],"sourcesContent":["/**\n * Template management code.\n *\n * @module quizaccess_seb/managetemplates\n * @copyright 2020 Dmitrii Metelkin <dmitriim@catalyst-au.net>\n */\ndefine(\n ['jquery', 'core/ajax', 'core/str', 'core/notification'],\n function($, ajax, str, notification) {\n var manager = {\n /**\n * Confirm removal of the specified template.\n *\n * @method removeTemplate\n * @param {EventFacade} e The EventFacade\n */\n removeTemplate: function(e) {\n e.preventDefault();\n var targetUrl = $(e.currentTarget).attr('href');\n str.get_strings([\n {\n key: 'confirmtemplateremovaltitle',\n component: 'quizaccess_seb'\n },\n {\n key: 'confirmtemplateremovalquestion',\n component: 'quizaccess_seb'\n },\n {\n key: 'yes',\n component: 'moodle'\n },\n {\n key: 'no',\n component: 'moodle'\n }\n ])\n .then(function(s) {\n notification.confirm(s[0], s[1], s[2], s[3], function() {\n window.location = targetUrl;\n });\n\n return;\n })\n .catch();\n },\n\n /**\n * Setup the template management UI.\n *\n * @method setup\n */\n setup: function() {\n $('body').delegate('[data-action=\"delete\"]', 'click', manager.removeTemplate);\n }\n };\n\n return /** @alias module:quizaccess_seb/managetemplates */ {\n /**\n * Setup the template management UI.\n *\n * @method setup\n */\n setup: manager.setup\n };\n });\n"],"names":["define","$","ajax","str","notification","manager","removeTemplate","e","preventDefault","targetUrl","currentTarget","attr","get_strings","key","component","then","s","confirm","window","location","catch","setup","delegate"],"mappings":"AAMAA,wCACI,CAAC,SAAU,YAAa,WAAY,sBACpC,SAASC,EAAGC,KAAMC,IAAKC,kBACfC,QAAU,CAOVC,eAAgB,SAASC,GACrBA,EAAEC,qBACEC,UAAYR,EAAEM,EAAEG,eAAeC,KAAK,QACxCR,IAAIS,YAAY,CACZ,CACIC,IAAY,8BACZC,UAAY,kBAEhB,CACID,IAAY,iCACZC,UAAY,kBAEhB,CACID,IAAY,MACZC,UAAY,UAEhB,CACID,IAAY,KACZC,UAAY,YAGnBC,MAAK,SAASC,GACXZ,aAAaa,QAAQD,EAAE,GAAIA,EAAE,GAAIA,EAAE,GAAIA,EAAE,IAAI,WACzCE,OAAOC,SAAWV,gBAKzBW,SAQLC,MAAO,WACHpB,EAAE,QAAQqB,SAAS,yBAA0B,QAASjB,QAAQC,wBAIX,CAMvDe,MAAOhB,QAAQgB"}
@@ -0,0 +1,11 @@
define("quizaccess_seb/validate_quiz_access",["exports","core/ajax","core/config","core/notification","quizaccess_seb/view"],(function(_exports,_ajax,_config,_notification,View){function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}
/**
* Validate Safe Exam Browser access keys.
*
* @module quizaccess_seb/validate_quiz_access
* @author Andrew Madden <andrewmadden@catalyst-au.net>
* @copyright 2021 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_ajax=_interopRequireDefault(_ajax),_config=_interopRequireDefault(_config),_notification=_interopRequireDefault(_notification),View=function(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}newObj.default=obj,cache&&cache.set(obj,newObj);return newObj}(View),window.SafeExamBrowser=window.SafeExamBrowser||null;const safeExamBrowserKeysUpdated=function(cmid){let autoreconfigure=arguments.length>1&&void 0!==arguments[1]&&arguments[1];isQuizAccessValid(cmid).then((response=>(setTimeout(View.clearLoadingAlert,1e3),response.configkey&&response.browserexamkey?View.allowAccess():(!0===autoreconfigure&&!1===response.configkey&&reconfigureSafeExamBrowser(cmid),setTimeout(View.showValidationFailedModal,1e3)),response))).catch((err=>{_notification.default.exception(err)}))},isQuizAccessValid=cmid=>{const request={methodname:"quizaccess_seb_validate_quiz_keys",args:{cmid:cmid,url:window.location.href,configkey:window.SafeExamBrowser.security.configKey,browserexamkey:window.SafeExamBrowser.security.browserExamKey}};return _ajax.default.call([request])[0]},isKeyEmpty=key=>":"===key,reconfigureSafeExamBrowser=cmid=>{const redirecturl=_config.default.wwwroot.replace(/^http/i,"seb")+"/mod/quiz/accessrule/seb/config.php?cmid="+cmid;document.location.replace(redirecturl)};_exports.init=async function(cmid){let autoreconfigure=arguments.length>1&&void 0!==arguments[1]&&arguments[1];null!==window.SafeExamBrowser&&(await View.addLoadingAlert(),isKeyEmpty(window.SafeExamBrowser.security.configKey)&&isKeyEmpty(window.SafeExamBrowser.security.browserExamKey)?window.SafeExamBrowser.security.updateKeys(safeExamBrowserKeysUpdated):safeExamBrowserKeysUpdated(cmid,autoreconfigure))}}));
//# sourceMappingURL=validate_quiz_access.min.js.map
File diff suppressed because one or more lines are too long
+11
View File
@@ -0,0 +1,11 @@
define("quizaccess_seb/view",["exports","core/notification","core/templates","core/str","core/local/modal/alert"],(function(_exports,_notification,Templates,Str,_alert){function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}return newObj.default=obj,cache&&cache.set(obj,newObj),newObj}function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}
/**
* Manage the quiz views.
*
* @module quizaccess_seb/view
* @author Andrew Madden <andrewmadden@catalyst-au.net>
* @copyright 2021 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.showValidationFailedModal=_exports.clearLoadingAlert=_exports.allowAccess=_exports.addLoadingAlert=void 0,_notification=_interopRequireDefault(_notification),Templates=_interopRequireWildcard(Templates),Str=_interopRequireWildcard(Str),_alert=_interopRequireDefault(_alert);const SELECTOR_MAIN="#region-main",SELECTOR_LOADING=".seb-loading",TEMPLATE_LOADING="quizaccess_seb/loading";_exports.allowAccess=()=>{window.location.reload()};_exports.addLoadingAlert=()=>Templates.render(TEMPLATE_LOADING,{}).then(((html,js)=>{const alertRegion=window.document.querySelector(SELECTOR_MAIN);return Templates.prependNodeContents(alertRegion,html,js)})).catch(_notification.default.exception);_exports.clearLoadingAlert=()=>{const alert=window.document.querySelector(SELECTOR_LOADING);alert&&Templates.replaceNode(alert,"","")};_exports.showValidationFailedModal=()=>{_alert.default.create({title:Str.get_string("sebkeysvalidationfailed","quizaccess_seb"),body:Str.get_string("invalidkeys","quizaccess_seb"),large:!1,show:!0}).catch(_notification.default.exception)}}));
//# sourceMappingURL=view.min.js.map
@@ -0,0 +1 @@
{"version":3,"file":"view.min.js","sources":["../src/view.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 * Manage the quiz views.\n *\n * @module quizaccess_seb/view\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 Notification from \"core/notification\";\nimport * as Templates from \"core/templates\";\nimport * as Str from \"core/str\";\nimport ModalAlert from \"core/local/modal/alert\";\n\n/** @var SELECTOR List of CSS selectors. */\nconst SELECTOR = {\n MAIN: '#region-main',\n LOADING: '.seb-loading',\n};\n\n/** @var Template List of mustache templates. */\nconst TEMPLATE = {\n LOADING: 'quizaccess_seb/loading',\n};\n\n/**\n * Manages view when access has been granted.\n */\nexport const allowAccess = () => {\n window.location.reload();\n};\n\n/**\n * Add an alert to page to inform that Safe Exam Browser access is being checked.\n *\n * @return {Promise}\n */\nexport const addLoadingAlert = () => {\n return Templates.render(TEMPLATE.LOADING, {}).then((html, js) => {\n const alertRegion = window.document.querySelector(SELECTOR.MAIN);\n return Templates.prependNodeContents(alertRegion, html, js);\n }).catch(Notification.exception);\n};\n\n/**\n * Remove the Safe Exam Browser access check alert from the page.\n */\nexport const clearLoadingAlert = () => {\n const alert = window.document.querySelector(SELECTOR.LOADING);\n if (alert) {\n Templates.replaceNode(alert, '', '');\n }\n};\n\n/**\n * Display validation failed modal.\n */\nexport const showValidationFailedModal = () => {\n ModalAlert.create({\n title: Str.get_string('sebkeysvalidationfailed', 'quizaccess_seb'),\n body: Str.get_string('invalidkeys', 'quizaccess_seb'),\n large: false,\n show: true,\n }).catch(Notification.exception);\n};\n"],"names":["SELECTOR","TEMPLATE","window","location","reload","Templates","render","then","html","js","alertRegion","document","querySelector","prependNodeContents","catch","Notification","exception","alert","replaceNode","create","title","Str","get_string","body","large","show"],"mappings":";;;;;;;;8VA8BMA,cACI,eADJA,iBAEO,eAIPC,iBACO,8CAMc,KACvBC,OAAOC,SAASC,mCAQW,IACpBC,UAAUC,OAAOL,iBAAkB,IAAIM,MAAK,CAACC,KAAMC,YAChDC,YAAcR,OAAOS,SAASC,cAAcZ,sBAC3CK,UAAUQ,oBAAoBH,YAAaF,KAAMC,OACzDK,MAAMC,sBAAaC,sCAMO,WACvBC,MAAQf,OAAOS,SAASC,cAAcZ,kBACxCiB,OACAZ,UAAUa,YAAYD,MAAO,GAAI,wCAOA,oBAC1BE,OAAO,CACdC,MAAOC,IAAIC,WAAW,0BAA2B,kBACjDC,KAAMF,IAAIC,WAAW,cAAe,kBACpCE,OAAO,EACPC,MAAM,IACPX,MAAMC,sBAAaC"}
@@ -0,0 +1,66 @@
/**
* Template management code.
*
* @module quizaccess_seb/managetemplates
* @copyright 2020 Dmitrii Metelkin <dmitriim@catalyst-au.net>
*/
define(
['jquery', 'core/ajax', 'core/str', 'core/notification'],
function($, ajax, str, notification) {
var manager = {
/**
* Confirm removal of the specified template.
*
* @method removeTemplate
* @param {EventFacade} e The EventFacade
*/
removeTemplate: function(e) {
e.preventDefault();
var targetUrl = $(e.currentTarget).attr('href');
str.get_strings([
{
key: 'confirmtemplateremovaltitle',
component: 'quizaccess_seb'
},
{
key: 'confirmtemplateremovalquestion',
component: 'quizaccess_seb'
},
{
key: 'yes',
component: 'moodle'
},
{
key: 'no',
component: 'moodle'
}
])
.then(function(s) {
notification.confirm(s[0], s[1], s[2], s[3], function() {
window.location = targetUrl;
});
return;
})
.catch();
},
/**
* Setup the template management UI.
*
* @method setup
*/
setup: function() {
$('body').delegate('[data-action="delete"]', 'click', manager.removeTemplate);
}
};
return /** @alias module:quizaccess_seb/managetemplates */ {
/**
* Setup the template management UI.
*
* @method setup
*/
setup: manager.setup
};
});
@@ -0,0 +1,121 @@
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Validate Safe Exam Browser access keys.
*
* @module quizaccess_seb/validate_quiz_access
* @author Andrew Madden <andrewmadden@catalyst-au.net>
* @copyright 2021 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
import Ajax from 'core/ajax';
import Config from 'core/config';
import Notification from "core/notification";
import * as View from 'quizaccess_seb/view';
// SafeExamBrowser object will be automatically initialized if using the SafeExamBrowser application.
window.SafeExamBrowser = window.SafeExamBrowser || null;
/**
* Once the keys are fetched, action checking access.
*
* @param {init} cmid Value of course module id of the quiz.
* @param {boolean} autoreconfigure Value of Moodle setting: quizaccess_seb/autoreconfigureseb.
*/
const safeExamBrowserKeysUpdated = (cmid, autoreconfigure = false) => {
// Action opening up the quiz.
isQuizAccessValid(cmid).then((response) => {
// Show the alert for an extra second to allow user to see it.
setTimeout(View.clearLoadingAlert, 1000);
if (response.configkey && response.browserexamkey) {
View.allowAccess();
} else {
// If autoreconfigureseb is enabled, attempt to reconfigure page with quiz settings.
if (autoreconfigure === true && response.configkey === false) {
reconfigureSafeExamBrowser(cmid);
}
setTimeout(View.showValidationFailedModal, 1000);
}
return response;
}).catch(err => {
Notification.exception(err);
});
};
/**
* Validate keys in Moodle backend.
*
* @param {init} cmid Value of course module id of the quiz.
* @return {Promise}
*/
const isQuizAccessValid = (cmid) => {
const request = {
methodname: 'quizaccess_seb_validate_quiz_keys',
args: {
cmid: cmid,
url: window.location.href,
configkey: window.SafeExamBrowser.security.configKey,
browserexamkey: window.SafeExamBrowser.security.browserExamKey
},
};
return Ajax.call([request])[0];
};
/**
* Check if the key is not yet set.
*
* @param {string} key config key or browser exam key.
* @return {boolean}
*/
const isKeyEmpty = (key) => {
// If the SafeExamBrowser object is defined, the default 'empty' value of the configKey and browserExamKey is ':'.
return key === ":";
};
/**
* Reload Safe Exam Browser with current quiz configuration.
*
* @param {init} cmid Value of course module id of the quiz.
*/
const reconfigureSafeExamBrowser = (cmid) => {
const domain = Config.wwwroot.replace(/^http/i, 'seb');
const redirecturl = domain + '/mod/quiz/accessrule/seb/config.php?cmid=' + cmid;
document.location.replace(redirecturl);
};
/**
* Initialize the process of fetching the keys.
*
* @param {init} cmid Value of course module id of the quiz.
* @param {boolean} autoreconfigure Value of Moodle setting: quizaccess_seb/autoreconfigureseb.
*/
export const init = async(cmid, autoreconfigure = false) => {
// If the SafeExamBrowser object is instantiated, try and use it to fetch the access keys.
if (window.SafeExamBrowser !== null) {
await View.addLoadingAlert();
// If the SEB keys are already set, we can call our callback directly.
if (!isKeyEmpty(window.SafeExamBrowser.security.configKey) || !isKeyEmpty(window.SafeExamBrowser.security.browserExamKey)) {
safeExamBrowserKeysUpdated(cmid, autoreconfigure);
} else {
window.SafeExamBrowser.security.updateKeys(safeExamBrowserKeysUpdated);
}
}
};
+80
View File
@@ -0,0 +1,80 @@
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Manage the quiz views.
*
* @module quizaccess_seb/view
* @author Andrew Madden <andrewmadden@catalyst-au.net>
* @copyright 2021 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
import Notification from "core/notification";
import * as Templates from "core/templates";
import * as Str from "core/str";
import ModalAlert from "core/local/modal/alert";
/** @var SELECTOR List of CSS selectors. */
const SELECTOR = {
MAIN: '#region-main',
LOADING: '.seb-loading',
};
/** @var Template List of mustache templates. */
const TEMPLATE = {
LOADING: 'quizaccess_seb/loading',
};
/**
* Manages view when access has been granted.
*/
export const allowAccess = () => {
window.location.reload();
};
/**
* Add an alert to page to inform that Safe Exam Browser access is being checked.
*
* @return {Promise}
*/
export const addLoadingAlert = () => {
return Templates.render(TEMPLATE.LOADING, {}).then((html, js) => {
const alertRegion = window.document.querySelector(SELECTOR.MAIN);
return Templates.prependNodeContents(alertRegion, html, js);
}).catch(Notification.exception);
};
/**
* Remove the Safe Exam Browser access check alert from the page.
*/
export const clearLoadingAlert = () => {
const alert = window.document.querySelector(SELECTOR.LOADING);
if (alert) {
Templates.replaceNode(alert, '', '');
}
};
/**
* Display validation failed modal.
*/
export const showValidationFailedModal = () => {
ModalAlert.create({
title: Str.get_string('sebkeysvalidationfailed', 'quizaccess_seb'),
body: Str.get_string('invalidkeys', 'quizaccess_seb'),
large: false,
show: true,
}).catch(Notification.exception);
};