MCPcopy Create free account
hub / github.com/PrairieLearn/PrairieLearn / checkProp

Function checkProp

question-servers/freeform.js:313–347  ·  view source on GitHub ↗
(prop, type, presentPhases, editPhases)

Source from the content-addressed store, hash-verified

311 checkData: function(data, origData, phase) {
312 const checked = [];
313 const checkProp = (prop, type, presentPhases, editPhases) => {
314 if (!presentPhases.includes(phase)) return null;
315 if (!_.has(data, prop)) return '"' + prop + '" is missing from "data"';
316 if (type == 'integer') {
317 if (!_.isInteger(data[prop])) {
318 return 'data.' + prop + ' is not an integer: ' + String(data[prop]);
319 }
320 } else if (type == 'number') {
321 if (!_.isFinite(data[prop])) {
322 return 'data.' + prop + ' is not a number: ' + String(data[prop]);
323 }
324 } else if (type == 'string') {
325 if (!_.isString(data[prop])) {
326 return 'data.' + prop + ' is not a string: ' + String(data[prop]);
327 }
328 } else if (type == 'boolean') {
329 if (!_.isBoolean(data[prop])) {
330 return 'data.' + prop + ' is not a boolean: ' + String(data[prop]);
331 }
332 } else if (type == 'object') {
333 if (!_.isObject(data[prop])) {
334 return 'data.' + prop + ' is not an object: ' + String(data[prop]);
335 }
336 } else {
337 return 'invalid type: ' + String(type);
338 }
339 if (!editPhases.includes(phase)) {
340 if (!_.has(origData, prop)) return '"' + prop + '" is missing from "origData"';
341 if (!_.isEqual(data[prop], origData[prop])) {
342 return `data.${prop} has been illegally modified, new value: "${JSON.stringify(data[prop])}", original value: "${JSON.stringify(origData[prop])}"`;
343 }
344 }
345 checked.push(prop);
346 return null;
347 };
348
349 let err;
350 let allPhases = ['generate', 'prepare', 'render', 'parse', 'grade', 'test', 'file'];

Callers 1

freeform.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected