@universis/evaluations 1.0.2

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.
Files changed (68) hide show
  1. package/.eslintignore +1 -0
  2. package/.eslintrc +34 -0
  3. package/.gitlab-ci.yml +22 -0
  4. package/LICENSE +163 -0
  5. package/README.md +38 -0
  6. package/babel.config.js +3 -0
  7. package/dist/EvaluationSchemaLoader.js +33 -0
  8. package/dist/EvaluationSchemaLoader.js.map +1 -0
  9. package/dist/EvaluationService.js +56 -0
  10. package/dist/EvaluationService.js.map +1 -0
  11. package/dist/config/models/AccessToken.json +76 -0
  12. package/dist/config/models/ClassInstructorEvaluationEvent.json +76 -0
  13. package/dist/config/models/CourseClassEvaluationEvent.json +57 -0
  14. package/dist/config/models/EvaluationAccessToken.json +101 -0
  15. package/dist/config/models/EvaluationDocument.json +72 -0
  16. package/dist/config/models/EvaluationEvent.json +50 -0
  17. package/dist/config/scope.access.json +11 -0
  18. package/dist/evaluationRouter.js +118 -0
  19. package/dist/evaluationRouter.js.map +1 -0
  20. package/dist/handlers/evaluation-key-handler.js +45 -0
  21. package/dist/handlers/evaluation-key-handler.js.map +1 -0
  22. package/dist/index.js +3 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/listeners/class-instructor-event-listener.js +27 -0
  25. package/dist/listeners/class-instructor-event-listener.js.map +1 -0
  26. package/dist/listeners/force-set-state-listener.js +47 -0
  27. package/dist/listeners/force-set-state-listener.js.map +1 -0
  28. package/dist/models/access-token-model.d.ts +37 -0
  29. package/dist/models/access-token-model.js +39 -0
  30. package/dist/models/access-token-model.js.map +1 -0
  31. package/dist/models/evaluation-access-token-model.d.ts +17 -0
  32. package/dist/models/evaluation-access-token-model.js +40 -0
  33. package/dist/models/evaluation-access-token-model.js.map +1 -0
  34. package/dist/models/evaluation-document-model.d.ts +13 -0
  35. package/dist/models/evaluation-document-model.js +150 -0
  36. package/dist/models/evaluation-document-model.js.map +1 -0
  37. package/dist/models/evaluation-event-model.d.ts +13 -0
  38. package/dist/models/evaluation-event-model.js +318 -0
  39. package/dist/models/evaluation-event-model.js.map +1 -0
  40. package/package.json +53 -0
  41. package/spec/CourseEvaluationSampleForm.json +1046 -0
  42. package/spec/EvaluationService.spec.js +9 -0
  43. package/spec/helpers/babel.js +1 -0
  44. package/spec/helpers/env.js +7 -0
  45. package/spec/helpers/reporter.js +11 -0
  46. package/spec/support/jasmine.json +13 -0
  47. package/src/EvaluationSchemaLoader.js +35 -0
  48. package/src/EvaluationService.js +57 -0
  49. package/src/config/models/AccessToken.json +76 -0
  50. package/src/config/models/ClassInstructorEvaluationEvent.json +76 -0
  51. package/src/config/models/CourseClassEvaluationEvent.json +57 -0
  52. package/src/config/models/EvaluationAccessToken.json +101 -0
  53. package/src/config/models/EvaluationDocument.json +72 -0
  54. package/src/config/models/EvaluationEvent.json +50 -0
  55. package/src/config/scope.access.json +11 -0
  56. package/src/evaluationRouter.js +117 -0
  57. package/src/handlers/evaluation-key-handler.js +45 -0
  58. package/src/index.js +2 -0
  59. package/src/listeners/class-instructor-event-listener.js +27 -0
  60. package/src/listeners/force-set-state-listener.js +46 -0
  61. package/src/models/access-token-model.d.ts +37 -0
  62. package/src/models/access-token-model.js +38 -0
  63. package/src/models/evaluation-access-token-model.d.ts +17 -0
  64. package/src/models/evaluation-access-token-model.js +39 -0
  65. package/src/models/evaluation-document-model.d.ts +13 -0
  66. package/src/models/evaluation-document-model.js +149 -0
  67. package/src/models/evaluation-event-model.d.ts +13 -0
  68. package/src/models/evaluation-event-model.js +317 -0
@@ -0,0 +1,9 @@
1
+ import {EvaluationService} from '../src/EvaluationService';
2
+ describe('EvaluationService', () => {
3
+
4
+ it('should create instance', async () => {
5
+ const service = new EvaluationService();
6
+ expect(service).toBeTruthy();
7
+ });
8
+
9
+ });
@@ -0,0 +1 @@
1
+ require('@babel/register');
@@ -0,0 +1,7 @@
1
+ // add default options
2
+ if (process && process.env) {
3
+ process.env.NODE_ENV = 'development';
4
+ process.env.DEBUG = 'api:*';
5
+ }
6
+ // use dotenv for other environment variables
7
+ require('dotenv').config();
@@ -0,0 +1,11 @@
1
+ const SpecReporter = require('jasmine-spec-reporter').SpecReporter;
2
+
3
+ jasmine.getEnv().clearReporters(); // remove default reporter logs
4
+ // noinspection JSCheckFunctionSignatures
5
+ jasmine.getEnv().addReporter(new SpecReporter({ // add jasmine-spec-reporter
6
+ spec: {
7
+ displayPending: true,
8
+ displayStacktrace: 'raw'
9
+ }
10
+ }));
11
+ jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000;
@@ -0,0 +1,13 @@
1
+ {
2
+ "spec_dir": "spec",
3
+ "spec_files": [
4
+ "**/*[sS]pec.js"
5
+ ],
6
+ "helpers": [
7
+ "helpers/env.js",
8
+ "helpers/babel.js",
9
+ "helpers/reporter.js"
10
+ ],
11
+ "stopSpecOnExpectationFailure": false,
12
+ "random": true
13
+ }
@@ -0,0 +1,35 @@
1
+ import {FileSchemaLoaderStrategy} from "@themost/data";
2
+ import path from 'path';
3
+ /**
4
+ * A schema loader for loading extra data models
5
+ */
6
+ export class EvaluationSchemaLoader extends FileSchemaLoaderStrategy {
7
+
8
+ /**
9
+ * @param {ConfigurationBase} config
10
+ */
11
+ constructor(config) {
12
+ super(config);
13
+ // set model path
14
+ this.setModelPath(path.resolve(__dirname, 'config/models'));
15
+ }
16
+
17
+ getModelDefinition(name) {
18
+ const model = super.getModelDefinition.bind(this)(name);
19
+ if (model) {
20
+ if (Array.isArray(model.eventListeners) ) {
21
+ model.eventListeners.forEach(eventListener => {
22
+ if (eventListener.type.indexOf('.') === 0) {
23
+ eventListener.type = path.resolve(__dirname, eventListener.type);
24
+ }
25
+ });
26
+ }
27
+ if (model.classPath && model.classPath.indexOf('.')===0) {
28
+ model.classPath= path.resolve(__dirname, model.classPath);
29
+ }
30
+ }
31
+ return model;
32
+ }
33
+
34
+ }
35
+
@@ -0,0 +1,57 @@
1
+ import { ApplicationService } from "@themost/common";
2
+ import LocalScopeAccessConfiguration from './config/scope.access.json';
3
+ import {evaluationRouter} from "./evaluationRouter";
4
+
5
+ function insertRouterBefore(parent, before, insert) {
6
+ const beforeIndex = parent.stack.findIndex( (item) => {
7
+ return item === before;
8
+ });
9
+ if (beforeIndex < 0) {
10
+ throw new Error('Target router cannot be found in parent stack.');
11
+ }
12
+ const findIndex = parent.stack.findIndex( (item) => {
13
+ return item === insert;
14
+ });
15
+ if (findIndex < 0) {
16
+ throw new Error('Router to be inserted cannot be found in parent stack.');
17
+ }
18
+ // remove last router
19
+ parent.stack.splice(findIndex, 1);
20
+ // move up
21
+ parent.stack.splice(beforeIndex, 0, insert);
22
+ }
23
+
24
+ export class EvaluationService extends ApplicationService {
25
+ constructor(app) {
26
+ super(app);
27
+ // extend universis api scope access configuration
28
+ if (app && app.container) {
29
+ app.container.subscribe((container) => {
30
+ if (container) {
31
+ // add extra scope access elements
32
+ const scopeAccess = app.getConfiguration().getStrategy(function ScopeAccessConfiguration() { });
33
+ if (scopeAccess != null) {
34
+ scopeAccess.elements.push.apply(scopeAccess.elements, LocalScopeAccessConfiguration);
35
+ }
36
+ // get container router
37
+ const router = container._router;
38
+ // find after position
39
+ const before = router.stack.find((item) => {
40
+ return item.name === 'dataContextMiddleware';
41
+ });
42
+ // use eudoxus router
43
+ container.use('/api/EvaluationEvents/Current', evaluationRouter(app));
44
+ if (before == null) {
45
+ // do nothing
46
+ return;
47
+ }
48
+ // get last router
49
+ const insert = router.stack[router.stack.length - 1];
50
+ // insert (re-index) router
51
+ insertRouterBefore(router, before, insert);
52
+ }
53
+ });
54
+ }
55
+ }
56
+
57
+ }
@@ -0,0 +1,76 @@
1
+ {
2
+ "$schema": "https://themost-framework.github.io/themost/models/2018/2/schema.json",
3
+ "@id": "https://themost.io/schemas/AccessToken",
4
+ "name": "AccessToken",
5
+ "title": "AccessToken",
6
+ "description": "Access tokens are credentials used to access protected resources.",
7
+ "hidden": true,
8
+ "sealed": false,
9
+ "abstract": false,
10
+ "version": "1.0",
11
+ "classPath": "./models/access-token-model",
12
+ "fields": [
13
+ {
14
+ "@id": "https://themost.io/schemas/access_token",
15
+ "name": "access_token",
16
+ "title": "Access Token",
17
+ "description": "An access token is a string representing an authorization issued to the client.",
18
+ "type": "Text",
19
+ "nullable": false,
20
+ "primary": true,
21
+ "value": "javascript:return this.chars(48);"
22
+ },
23
+ {
24
+ "@id": "https://themost.io/schemas/client_id",
25
+ "name": "user_id",
26
+ "title": "User",
27
+ "type": "Text",
28
+ "editable": false,
29
+ "nullable": false
30
+ },
31
+ {
32
+ "@id": "https://themost.io/schemas/client_id",
33
+ "name": "client_id",
34
+ "title": "Client ID",
35
+ "description": "The authorization server issues the registered client a client identifier -- a unique string representing the registration information provided by the client.",
36
+ "type": "Text",
37
+ "nullable": false,
38
+ "indexed": true
39
+ },
40
+ {
41
+ "@id": "https://themost.io/schemas/expires",
42
+ "description": "The expiration date and time of this access token.",
43
+ "name": "expires",
44
+ "title": "Expires",
45
+ "type": "DateTime",
46
+ "nullable": true
47
+ },
48
+ {
49
+ "@id": "https://themost.io/schemas/refresh_token",
50
+ "name": "refresh_token",
51
+ "title": "Refresh Token",
52
+ "description": "Refresh tokens are issued to the client by the authorization server and are used to obtain a new access token when the current access token becomes invalid or expires.",
53
+ "type": "Text",
54
+ "value": "javascript:return this.chars(48);"
55
+ },
56
+ {
57
+ "@id": "https://themost.io/schemas/scope",
58
+ "name": "scope",
59
+ "title": "Scope",
60
+ "description": "Scope is used to limit the authorization granted to the client by the resource owner.",
61
+ "type": "Text"
62
+ }
63
+ ],
64
+ "privileges": [
65
+ {
66
+ "mask": 15,
67
+ "type": "global",
68
+ "account": "Administrators"
69
+ },
70
+ {
71
+ "mask": 15,
72
+ "type": "global"
73
+ }
74
+ ]
75
+ }
76
+
@@ -0,0 +1,76 @@
1
+ {
2
+ "$schema": "https://themost-framework.github.io/themost/models/2018/2/schema.json",
3
+ "@id": "http://schema.org/ClassInstructorEvaluationEvent",
4
+ "name": "ClassInstructorEvaluationEvent",
5
+ "title": "ClassInstructorEvaluationEvents",
6
+ "abstract": false,
7
+ "sealed": false,
8
+ "inherits": "EvaluationEvent",
9
+ "version": "1.0",
10
+ "fields": [
11
+ {
12
+ "@id": "http://schema.org/courseClassInstructor",
13
+ "name": "courseClassInstructor",
14
+ "title": "Course Class Instructor",
15
+ "type": "CourseClassInstructor",
16
+ "nullable": false,
17
+ "expandable": true,
18
+ "mapping": {
19
+ "options": {
20
+ "$expand": "courseClass,instructor"
21
+ }
22
+ }
23
+ },
24
+ {
25
+ "@id": "http://schema.org/organizer",
26
+ "name": "organizer",
27
+ "title": "organizer",
28
+ "description": "An organizer of an Event.",
29
+ "type": "Department",
30
+ "nullable": false
31
+ },
32
+ {
33
+ "name": "additionalType",
34
+ "title": "Additional Type",
35
+ "description": "An additional type for the item, typically used for adding more specific types from external vocabularies in microdata syntax. This is a relationship between something and a class that the thing is in. In RDFa syntax, it is better to use the native RDFa syntax - the 'typeof' attribute - for multiple types. Schema.org tools may have only weaker understanding of extra types, in particular those defined externally.",
36
+ "type": "Text",
37
+ "readonly": true,
38
+ "value": "javascript:return this.model.name;"
39
+ }
40
+ ],
41
+ "eventListeners": [
42
+ {
43
+ "type": "./listeners/class-instructor-event-listener"
44
+ }
45
+ ],
46
+ "privileges": [
47
+ {
48
+ "mask": 15,
49
+ "type": "global"
50
+ },
51
+ {
52
+ "mask": 1,
53
+ "type": "global",
54
+ "account": "*"
55
+ },
56
+ {
57
+ "mask": 15,
58
+ "type": "global",
59
+ "account": "Administrators"
60
+ }
61
+ ],
62
+ "resultPrivileges": [
63
+ {
64
+ "mask": 1,
65
+ "type": "self",
66
+ "account": "Instructors",
67
+ "filter": "evaluationEvent/courseClassInstructor/instructor/user eq me() or evaluationEvent/courseClassInstructor/instructor eq instructor()"
68
+ },
69
+ {
70
+ "mask": 1,
71
+ "type": "self",
72
+ "account": "Registrar",
73
+ "filter": "organizer eq departments()"
74
+ }
75
+ ]
76
+ }
@@ -0,0 +1,57 @@
1
+ {
2
+ "$schema": "https://themost-framework.github.io/themost/models/2018/2/schema.json",
3
+ "@id": "http://schema.org/CourseClassEvaluationEvent",
4
+ "name": "CourseClassEvaluationEvent",
5
+ "title": "CourseClassEvaluationEvents",
6
+ "abstract": false,
7
+ "sealed": false,
8
+ "inherits": "EvaluationEvent",
9
+ "version": "1.0",
10
+ "fields": [
11
+ {
12
+ "@id": "http://schema.org/courseClass",
13
+ "name": "courseClass",
14
+ "title": "Course Class",
15
+ "type": "CourseClass",
16
+ "nullable": false
17
+ },
18
+ {
19
+ "@id": "http://schema.org/organizer",
20
+ "name": "organizer",
21
+ "title": "organizer",
22
+ "description": "An organizer of an Event.",
23
+ "type": "Department",
24
+ "nullable": false
25
+ }
26
+ ],
27
+ "privileges": [
28
+ {
29
+ "mask": 15,
30
+ "type": "global"
31
+ },
32
+ {
33
+ "mask": 1,
34
+ "type": "global",
35
+ "account": "*"
36
+ },
37
+ {
38
+ "mask": 15,
39
+ "type": "global",
40
+ "account": "Administrators"
41
+ }
42
+ ],
43
+ "resultPrivileges": [
44
+ {
45
+ "mask": 1,
46
+ "type": "self",
47
+ "account": "Instructors",
48
+ "filter": "courseClass/instructors/instructor eq instructor()"
49
+ },
50
+ {
51
+ "mask": 1,
52
+ "type": "self",
53
+ "account": "Registrar",
54
+ "filter": "organizer eq departments()"
55
+ }
56
+ ]
57
+ }
@@ -0,0 +1,101 @@
1
+ {
2
+ "$schema": "https://themost-framework.github.io/themost/models/2018/2/schema.json",
3
+ "@id": "http://schema.org/EvaluationAccessToken",
4
+ "name": "EvaluationAccessToken",
5
+ "description": "An access token provided for evaluating an object.",
6
+ "title": "EvaluationAccessToken",
7
+ "abstract": false,
8
+ "sealed": false,
9
+ "hidden": false,
10
+ "inherits": "AccessToken",
11
+ "version": "1.0",
12
+ "classPath": "./models/evaluation-access-token-model",
13
+ "fields": [
14
+ {
15
+ "@id": "http://schema.org/evaluationEvent",
16
+ "name": "evaluationEvent",
17
+ "title": "evaluationEvent",
18
+ "type": "EvaluationEvent",
19
+ "nullable": false
20
+ },
21
+ {
22
+ "@id": "https://themost.io/schemas/access_token",
23
+ "name": "access_token",
24
+ "title": "Access Token",
25
+ "description": "An access token is a string representing an authorization issued to the client.",
26
+ "type": "Text",
27
+ "nullable": false,
28
+ "primary": true,
29
+ "value": "javascript:return require('lodash').sampleSize('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', 20).join('');"
30
+ },
31
+ {
32
+ "@id": "https://themost.io/schemas/scope",
33
+ "name": "scope",
34
+ "title": "Scope",
35
+ "description": "Scope is used to limit the authorization granted to the client by the resource owner.",
36
+ "type": "Text",
37
+ "readonly": true,
38
+ "value": "javascript:return 'evaluation';"
39
+ },
40
+ {
41
+ "@id": "https://themost.io/schemas/user_id",
42
+ "name": "user_id",
43
+ "title": "User",
44
+ "type": "Text",
45
+ "nullable": false,
46
+ "editable": false,
47
+ "value": "javascript:return 'anonymous';"
48
+ },
49
+ {
50
+ "@id": "https://themost.io/schemas/client_id",
51
+ "name": "client_id",
52
+ "title": "Client ID",
53
+ "description": "The authorization server issues the registered client a client identifier -- a unique string representing the registration information provided by the client.",
54
+ "type": "WebApplication",
55
+ "nullable": false,
56
+ "indexed": true,
57
+ "value": "javascript:return 'evaluation-center';",
58
+ "mapping": {
59
+ "associationType": "association",
60
+ "parentModel": "WebApplication",
61
+ "parentField": "alternateName",
62
+ "childModel": "EvaluationAccessToken",
63
+ "childField": "client_id"
64
+ }
65
+ },
66
+ {
67
+ "@id": "https://themost.io/schemas/expires",
68
+ "description": "The expiration date and time of this access token.",
69
+ "name": "expires",
70
+ "title": "Expires",
71
+ "type": "DateTime",
72
+ "nullable": true,
73
+ "value": "javascript:return require('moment')(new Date()).add(1, 'd').toDate();"
74
+ },
75
+ {
76
+ "@id": "https://themost.io/schemas/webApplication",
77
+ "name": "webApplication",
78
+ "title": "Web Application",
79
+ "type": "Text",
80
+ "nullable": true
81
+ }
82
+ ],
83
+ "constraints": [
84
+ ],
85
+ "privileges": [
86
+ {
87
+ "mask": 15,
88
+ "type": "global"
89
+ },
90
+ {
91
+ "mask": 15,
92
+ "type": "global",
93
+ "account": "Administrators"
94
+ }
95
+ ],
96
+ "eventListeners": [
97
+ {
98
+ "type": "./listeners/force-set-state-listener"
99
+ }
100
+ ]
101
+ }
@@ -0,0 +1,72 @@
1
+ {
2
+ "$schema": "https://themost-framework.github.io/themost/models/2018/2/schema.json",
3
+ "@id": "http://schema.org/EvaluationDocument",
4
+ "name": "EvaluationDocument",
5
+ "description": "Evaluation document",
6
+ "title": "EvaluationDocument",
7
+ "abstract": false,
8
+ "sealed": false,
9
+ "version": "1.0",
10
+ "inherits": "Attachment",
11
+ "classPath": "./models/evaluation-document-model",
12
+ "fields": [
13
+ {
14
+ "name": "documentNumber",
15
+ "title": "Document number",
16
+ "type": "Integer",
17
+ "value": "javascript:return this.newid();",
18
+ "nullable": false
19
+ },
20
+ {
21
+ "@id": "http://schema.org/evaluationType",
22
+ "name": "resultType",
23
+ "title": "Result Type",
24
+ "description": "A string which represents the data model where evaluation results will be stored.",
25
+ "type": "Text",
26
+ "value": "javascript:return 'Evaluation' + this.target.documentNumber;"
27
+ },
28
+ {
29
+ "name": "sameAs",
30
+ "title": "Same As",
31
+ "description": "URL of a reference Web page that unambiguously indicates the item's identity. E.g. the URL of the item's Wikipedia page, Freebase page, or official website.",
32
+ "type": "URL",
33
+ "nullable": true
34
+ },
35
+ {
36
+ "@id": "https://themost.io/schemas/version",
37
+ "name": "version",
38
+ "title": "Version",
39
+ "description": "The version of this item.",
40
+ "type": "Text",
41
+ "validation": {
42
+ "pattern": "^\\d+.\\d+.\\d+$"
43
+ }
44
+
45
+ }
46
+ ],
47
+ "constraints": [
48
+ {
49
+ "type": "unique",
50
+ "fields": [
51
+ "sameAs"
52
+ ]
53
+ }
54
+ ],
55
+ "privileges": [
56
+ {
57
+ "mask": 1,
58
+ "type": "global",
59
+ "account": "*"
60
+ },
61
+ {
62
+ "mask": 15,
63
+ "type": "global"
64
+ },
65
+ {
66
+ "mask": 15,
67
+ "type": "global",
68
+ "account": "Administrators"
69
+ }
70
+ ]
71
+ }
72
+
@@ -0,0 +1,50 @@
1
+ {
2
+ "$schema": "https://themost-framework.github.io/themost/models/2018/2/schema.json",
3
+ "@id": "http://schema.org/EvaluationEvent",
4
+ "name": "EvaluationEvent",
5
+ "title": "EvaluationEvents",
6
+ "abstract": false,
7
+ "sealed": false,
8
+ "inherits": "Event",
9
+ "version": "1.0",
10
+ "classPath": "./models/evaluation-event-model",
11
+ "fields": [
12
+ {
13
+ "name": "id",
14
+ "type": "Integer",
15
+ "primary": true,
16
+ "nullable": false
17
+ },
18
+ {
19
+ "@id": "http://schema.org/evaluationDocument",
20
+ "name": "evaluationDocument",
21
+ "title": "evaluationDocument",
22
+ "type": "EvaluationDocument",
23
+ "nullable": false
24
+ },
25
+ {
26
+ "name": "additionalType",
27
+ "title": "Additional Type",
28
+ "description": "An additional type for the item, typically used for adding more specific types from external vocabularies in microdata syntax. This is a relationship between something and a class that the thing is in. In RDFa syntax, it is better to use the native RDFa syntax - the 'typeof' attribute - for multiple types. Schema.org tools may have only weaker understanding of extra types, in particular those defined externally.",
29
+ "type": "Text",
30
+ "readonly": true,
31
+ "value": "javascript:return this.model.name;"
32
+ }
33
+ ],
34
+ "privileges": [
35
+ {
36
+ "mask": 15,
37
+ "type": "global"
38
+ },
39
+ {
40
+ "mask": 1,
41
+ "type": "global",
42
+ "account": "*"
43
+ },
44
+ {
45
+ "mask": 15,
46
+ "type": "global",
47
+ "account": "Administrators"
48
+ }
49
+ ]
50
+ }
@@ -0,0 +1,11 @@
1
+ [
2
+ {
3
+ "scope": [
4
+ "teachers"
5
+ ],
6
+ "resource": "/api/ClassInstructorEvaluationEvents/(\\d+)/Results",
7
+ "access": [
8
+ "read"
9
+ ]
10
+ }
11
+ ]