@universis/evaluations 1.0.8 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/models/ClassInstructorEvaluationEvent.json +16 -2
- package/dist/config/models/EvaluationAccessToken.json +15 -0
- package/dist/config/models/GenerateInstructorTokenAction.json +19 -2
- package/dist/config/models/SendInstructorTokenAction.json +52 -0
- package/dist/config/models/SendTokenAction.json +45 -0
- package/dist/models/access-token-model.js +4 -1
- package/dist/models/access-token-model.js.map +1 -1
- package/dist/models/class-instructor-evaluation-event-model.js +220 -8
- package/dist/models/class-instructor-evaluation-event-model.js.map +1 -1
- package/dist/models/evaluation-event-model.js +49 -11
- package/dist/models/evaluation-event-model.js.map +1 -1
- package/package.json +1 -1
- package/src/config/models/ClassInstructorEvaluationEvent.json +16 -2
- package/src/config/models/EvaluationAccessToken.json +15 -0
- package/src/config/models/GenerateInstructorTokenAction.json +19 -2
- package/src/config/models/SendInstructorTokenAction.json +52 -0
- package/src/config/models/SendTokenAction.json +45 -0
- package/src/models/access-token-model.js +8 -5
- package/src/models/class-instructor-evaluation-event-model.js +213 -1
- package/src/models/evaluation-event-model.js +45 -7
|
@@ -77,6 +77,9 @@ _data.EdmMapping.func('Current', 'EvaluationEvent'), _dec3 =
|
|
|
77
77
|
|
|
78
78
|
|
|
79
79
|
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
80
83
|
|
|
81
84
|
|
|
82
85
|
|
|
@@ -262,6 +265,41 @@ _data.EdmMapping.func('FormAttributes', _data.EdmType.CollectionOf('Object')), _
|
|
|
262
265
|
|
|
263
266
|
|
|
264
267
|
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
|
|
265
303
|
|
|
266
304
|
|
|
267
305
|
|
|
@@ -292,9 +330,8 @@ _data.EdmMapping.action('Evaluate', 'Object'), _dec(_class = (_class2 = class Ev
|
|
|
292
330
|
*/static async getCurrent(context) {// get evaluation key
|
|
293
331
|
const token = await EvaluationAccessToken.inspect(context, context.user && context.user.authenticationToken);if (token.active === false) {throw new _common.HttpTokenExpiredError('Evaluation access token has been expired or is invalid.');} // get evaluation event
|
|
294
332
|
// get current date
|
|
295
|
-
|
|
296
|
-
const
|
|
297
|
-
let evaluationEvent = await context.model('EvaluationEvent').where('id').equal(token.sub).and('date(startDate)').lowerOrEqual(startDate).and('date(endDate)').greaterOrEqual(endDate).and('eventStatus/alternateName').equal('EventOpened').silent().getTypedItem();if (evaluationEvent == null) {throw new _common.HttpNotFoundError('The specified evaluation cannot be found');}if (evaluationEvent.additionalType !== 'EvaluationEvent') {if (evaluationEvent.additionalType === 'ClassInstructorEvaluationEvent') {const event = await context.model('ClassInstructorEvaluationEvent').where('id').equal(token.sub).expand({ name: 'courseClassInstructor', options: { $expand: 'courseClass($expand=course,year,period),instructor' } }).silent().getTypedItem();const courseClass = event.courseClassInstructor.courseClass;const instructor = event.courseClassInstructor.instructor;evaluationEvent.courseClass = `${courseClass.course.displayCode}-${courseClass.title} (${courseClass.year.alternateName}-${courseClass.period.name}) `;evaluationEvent.instructor = `${instructor.familyName} ${instructor.givenName}`;} else {evaluationEvent = await evaluationEvent.silent().getAdditionalObject();}}return evaluationEvent;}async getForm() {const form = await this.property('evaluationDocument').getItem();const service = this.context.getApplication().getService(function PrivateContentService() {}); /**
|
|
333
|
+
let evaluationEvent = await context.model('EvaluationEvent').where('id').equal(token.sub).and('eventStatus/alternateName').equal('EventOpened').silent().getTypedItem();if (evaluationEvent == null) {throw new _common.HttpNotFoundError('The specified evaluation cannot be found');} // check dates
|
|
334
|
+
const currentDate = new Date().setHours(0, 0, 0, 0);const startDate = evaluationEvent.startDate.setHours(0, 0, 0, 0);const endDate = evaluationEvent.endDate.setHours(0, 0, 0, 0);if (startDate > currentDate || endDate < currentDate) {throw new _common.HttpNotFoundError('The specified evaluation cannot be found, it is expired or not started.');}if (evaluationEvent.additionalType !== 'EvaluationEvent') {if (evaluationEvent.additionalType === 'ClassInstructorEvaluationEvent') {const event = await context.model('ClassInstructorEvaluationEvent').where('id').equal(token.sub).expand({ name: 'courseClassInstructor', options: { $expand: 'courseClass($expand=course,year,period),instructor' } }).silent().getTypedItem();const courseClass = event.courseClassInstructor.courseClass;const instructor = event.courseClassInstructor.instructor;evaluationEvent.courseClass = `${courseClass.course.displayCode}-${courseClass.title} (${courseClass.year.alternateName}-${courseClass.period.name}) `;evaluationEvent.instructor = `${instructor.familyName} ${instructor.givenName}`;} else {evaluationEvent = await evaluationEvent.silent().getAdditionalObject();}}return evaluationEvent;}async getForm() {const form = await this.property('evaluationDocument').getItem();const service = this.context.getApplication().getService(function PrivateContentService() {}); /**
|
|
298
335
|
* @type {string}
|
|
299
336
|
*/const formPath = await new Promise((resolve, reject) => {service.resolvePhysicalPath(this.context, form, (err, physicalPath) => {if (err) {return reject(err);}return resolve(physicalPath);});});const readFileAsync = _util.default.promisify(_fs.default.readFile);let content = await readFileAsync(formPath);if (content == null) {throw new _common.HttpNotFoundError('Evaluation form cannot be found');}let buffer = Buffer.from(content, 'base64');let result;result = JSON.parse(buffer.toString('utf8'));try {result.properties = result.properties || {};Object.assign(result.properties, { name: form.resultType, _id: form.id, _event: this.id }); // post-processing
|
|
300
337
|
let shouldUpgrade = true;let model = this.context.model(form.resultType);if (model != null) {shouldUpgrade = (0, _semver.lt)(model.version, form.version);}if (shouldUpgrade) {// load for inspector
|
|
@@ -316,17 +353,18 @@ _data.EdmMapping.action('Evaluate', 'Object'), _dec(_class = (_class2 = class Ev
|
|
|
316
353
|
*/const context = this.context;const result = [];const form = await this.getForm();this.setParentLegend(form); // get model attributes
|
|
317
354
|
/**
|
|
318
355
|
* @type {DataConfigurationStrategy|*}
|
|
319
|
-
*/const dataConfiguration = context.getApplication().getConfiguration().getStrategy(_data.DataConfigurationStrategy);const dataTypes = dataConfiguration.dataTypes;const q = context.model(form.properties.name).asQueryable();const selectArguments = [];const model = dataConfiguration.model(form.properties.name);const attributes = model.fields;attributes.forEach((attribute) => {const key = this.findByKey(form.components, attribute.name);if (key) {attribute = Object.assign(attribute, { name: attribute.name, label: key.label });attribute.isNumber = false;attribute.legend = key.customProperties && key.customProperties.legend;if (Object.prototype.hasOwnProperty.call(dataTypes, attribute.type)) {attribute.isNumber = dataTypes[attribute.type].type === 'number';}selectArguments.push(`${attribute.name}`);
|
|
320
|
-
|
|
356
|
+
*/const dataConfiguration = context.getApplication().getConfiguration().getStrategy(_data.DataConfigurationStrategy);const dataTypes = dataConfiguration.dataTypes;const q = context.model(form.properties.name).asQueryable();const selectArguments = [];const model = dataConfiguration.model(form.properties.name);const attributes = model.fields;attributes.forEach((attribute) => {const key = this.findByKey(form.components, attribute.name);if (key) {attribute = Object.assign(attribute, { name: attribute.name, label: key.label });attribute.isNumber = false;attribute.legend = key.customProperties && key.customProperties.legend;if (Object.prototype.hasOwnProperty.call(dataTypes, attribute.type)) {attribute.isNumber = dataTypes[attribute.type].type === 'number';}selectArguments.push(`${attribute.name}`); // clear std,avg and responses from model attribute
|
|
357
|
+
attribute.std = 0;attribute.avg = 0;delete attribute.responses;result.push(attribute);}});const showResults = await this.showResults(context);if (selectArguments.length && showResults === true) {const responses = await q.select.apply(q, selectArguments).where('evaluationEvent').equal(this.getId()).silent().getAllItems();for (let i = 0; i < result.length; i++) {const qElement = result[i];qElement.responses = [];if (qElement.isNumber) {// add mean value and standard deviation
|
|
358
|
+
qElement.std = responses.length ? math.std(responses.map((x) => {return x[qElement.name];})) : 0;qElement.avg = responses.length ? math.mean(responses.map((x) => {return x[qElement.name];})) : 0;} else {qElement.responses = responses.map((x) => {return x[qElement.name];});}}}return result;}async showResults(context) {// this is a custom way to get permissions based on eventStatus and user groups
|
|
359
|
+
let showResults = true;let found = false;const eventStatusesResults = context.getConfiguration().getSourceAt('settings/evaluation/results/statuses') || [];const groupsAllowed = context.getConfiguration().getSourceAt('settings/evaluation/results/groupsAllowed') || [];if (eventStatusesResults.length > 0) {// check if eventStatus is allowed
|
|
360
|
+
if (groupsAllowed.length > 0) {// but first check if user belongs to allowed groups
|
|
361
|
+
const userName = context.interactiveUser ? context.interactiveUser.name : context.user.name;const user = await context.model('User').where('name').equal(userName).expand('groups').getItem();found = user.groups.some((r) => groupsAllowed.indexOf(r.name) >= 0);}if (!found) {const evaluationEvent = await context.model('EvaluationEvent').where('id').equal(this.getId()).select('id', 'eventStatus/alternateName as eventStatus').getItem();if (evaluationEvent == null) {throw new _common.HttpNotFoundError('The specified evaluation cannot be found');}showResults = eventStatusesResults.findIndex((x) => {return x === evaluationEvent.eventStatus;}) >= 0;}}return showResults;}findByKey(array, key) {for (let index = 0; index < array.length; index++) {const element = array[index];if (element.key === key) {return element;} else {if (element.components) {const found = this.findByKey(element.components, key);if (found) {return found;}}}}}setParentLegend(component) {if (Array.isArray(component.components)) {component.components.forEach((item) => {if (component.legend) {item.customProperties = item.customProperties || {};item.customProperties.legend = component.legend;}this.setParentLegend(item);});}}async evaluate(data) {const token = await EvaluationAccessToken.inspect(this.context, this.context.user.authenticationToken);if (token.active === false) {throw new _common.HttpTokenExpiredError('Evaluation access token has been expired or is invalid.');}if (this.id !== token.sub) {throw new _common.HttpBadRequestError('Evaluation access token is invalid');} // get evaluation form
|
|
321
362
|
const form = await this.getForm(); // get evaluation document
|
|
322
363
|
if (form == null) {throw new _common.HttpNotFoundError('Evaluation form cannot be found');} // get evaluation document
|
|
323
364
|
const evaluationDocument = await this.context.model(_evaluationDocumentModel.default).where('id').equal(form.properties._id).silent().getItem();if (evaluationDocument == null) {throw new _common.HttpNotFoundError('Evaluation document cannot be found');} // assign defaults
|
|
324
365
|
Object.assign(data, { evaluationEvent: this.id, evaluationDocument: evaluationDocument.id }); // and finally append evaluation
|
|
325
366
|
await this.context.model(evaluationDocument.resultType).on('after.save', (event, callback) => {const context = event.model.context;context.model(EvaluationAccessToken).where('access_token').equal(context.user && context.user.authenticationToken).silent().getItem().then((token) => {if (token == null) {throw new _common.HttpTokenExpiredError('Evaluation token is required');}return context.model(EvaluationAccessToken).silent().save({ access_token: token.access_token, expires: new Date(0), // set epoch date
|
|
326
|
-
used: true });
|
|
327
|
-
}).then(() => {
|
|
328
|
-
return callback();
|
|
329
|
-
}).catch((err) => {
|
|
367
|
+
used: true });}).then(() => {return callback();}).catch((err) => {
|
|
330
368
|
_common.TraceUtils.error('An error occurred while submitting evaluation');
|
|
331
369
|
return callback(err);
|
|
332
370
|
});
|
|
@@ -345,11 +383,11 @@ _data.EdmMapping.action('Evaluate', 'Object'), _dec(_class = (_class2 = class Ev
|
|
|
345
383
|
n += newItems.length;
|
|
346
384
|
items.push.apply(items, newItems);
|
|
347
385
|
}
|
|
348
|
-
await context.model('EvaluationAccessToken').save(items);
|
|
386
|
+
await context.model('EvaluationAccessToken').silent().save(items);
|
|
349
387
|
return n;
|
|
350
388
|
} else {
|
|
351
389
|
items = await EvaluationEvent.generateManyTokens(context, generateOptions);
|
|
352
|
-
await context.model('EvaluationAccessToken').save(items);
|
|
390
|
+
await context.model('EvaluationAccessToken').silent().save(items);
|
|
353
391
|
return items.length;
|
|
354
392
|
}
|
|
355
393
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/models/evaluation-event-model.js"],"names":["EvaluationAccessToken","require","math","EvaluationEvent","EdmMapping","entityType","func","EdmType","CollectionOf","param","action","DataObject","constructor","getCurrent","context","token","inspect","user","authenticationToken","active","HttpTokenExpiredError","startDate","Date","endDate","startOf","toDate","evaluationEvent","model","where","equal","sub","and","lowerOrEqual","greaterOrEqual","silent","getTypedItem","HttpNotFoundError","additionalType","event","expand","name","options","$expand","courseClass","courseClassInstructor","instructor","course","displayCode","title","year","alternateName","period","familyName","givenName","getAdditionalObject","getForm","form","property","getItem","service","getApplication","getService","PrivateContentService","formPath","Promise","resolve","reject","resolvePhysicalPath","err","physicalPath","readFileAsync","util","promisify","fs","readFile","content","buffer","Buffer","from","result","JSON","parse","toString","properties","Object","assign","resultType","_id","id","_event","shouldUpgrade","version","inspector","JsonFormInspector","source","view","hidden","fields","push","apply","type","getModel","editable","nullable","indexed","dataConfiguration","getConfiguration","getStrategy","DataConfigurationStrategy","privileges","splice","thisModel","Array","isArray","resultPrivileges","setModelDefinition","builder","ODataModelBuilder","addEntitySet","removeEntitySet","save","TraceUtils","error","HttpServerError","getResults","prepare","getAccessTokens","getFormAttributes","setParentLegend","dataTypes","q","asQueryable","selectArguments","attributes","forEach","attribute","key","findByKey","components","label","isNumber","legend","customProperties","prototype","hasOwnProperty","call","length","responses","select","getId","getAllItems","i","qElement","std","map","x","avg","mean","array","index","element","found","component","item","evaluate","data","HttpBadRequestError","evaluationDocument","EvaluationDocument","on","callback","then","access_token","expires","used","catch","generateTokens","generateOptions","items","n","newItems","itemGenerateOptions","generateManyTokens","Args","check","maximumGenerateTokens","LangUtils","parseInt","getSourceAt","module","exports"],"mappings":"aAAA;;;;;;AAMA;;;;;;;;AAQA;AACA;AACA;;;AAGA;AACA;AACA;AACA,wD,s2BAJA,MAAMA,qBAAqB,GAAGC,OAAO,CAAC,iCAAD,CAArC;AAKA,MAAMC,IAAI,GAAGD,OAAO,CAAC,QAAD,CAApB;;AAEA;AACA;AACA,G;;AAEME,e,WADLC,iBAAWC,UAAX,CAAsB,iBAAtB,C;;;;;;;;;;;;AAaID,iBAAWE,IAAX,CAAgB,SAAhB,EAA2B,iBAA3B,C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,QAAV,CAAmB7K,OAAO,CAAC4F,gBAAR,GAA2BkF,WAA3B,CAAuC,2CAAvC,CAAnB,CAA5B;AACA,QAAIH,qBAAqB,KAAK,CAA9B,EAAiC;AAC7BA,MAAAA,qBAAqB,GAAG,IAAxB;AACH;AACDF,iBAAKC,KAAL,CAAWL,CAAC,GAAGM,qBAAf,EAAuC,gEAA+DA,qBAAsB,GAA5H;AACA,UAAMP,KAAK,GAAG,EAAd;AACA;AACA,SAAK,IAAInB,KAAK,GAAG,CAAjB,EAAoBA,KAAK,GAAGoB,CAA5B,EAA+BpB,KAAK,EAApC,EAAwC;AACpCmB,MAAAA,KAAK,CAAChF,IAAN,CAAW;AACPxE,QAAAA,eAAe,EAAEuJ,eAAe,CAACvJ,eAD1B;AAEPmJ,QAAAA,OAAO,EAAEI,eAAe,CAACJ,OAFlB,EAAX;;AAIH;AACD,WAAOK,KAAP;AACH,GA7VoC,C;;AA+VzCW,MAAM,CAACC,OAAP,GAAiB3L,eAAjB","sourcesContent":["import { HttpNotFoundError, HttpTokenExpiredError, HttpServerError,\n TraceUtils, \n HttpBadRequestError,\n Args,\n LangUtils} from '@themost/common';\n\nimport {\n DataConfigurationStrategy,\n DataContext,\n DataObject,\n EdmMapping,\n EdmType,\n ODataModelBuilder\n} from '@themost/data';\nimport { HttpContext } from '@themost/web';\nimport { JsonFormInspector } from '@themost/form-inspector';\nimport EvaluationDocument from './evaluation-document-model';\n\nconst EvaluationAccessToken = require('./evaluation-access-token-model');\nimport {lt} from 'semver';\nimport util from \"util\";\nimport fs from \"fs\";\nimport moment from \"moment\";\nconst math = require('mathjs');\n\n/**\n * @class\n */\n@EdmMapping.entityType('EvaluationEvent')\nclass EvaluationEvent extends DataObject {\n /**\n * @constructor\n */\n constructor() {\n super();\n }\n\n /**\n * Get current evaluation based on the evaluation key contained in Evaluation-Key HTTP header\n * @param {HttpContext} context\n */\n @EdmMapping.func('Current', 'EvaluationEvent')\n static async getCurrent(context) {\n // get evaluation key\n const token = await EvaluationAccessToken.inspect(context, context.user && context.user.authenticationToken);\n if (token.active === false) {\n throw new HttpTokenExpiredError('Evaluation access token has been expired or is invalid.');\n }\n // get evaluation event\n // get current date\n const startDate = new Date(); // get current date with time\n const endDate = moment(new Date()).startOf('day').toDate(); // get only date format\n let evaluationEvent = await context.model('EvaluationEvent')\n .where('id').equal(token.sub)\n .and('date(startDate)').lowerOrEqual(startDate)\n .and('date(endDate)').greaterOrEqual(endDate)\n .and('eventStatus/alternateName').equal('EventOpened')\n .silent().getTypedItem();\n if (evaluationEvent == null) {\n throw new HttpNotFoundError('The specified evaluation cannot be found');\n }\n if (evaluationEvent.additionalType !== 'EvaluationEvent') {\n if (evaluationEvent.additionalType === 'ClassInstructorEvaluationEvent') {\n const event = await context.model('ClassInstructorEvaluationEvent')\n .where('id').equal(token.sub)\n .expand({\n name: 'courseClassInstructor',\n options: {\n $expand: 'courseClass($expand=course,year,period),instructor'\n }\n })\n .silent().getTypedItem();\n const courseClass= event.courseClassInstructor.courseClass;\n const instructor = event.courseClassInstructor.instructor;\n evaluationEvent.courseClass = `${courseClass.course.displayCode}-${courseClass.title} (${courseClass.year.alternateName}-${courseClass.period.name}) `;\n evaluationEvent.instructor = `${instructor.familyName} ${instructor.givenName}`;\n } else {\n evaluationEvent = await evaluationEvent.silent().getAdditionalObject();\n }\n }\n return evaluationEvent;\n }\n\n @EdmMapping.func('form', 'Object')\n async getForm() {\n const form = await this.property('evaluationDocument').getItem();\n const service = this.context.getApplication().getService(function PrivateContentService(){});\n /**\n * @type {string}\n */\n const formPath = await new Promise((resolve, reject) => {\n service.resolvePhysicalPath(this.context, form, (err, physicalPath) => {\n if (err) {\n return reject(err);\n }\n return resolve(physicalPath);\n })\n });\n const readFileAsync = util.promisify(fs.readFile);\n let content = await readFileAsync(formPath);\n if (content == null) {\n throw new HttpNotFoundError('Evaluation form cannot be found');\n }\n let buffer = Buffer.from(content,'base64');\n let result;\n result = JSON.parse(buffer.toString('utf8'));\n\n try {\n result.properties = result.properties || {};\n Object.assign(result.properties, {\n name: form.resultType,\n _id: form.id,\n _event: this.id\n });\n // post-processing\n let shouldUpgrade = true;\n let model = this.context.model(form.resultType);\n if (model != null) {\n shouldUpgrade = lt(model.version, form.version)\n }\n if (shouldUpgrade) {\n // load for inspector\n const inspector = new JsonFormInspector();\n model = inspector.inspect(result);\n // post processing steps\n Object.assign(model, {\n source: form.resultType, // add source from evaluation document e.g. Evaluation1\n view: form.resultType, // add view from evaluation document e.g. Evaluation1\n version: model.version ,// set version (follow updates)\n hidden: true\n });\n // add evaluation event and evaluation document associations\n // for further processing of evaluation results\n model.fields.push.apply(model.fields, [\n {\n name: 'evaluationEvent',\n type: this.getModel().name,\n editable: false,\n nullable: false,\n indexed: true,\n }\n ]);\n // reset privileges\n /**\n * @type {DataConfigurationStrategy|*}\n */\n const dataConfiguration = this.context.getApplication()\n .getConfiguration().getStrategy(DataConfigurationStrategy);\n\n model.privileges.splice(0);\n // get resultPrivileges\n const thisModel = dataConfiguration.model(this.getModel().name);\n\n model.privileges.push.apply(model.privileges, [\n {\n \"mask\": 15,\n \"type\": \"global\"\n },\n {\n \"mask\": 1,\n \"type\": \"global\",\n \"account\": \"Administrators\"\n }\n ]);\n // add extra privileges\n if (Array.isArray(thisModel.resultPrivileges)) {\n model.privileges.push.apply(model.privileges, thisModel.resultPrivileges);\n }\n dataConfiguration.setModelDefinition(model);\n // add entity set\n const builder = this.context.getApplication().getService(ODataModelBuilder);\n builder.addEntitySet(model.name, model.name);\n if (model.hidden) {\n builder.removeEntitySet(model.name);\n }\n // update version\n form.version= model.version;\n await this.context.model('EvaluationDocument').silent().save(form);\n }\n return result;\n } catch (err) {\n TraceUtils.error(`Error while decoding evaluation form ${form.id} content.`);\n TraceUtils.error(err);\n throw new HttpServerError('An error occurred while decoding evaluation form.');\n }\n }\n\n @EdmMapping.func('Results', EdmType.CollectionOf('Object'))\n async getResults() {\n const form = await this.getForm();\n return this.context.model(form.properties.name).where('evaluationEvent').equal(this.id).prepare();\n }\n\n @EdmMapping.func('Tokens', EdmType.CollectionOf('EvaluationAccessToken'))\n async getAccessTokens() {\n return this.context.model('EvaluationAccessToken').where('evaluationEvent').equal(this.id).prepare();\n }\n\n @EdmMapping.func('FormAttributes', EdmType.CollectionOf('Object'))\n async getFormAttributes() {\n /**\n * @type {DataContext|*}\n */\n const context = this.context;\n const result = [];\n const form = await this.getForm();\n this.setParentLegend(form);\n // get model attributes\n /**\n * @type {DataConfigurationStrategy|*}\n */\n const dataConfiguration = context.getApplication()\n .getConfiguration().getStrategy(DataConfigurationStrategy);\n const dataTypes = dataConfiguration.dataTypes;\n const q = context.model(form.properties.name).asQueryable();\n const selectArguments = [];\n const model = dataConfiguration.model(form.properties.name);\n const attributes = model.fields;\n attributes.forEach(attribute => {\n const key = this.findByKey(form.components, attribute.name);\n if (key) {\n attribute = Object.assign(attribute, {\n name: attribute.name, label: key.label\n });\n attribute.isNumber = false;\n attribute.legend = key.customProperties && key.customProperties.legend;\n if (Object.prototype.hasOwnProperty.call(dataTypes, attribute.type)) {\n attribute.isNumber = dataTypes[attribute.type].type === 'number';\n }\n selectArguments.push(`${attribute.name}`);\n result.push(attribute);\n }\n\n });\n if (selectArguments.length) {\n const responses = await q.select.apply(q, selectArguments).where('evaluationEvent').equal(this.getId()).silent().getAllItems();\n for (let i = 0; i < result.length; i++) {\n const qElement = result[i];\n qElement.responses=[];\n if (qElement.isNumber) {\n // add mean value and standard deviation\n qElement.std = responses.length? math.std(responses.map(x => {\n return x[qElement.name];\n })):0;\n qElement.avg = responses.length? math.mean(responses.map(x => {\n return x[qElement.name];\n })):0;\n } else {\n qElement.responses = responses.map(x => {\n return x[qElement.name];\n });\n }\n }\n }\n return result;\n }\n\n findByKey(array, key) {\n for (let index = 0; index < array.length; index++) {\n const element = array[index];\n if (element.key === key) {\n return element;\n } else {\n if (element.components) {\n const found = this.findByKey(element.components, key);\n if (found) {\n return found;\n }\n }\n }\n }\n }\n\n setParentLegend(component) {\n if (Array.isArray(component.components)) {\n component.components.forEach(item => {\n if (component.legend) {\n item.customProperties = item.customProperties || {};\n item.customProperties.legend = component.legend;\n }\n this.setParentLegend(item);\n });\n }\n }\n\n @EdmMapping.param('data', 'Object', false, true)\n @EdmMapping.action('Evaluate', 'Object')\n async evaluate(data) {\n const token = await EvaluationAccessToken.inspect(this.context, this.context.user.authenticationToken);\n if (token.active === false) {\n throw new HttpTokenExpiredError('Evaluation access token has been expired or is invalid.');\n }\n if (this.id !== token.sub) {\n throw new HttpBadRequestError('Evaluation access token is invalid');\n }\n // get evaluation form\n const form = await this.getForm();\n // get evaluation document\n if (form == null) {\n throw new HttpNotFoundError('Evaluation form cannot be found');\n }\n // get evaluation document\n const evaluationDocument = await this.context.model(EvaluationDocument)\n .where('id').equal(form.properties._id)\n .silent().getItem();\n if (evaluationDocument == null) {\n throw new HttpNotFoundError('Evaluation document cannot be found');\n }\n // assign defaults\n Object.assign(data, {\n evaluationEvent: this.id,\n evaluationDocument: evaluationDocument.id\n });\n // and finally append evaluation\n await this.context.model(evaluationDocument.resultType).on('after.save', (event, callback) => {\n const context = event.model.context;\n context.model(EvaluationAccessToken).where('access_token').equal(context.user && context.user.authenticationToken)\n .silent().getItem().then((token) => {\n if (token == null) {\n throw new HttpTokenExpiredError('Evaluation token is required');\n }\n return context.model(EvaluationAccessToken).silent().save({\n access_token: token.access_token,\n expires: new Date(0), // set epoch date\n used: true\n });\n }).then(() => {\n return callback();\n }).catch((err) => {\n TraceUtils.error('An error occurred while submitting evaluation');\n return callback(err);\n });\n }).silent().save(data);\n return data;\n }\n\n static async generateTokens(context, generateOptions) {\n let items = [];\n if (Array.isArray(generateOptions)) {\n let n = 0;\n let newItems;\n // eslint-disable-next-line no-unused-vars\n for(let itemGenerateOptions of generateOptions) {\n newItems = await EvaluationEvent.generateManyTokens(context, itemGenerateOptions);\n n += newItems.length;\n items.push.apply(items, newItems);\n }\n await context.model('EvaluationAccessToken').save(items);\n return n\n } else {\n items = await EvaluationEvent.generateManyTokens(context, generateOptions);\n await context.model('EvaluationAccessToken').save(items);\n return items.length;\n } \n }\n /**\n * Generates a number of access tokens for the given event \n * @param {DataContext} context\n * @param {{evaluationEvent: number, n: number, expires?: DateTime}} generateOptions\n */\n static async generateManyTokens(context, generateOptions) {\n const n = generateOptions.n;\n Args.check(typeof n === 'number', 'Expected a number greater than zero');\n Args.check(n > 0, 'The number of access tokens must be greater than zero');\n let maximumGenerateTokens = LangUtils.parseInt(context.getConfiguration().getSourceAt('settings/evaluation/maximumGenerateTokens'));\n if (maximumGenerateTokens === 0) {\n maximumGenerateTokens = 1000;\n }\n Args.check(n < maximumGenerateTokens, `The specified number of tokens exceeded the maximum allowed (${maximumGenerateTokens})`);\n const items = [];\n // generate tokens\n for (let index = 0; index < n; index++) {\n items.push({\n evaluationEvent: generateOptions.evaluationEvent,\n expires: generateOptions.expires\n });\n }\n return items;\n }\n}\nmodule.exports = EvaluationEvent;\n"],"file":"evaluation-event-model.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/models/evaluation-event-model.js"],"names":["EvaluationAccessToken","require","math","EvaluationEvent","EdmMapping","entityType","func","EdmType","CollectionOf","param","action","DataObject","constructor","getCurrent","context","token","inspect","user","authenticationToken","active","HttpTokenExpiredError","evaluationEvent","model","where","equal","sub","and","silent","getTypedItem","HttpNotFoundError","currentDate","Date","setHours","startDate","endDate","additionalType","event","expand","name","options","$expand","courseClass","courseClassInstructor","instructor","course","displayCode","title","year","alternateName","period","familyName","givenName","getAdditionalObject","getForm","form","property","getItem","service","getApplication","getService","PrivateContentService","formPath","Promise","resolve","reject","resolvePhysicalPath","err","physicalPath","readFileAsync","util","promisify","fs","readFile","content","buffer","Buffer","from","result","JSON","parse","toString","properties","Object","assign","resultType","_id","id","_event","shouldUpgrade","version","inspector","JsonFormInspector","source","view","hidden","fields","push","apply","type","getModel","editable","nullable","indexed","dataConfiguration","getConfiguration","getStrategy","DataConfigurationStrategy","privileges","splice","thisModel","Array","isArray","resultPrivileges","setModelDefinition","builder","ODataModelBuilder","addEntitySet","removeEntitySet","save","TraceUtils","error","HttpServerError","getResults","prepare","getAccessTokens","getFormAttributes","setParentLegend","dataTypes","q","asQueryable","selectArguments","attributes","forEach","attribute","key","findByKey","components","label","isNumber","legend","customProperties","prototype","hasOwnProperty","call","std","avg","responses","showResults","length","select","getId","getAllItems","i","qElement","map","x","mean","found","eventStatusesResults","getSourceAt","groupsAllowed","userName","interactiveUser","groups","some","r","indexOf","findIndex","eventStatus","array","index","element","component","item","evaluate","data","HttpBadRequestError","evaluationDocument","EvaluationDocument","on","callback","then","access_token","expires","used","catch","generateTokens","generateOptions","items","n","newItems","itemGenerateOptions","generateManyTokens","Args","check","maximumGenerateTokens","LangUtils","parseInt","module","exports"],"mappings":"aAAA;;;;;;AAMA;;;;;;;;AAQA;AACA;AACA;;;AAGA;AACA;AACA;AACA,wD,s2BAJA,MAAMA,qBAAqB,GAAGC,OAAO,CAAC,iCAAD,CAArC;AAKA,MAAMC,IAAI,GAAGD,OAAO,CAAC,QAAD,CAApB;;AAEA;AACA;AACA,G;;AAEME,e,WADLC,iBAAWC,UAAX,CAAsB,iBAAtB,C;;;;;;;;;;;;AAaID,iBAAWE,IAAX,CAAgB,SAAhB,EAA2B,iBAA3B,C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CAF,iBAAWE,IAAX,CAAgB,MAAhB,EAAwB,QAAxB,C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwGAF,iBAAWE,IAAX,CAAgB,SAAhB,EAA2BC,cAAQC,YAAR,CAAqB,QAArB,CAA3B,C;;;;;;AAMAJ,iBAAWE,IAAX,CAAgB,QAAhB,EAA0BC,cAAQC,YAAR,CAAqB,uBAArB,CAA1B,C;;;;;AAKAJ,iBAAWE,IAAX,CAAgB,gBAAhB,EAAkCC,cAAQ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A;AACA;AACmC,eAAlB4C,kBAAkB,CAAClL,OAAD,EAAU6K,eAAV,EAA2B;AACtD,UAAME,CAAC,GAAGF,eAAe,CAACE,CAA1B;AACAI,iBAAKC,KAAL,CAAW,OAAOL,CAAP,KAAa,QAAxB,EAAkC,qCAAlC;AACAI,iBAAKC,KAAL,CAAWL,CAAC,GAAG,CAAf,EAAkB,uDAAlB;AACA,QAAIM,qBAAqB,GAAGC,kBAAUC,QAAV,CAAmBvL,OAAO,CAAC0F,gBAAR,GAA2BuD,WAA3B,CAAuC,2CAAvC,CAAnB,CAA5B;AACA,QAAIoC,qBAAqB,KAAK,CAA9B,EAAiC;AAC7BA,MAAAA,qBAAqB,GAAG,IAAxB;AACH;AACDF,iBAAKC,KAAL,CAAWL,CAAC,GAAGM,qBAAf,EAAuC,gEAA+DA,qBAAsB,GAA5H;AACA,UAAMP,KAAK,GAAG,EAAd;AACA;AACA,SAAK,IAAIlB,KAAK,GAAG,CAAjB,EAAoBA,KAAK,GAAGmB,CAA5B,EAA+BnB,KAAK,EAApC,EAAwC;AACpCkB,MAAAA,KAAK,CAAC5F,IAAN,CAAW;AACP3E,QAAAA,eAAe,EAAEsK,eAAe,CAACtK,eAD1B;AAEPkK,QAAAA,OAAO,EAAEI,eAAe,CAACJ,OAFlB,EAAX;;AAIH;AACD,WAAOK,KAAP;AACH,GAnYoC,C;;AAqYzCU,MAAM,CAACC,OAAP,GAAiBpM,eAAjB","sourcesContent":["import { HttpNotFoundError, HttpTokenExpiredError, HttpServerError,\n TraceUtils, \n HttpBadRequestError,\n Args,\n LangUtils} from '@themost/common';\n\nimport {\n DataConfigurationStrategy,\n DataContext,\n DataObject,\n EdmMapping,\n EdmType,\n ODataModelBuilder\n} from '@themost/data';\nimport { HttpContext } from '@themost/web';\nimport { JsonFormInspector } from '@themost/form-inspector';\nimport EvaluationDocument from './evaluation-document-model';\n\nconst EvaluationAccessToken = require('./evaluation-access-token-model');\nimport {lt} from 'semver';\nimport util from \"util\";\nimport fs from \"fs\";\nimport moment from \"moment\";\nconst math = require('mathjs');\n\n/**\n * @class\n */\n@EdmMapping.entityType('EvaluationEvent')\nclass EvaluationEvent extends DataObject {\n /**\n * @constructor\n */\n constructor() {\n super();\n }\n\n /**\n * Get current evaluation based on the evaluation key contained in Evaluation-Key HTTP header\n * @param {HttpContext} context\n */\n @EdmMapping.func('Current', 'EvaluationEvent')\n static async getCurrent(context) {\n // get evaluation key\n const token = await EvaluationAccessToken.inspect(context, context.user && context.user.authenticationToken);\n if (token.active === false) {\n throw new HttpTokenExpiredError('Evaluation access token has been expired or is invalid.');\n }\n // get evaluation event\n // get current date\n let evaluationEvent = await context.model('EvaluationEvent')\n .where('id').equal(token.sub)\n .and('eventStatus/alternateName').equal('EventOpened')\n .silent().getTypedItem();\n if (evaluationEvent == null) {\n throw new HttpNotFoundError('The specified evaluation cannot be found');\n }\n // check dates\n const currentDate = new Date().setHours(0,0,0,0);\n const startDate = evaluationEvent.startDate.setHours(0,0,0,0);\n const endDate = evaluationEvent.endDate.setHours(0,0,0,0);\n if (startDate>currentDate || endDate<currentDate) {\n throw new HttpNotFoundError('The specified evaluation cannot be found, it is expired or not started.');\n }\n if (evaluationEvent.additionalType !== 'EvaluationEvent') {\n if (evaluationEvent.additionalType === 'ClassInstructorEvaluationEvent') {\n const event = await context.model('ClassInstructorEvaluationEvent')\n .where('id').equal(token.sub)\n .expand({\n name: 'courseClassInstructor',\n options: {\n $expand: 'courseClass($expand=course,year,period),instructor'\n }\n })\n .silent().getTypedItem();\n const courseClass= event.courseClassInstructor.courseClass;\n const instructor = event.courseClassInstructor.instructor;\n evaluationEvent.courseClass = `${courseClass.course.displayCode}-${courseClass.title} (${courseClass.year.alternateName}-${courseClass.period.name}) `;\n evaluationEvent.instructor = `${instructor.familyName} ${instructor.givenName}`;\n } else {\n evaluationEvent = await evaluationEvent.silent().getAdditionalObject();\n }\n }\n return evaluationEvent;\n }\n\n @EdmMapping.func('form', 'Object')\n async getForm() {\n const form = await this.property('evaluationDocument').getItem();\n const service = this.context.getApplication().getService(function PrivateContentService(){});\n /**\n * @type {string}\n */\n const formPath = await new Promise((resolve, reject) => {\n service.resolvePhysicalPath(this.context, form, (err, physicalPath) => {\n if (err) {\n return reject(err);\n }\n return resolve(physicalPath);\n })\n });\n const readFileAsync = util.promisify(fs.readFile);\n let content = await readFileAsync(formPath);\n if (content == null) {\n throw new HttpNotFoundError('Evaluation form cannot be found');\n }\n let buffer = Buffer.from(content,'base64');\n let result;\n result = JSON.parse(buffer.toString('utf8'));\n\n try {\n result.properties = result.properties || {};\n Object.assign(result.properties, {\n name: form.resultType,\n _id: form.id,\n _event: this.id\n });\n // post-processing\n let shouldUpgrade = true;\n let model = this.context.model(form.resultType);\n if (model != null) {\n shouldUpgrade = lt(model.version, form.version)\n }\n if (shouldUpgrade) {\n // load for inspector\n const inspector = new JsonFormInspector();\n model = inspector.inspect(result);\n // post processing steps\n Object.assign(model, {\n source: form.resultType, // add source from evaluation document e.g. Evaluation1\n view: form.resultType, // add view from evaluation document e.g. Evaluation1\n version: model.version ,// set version (follow updates)\n hidden: true\n });\n // add evaluation event and evaluation document associations\n // for further processing of evaluation results\n model.fields.push.apply(model.fields, [\n {\n name: 'evaluationEvent',\n type: this.getModel().name,\n editable: false,\n nullable: false,\n indexed: true,\n }\n ]);\n // reset privileges\n /**\n * @type {DataConfigurationStrategy|*}\n */\n const dataConfiguration = this.context.getApplication()\n .getConfiguration().getStrategy(DataConfigurationStrategy);\n\n model.privileges.splice(0);\n // get resultPrivileges\n const thisModel = dataConfiguration.model(this.getModel().name);\n\n model.privileges.push.apply(model.privileges, [\n {\n \"mask\": 15,\n \"type\": \"global\"\n },\n {\n \"mask\": 1,\n \"type\": \"global\",\n \"account\": \"Administrators\"\n }\n ]);\n // add extra privileges\n if (Array.isArray(thisModel.resultPrivileges)) {\n model.privileges.push.apply(model.privileges, thisModel.resultPrivileges);\n }\n dataConfiguration.setModelDefinition(model);\n // add entity set\n const builder = this.context.getApplication().getService(ODataModelBuilder);\n builder.addEntitySet(model.name, model.name);\n if (model.hidden) {\n builder.removeEntitySet(model.name);\n }\n // update version\n form.version= model.version;\n await this.context.model('EvaluationDocument').silent().save(form);\n }\n return result;\n } catch (err) {\n TraceUtils.error(`Error while decoding evaluation form ${form.id} content.`);\n TraceUtils.error(err);\n throw new HttpServerError('An error occurred while decoding evaluation form.');\n }\n }\n\n @EdmMapping.func('Results', EdmType.CollectionOf('Object'))\n async getResults() {\n const form = await this.getForm();\n return this.context.model(form.properties.name).where('evaluationEvent').equal(this.id).prepare();\n }\n\n @EdmMapping.func('Tokens', EdmType.CollectionOf('EvaluationAccessToken'))\n async getAccessTokens() {\n return this.context.model('EvaluationAccessToken').where('evaluationEvent').equal(this.id).prepare();\n }\n\n @EdmMapping.func('FormAttributes', EdmType.CollectionOf('Object'))\n async getFormAttributes() {\n /**\n * @type {DataContext|*}\n */\n const context = this.context;\n const result = [];\n const form = await this.getForm();\n this.setParentLegend(form);\n // get model attributes\n /**\n * @type {DataConfigurationStrategy|*}\n */\n const dataConfiguration = context.getApplication()\n .getConfiguration().getStrategy(DataConfigurationStrategy);\n const dataTypes = dataConfiguration.dataTypes;\n const q = context.model(form.properties.name).asQueryable();\n const selectArguments = [];\n const model = dataConfiguration.model(form.properties.name);\n const attributes = model.fields;\n attributes.forEach(attribute => {\n const key = this.findByKey(form.components, attribute.name);\n if (key) {\n attribute = Object.assign(attribute, {\n name: attribute.name, label: key.label\n });\n attribute.isNumber = false;\n attribute.legend = key.customProperties && key.customProperties.legend;\n if (Object.prototype.hasOwnProperty.call(dataTypes, attribute.type)) {\n attribute.isNumber = dataTypes[attribute.type].type === 'number';\n }\n selectArguments.push(`${attribute.name}`);\n // clear std,avg and responses from model attribute\n attribute.std = 0;\n attribute.avg = 0;\n delete attribute.responses;\n result.push(attribute);\n }\n\n });\n const showResults = await this.showResults(context);\n if (selectArguments.length && showResults === true) {\n const responses = await q.select.apply(q, selectArguments).where('evaluationEvent').equal(this.getId()).silent().getAllItems();\n for (let i = 0; i < result.length; i++) {\n const qElement = result[i];\n qElement.responses=[];\n if (qElement.isNumber) {\n // add mean value and standard deviation\n qElement.std = responses.length? math.std(responses.map(x => {\n return x[qElement.name];\n })):0;\n qElement.avg = responses.length? math.mean(responses.map(x => {\n return x[qElement.name];\n })):0;\n } else {\n qElement.responses = responses.map(x => {\n return x[qElement.name];\n });\n }\n }\n }\n return result;\n }\n\n async showResults (context) {\n\n // this is a custom way to get permissions based on eventStatus and user groups\n let showResults = true;\n let found = false;\n const eventStatusesResults = context.getConfiguration().getSourceAt('settings/evaluation/results/statuses') || [];\n const groupsAllowed = context.getConfiguration().getSourceAt('settings/evaluation/results/groupsAllowed') || [];\n if (eventStatusesResults.length > 0) {\n // check if eventStatus is allowed\n if (groupsAllowed.length > 0) {\n // but first check if user belongs to allowed groups\n const userName = context.interactiveUser ? context.interactiveUser.name : context.user.name;\n const user = await context.model('User').where('name').equal(userName).expand('groups').getItem();\n found = user.groups.some(r => groupsAllowed.indexOf(r.name) >= 0);\n }\n if (!found) {\n const evaluationEvent = await context.model('EvaluationEvent').where('id').equal(this.getId())\n .select('id', 'eventStatus/alternateName as eventStatus')\n .getItem();\n if (evaluationEvent == null) {\n throw new HttpNotFoundError('The specified evaluation cannot be found');\n }\n showResults = eventStatusesResults.findIndex(x => {\n return x === evaluationEvent.eventStatus;\n }) >= 0;\n }\n }\n return showResults;\n }\n\n findByKey(array, key) {\n for (let index = 0; index < array.length; index++) {\n const element = array[index];\n if (element.key === key) {\n return element;\n } else {\n if (element.components) {\n const found = this.findByKey(element.components, key);\n if (found) {\n return found;\n }\n }\n }\n }\n }\n\n setParentLegend(component) {\n if (Array.isArray(component.components)) {\n component.components.forEach(item => {\n if (component.legend) {\n item.customProperties = item.customProperties || {};\n item.customProperties.legend = component.legend;\n }\n this.setParentLegend(item);\n });\n }\n }\n\n @EdmMapping.param('data', 'Object', false, true)\n @EdmMapping.action('Evaluate', 'Object')\n async evaluate(data) {\n const token = await EvaluationAccessToken.inspect(this.context, this.context.user.authenticationToken);\n if (token.active === false) {\n throw new HttpTokenExpiredError('Evaluation access token has been expired or is invalid.');\n }\n if (this.id !== token.sub) {\n throw new HttpBadRequestError('Evaluation access token is invalid');\n }\n // get evaluation form\n const form = await this.getForm();\n // get evaluation document\n if (form == null) {\n throw new HttpNotFoundError('Evaluation form cannot be found');\n }\n // get evaluation document\n const evaluationDocument = await this.context.model(EvaluationDocument)\n .where('id').equal(form.properties._id)\n .silent().getItem();\n if (evaluationDocument == null) {\n throw new HttpNotFoundError('Evaluation document cannot be found');\n }\n // assign defaults\n Object.assign(data, {\n evaluationEvent: this.id,\n evaluationDocument: evaluationDocument.id\n });\n // and finally append evaluation\n await this.context.model(evaluationDocument.resultType).on('after.save', (event, callback) => {\n const context = event.model.context;\n context.model(EvaluationAccessToken).where('access_token').equal(context.user && context.user.authenticationToken)\n .silent().getItem().then((token) => {\n if (token == null) {\n throw new HttpTokenExpiredError('Evaluation token is required');\n }\n return context.model(EvaluationAccessToken).silent().save({\n access_token: token.access_token,\n expires: new Date(0), // set epoch date\n used: true\n });\n }).then(() => {\n return callback();\n }).catch((err) => {\n TraceUtils.error('An error occurred while submitting evaluation');\n return callback(err);\n });\n }).silent().save(data);\n return data;\n }\n\n static async generateTokens(context, generateOptions) {\n let items = [];\n if (Array.isArray(generateOptions)) {\n let n = 0;\n let newItems;\n // eslint-disable-next-line no-unused-vars\n for(let itemGenerateOptions of generateOptions) {\n newItems = await EvaluationEvent.generateManyTokens(context, itemGenerateOptions);\n n += newItems.length;\n items.push.apply(items, newItems);\n }\n await context.model('EvaluationAccessToken').silent().save(items);\n return n\n } else {\n items = await EvaluationEvent.generateManyTokens(context, generateOptions);\n await context.model('EvaluationAccessToken').silent().save(items);\n return items.length;\n } \n }\n /**\n * Generates a number of access tokens for the given event \n * @param {DataContext} context\n * @param {{evaluationEvent: number, n: number, expires?: DateTime}} generateOptions\n */\n static async generateManyTokens(context, generateOptions) {\n const n = generateOptions.n;\n Args.check(typeof n === 'number', 'Expected a number greater than zero');\n Args.check(n > 0, 'The number of access tokens must be greater than zero');\n let maximumGenerateTokens = LangUtils.parseInt(context.getConfiguration().getSourceAt('settings/evaluation/maximumGenerateTokens'));\n if (maximumGenerateTokens === 0) {\n maximumGenerateTokens = 1000;\n }\n Args.check(n < maximumGenerateTokens, `The specified number of tokens exceeded the maximum allowed (${maximumGenerateTokens})`);\n const items = [];\n // generate tokens\n for (let index = 0; index < n; index++) {\n items.push({\n evaluationEvent: generateOptions.evaluationEvent,\n expires: generateOptions.expires\n });\n }\n return items;\n }\n}\nmodule.exports = EvaluationEvent;\n"],"file":"evaluation-event-model.js"}
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"sealed": false,
|
|
8
8
|
"inherits": "EvaluationEvent",
|
|
9
9
|
"classPath": "./models/class-instructor-evaluation-event-model",
|
|
10
|
-
"version": "1.
|
|
10
|
+
"version": "1.2",
|
|
11
11
|
"fields": [
|
|
12
12
|
{
|
|
13
13
|
"@id": "http://schema.org/courseClassInstructor",
|
|
@@ -54,7 +54,21 @@
|
|
|
54
54
|
"many": true,
|
|
55
55
|
"mapping": {
|
|
56
56
|
"parentModel": "ClassInstructorEvaluationEvent",
|
|
57
|
-
"childModel": "
|
|
57
|
+
"childModel": "GenerateInstructorTokenAction",
|
|
58
|
+
"parentField": "id",
|
|
59
|
+
"childField": "event",
|
|
60
|
+
"cascade": "delete",
|
|
61
|
+
"associationType": "association"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"name": "sendActions",
|
|
66
|
+
"title": "Send token actions",
|
|
67
|
+
"type": "SendTokenAction",
|
|
68
|
+
"many": true,
|
|
69
|
+
"mapping": {
|
|
70
|
+
"parentModel": "ClassInstructorEvaluationEvent",
|
|
71
|
+
"childModel": "SendInstructorTokenAction",
|
|
58
72
|
"parentField": "id",
|
|
59
73
|
"childField": "event",
|
|
60
74
|
"cascade": "delete",
|
|
@@ -106,6 +106,21 @@
|
|
|
106
106
|
"mask": 15,
|
|
107
107
|
"type": "global",
|
|
108
108
|
"account": "Administrators"
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"mask": 1,
|
|
112
|
+
"type": "global",
|
|
113
|
+
"account": "QualityAssuranceDepartment"
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"mask": 1,
|
|
117
|
+
"type": "global",
|
|
118
|
+
"account": "QualityAssuranceUnit"
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"mask": 1,
|
|
122
|
+
"type": "global",
|
|
123
|
+
"account": "Registrar"
|
|
109
124
|
}
|
|
110
125
|
],
|
|
111
126
|
"eventListeners": [
|
|
@@ -28,13 +28,30 @@
|
|
|
28
28
|
],
|
|
29
29
|
"privileges": [
|
|
30
30
|
{
|
|
31
|
-
"mask":
|
|
31
|
+
"mask": 31,
|
|
32
32
|
"type": "global"
|
|
33
33
|
},
|
|
34
34
|
{
|
|
35
|
-
"mask":
|
|
35
|
+
"mask": 31,
|
|
36
36
|
"type": "global",
|
|
37
37
|
"account": "Administrators"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"mask": 17,
|
|
41
|
+
"type": "self",
|
|
42
|
+
"account": "Registrar",
|
|
43
|
+
"filter": "event/courseClassInstructor/courseClass/course/department eq departments()"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"mask": 17,
|
|
47
|
+
"type": "global",
|
|
48
|
+
"account": "QualityAssuranceUnit"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"mask": 17,
|
|
52
|
+
"type": "self",
|
|
53
|
+
"account": "QualityAssuranceDepartment",
|
|
54
|
+
"filter": "event/courseClassInstructor/courseClass/course/department eq departments()"
|
|
38
55
|
}
|
|
39
56
|
]
|
|
40
57
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://themost-framework.github.io/themost/models/2018/2/schema.json",
|
|
3
|
+
"@id": "http://schema.org/SendInstructorTokenAction",
|
|
4
|
+
"name": "SendInstructorTokenAction",
|
|
5
|
+
"description": "The act of organizing tasks/objects/events by associating resources to it.",
|
|
6
|
+
"title": "SendInstructorTokenAction",
|
|
7
|
+
"abstract": false,
|
|
8
|
+
"sealed": false,
|
|
9
|
+
"inherits": "SendTokenAction",
|
|
10
|
+
"version": "1.1",
|
|
11
|
+
"fields": [
|
|
12
|
+
{
|
|
13
|
+
"name": "event",
|
|
14
|
+
"title": "Γεγονός αξιολόγησης",
|
|
15
|
+
"type": "ClassInstructorEvaluationEvent",
|
|
16
|
+
"nullable": false
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"name": "numberOfStudents",
|
|
20
|
+
"description": "Σύνολο φοιτητών",
|
|
21
|
+
"type": "Integer"
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"privileges": [
|
|
25
|
+
{
|
|
26
|
+
"mask": 15,
|
|
27
|
+
"type": "global"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"mask": 15,
|
|
31
|
+
"type": "global",
|
|
32
|
+
"account": "Administrators"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"mask": 1,
|
|
36
|
+
"type": "self",
|
|
37
|
+
"account": "Registrar",
|
|
38
|
+
"filter": "event/courseClassInstructor/courseClass/course/department eq departments()"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"mask": 1,
|
|
42
|
+
"type": "global",
|
|
43
|
+
"account": "QualityAssuranceUnit"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"mask": 1,
|
|
47
|
+
"type": "self",
|
|
48
|
+
"account": "QualityAssuranceDepartment",
|
|
49
|
+
"filter": "event/courseClassInstructor/courseClass/course/department eq departments()"
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://themost-framework.github.io/themost/models/2018/2/schema.json",
|
|
3
|
+
"@id": "http://schema.org/SendTokenAction",
|
|
4
|
+
"name": "SendTokenAction",
|
|
5
|
+
"description": "The act of organizing tasks/objects/events by associating resources to it.",
|
|
6
|
+
"title": "SendTokenAction",
|
|
7
|
+
"abstract": false,
|
|
8
|
+
"sealed": false,
|
|
9
|
+
"inherits": "Action",
|
|
10
|
+
"version": "1.0",
|
|
11
|
+
"fields": [
|
|
12
|
+
{
|
|
13
|
+
"name": "event",
|
|
14
|
+
"title": "Γεγονός αξιολόγησης",
|
|
15
|
+
"type": "EvaluationEvent",
|
|
16
|
+
"nullable": false
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"name": "total",
|
|
20
|
+
"description": "Σύνολο tokens προς αποστολή",
|
|
21
|
+
"type": "Integer"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"name": "sent",
|
|
25
|
+
"description": "Σύνολο tokens που στάλθηκαν επιτυχώς",
|
|
26
|
+
"type": "Integer"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"name": "failed",
|
|
30
|
+
"description": "Σύνολο tokens των οποίων τη αποστολή απέτυχε",
|
|
31
|
+
"type": "Integer"
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
"privileges": [
|
|
35
|
+
{
|
|
36
|
+
"mask": 15,
|
|
37
|
+
"type": "global"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"mask": 15,
|
|
41
|
+
"type": "global",
|
|
42
|
+
"account": "Administrators"
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
}
|
|
@@ -28,11 +28,14 @@ class AccessToken extends DataObject {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
isExpired() {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
if (this.expires == null) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
// check only date parts
|
|
35
|
+
const currentDate = new Date().setHours(0, 0, 0, 0);
|
|
36
|
+
const expires = this.expires.setHours(0, 0, 0, 0);
|
|
37
|
+
return (expires < currentDate);
|
|
35
38
|
}
|
|
36
39
|
}
|
|
37
40
|
|
|
38
|
-
module.exports = AccessToken;
|
|
41
|
+
module.exports = AccessToken;
|