Skip to content

Commit 0498eb0

Browse files
committed
1 parent c41344e commit 0498eb0

File tree

9 files changed

+160
-5
lines changed

9 files changed

+160
-5
lines changed

collections/checkLab.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare module "validateLab" {
2+
export function validateLab(str: string): boolean
3+
}

collections/checkLab.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"use strict";
2+
module.exports = function(str){
3+
4+
if(!str) { return false; }
5+
var tux = eval(str);
6+
//var s = tuxlab;
7+
var tuxOrig = require('./tuxlab.js');
8+
return ((typeof tux != "undefined") &&
9+
(typeof tux.setup === 'function') && //check for instructor field types
10+
(typeof tux.tasks === 'function') &&
11+
(tux.init.toString() === tuxOrig.init.toString()) && //check for unchanged
12+
(tux.newTask.toString() === tuxOrig.newTask.toString()));
13+
14+
}

collections/labs.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import { Meteor } from 'meteor/meteor';
33

44
import { Roles } from './users.ts';
55

6+
//import { validateLab } from './checkLab.ts';
7+
declare var validateLab : any;
8+
import validateLab = require('./checkLab');
69
export const labs : any = new Mongo.Collection('labs');
710

811
/**
@@ -78,10 +81,30 @@ labs.allow({
7881
if(Meteor.isServer){
7982
Meteor.startup(function(){
8083
var LabValidator = function(userid, doc, fieldNames?, modifier?, options?){
81-
if (typeof fieldNames === "undefined" || fieldNames.includes('tasks') || fieldNames.includes('file')){
84+
if (typeof fieldNames === "undefined"){
85+
console.log("inserting");
86+
if(!(doc.course_id && doc.file && //check for lab fields
87+
(Meteor.isServer || Roles.isInstructorFor(doc.course_id,userid))&& //check for instructor authorization
88+
validateLab(doc.file))){ //check for labfile errors
89+
return false;
90+
}
91+
8292
//TODO @CEM: Validate Lab
8393
//TODO @CEM: Generate tasks array
8494
}
95+
else if(fieldNames.includes('tasks') && !fieldNames.includes('file')){
96+
return false;
97+
}
98+
else if(fieldNames.includes('file')){
99+
if(!((Meteor.isServer || Roles.isInstructorFor(doc.course_id,userid)) && //check for instructor authorization
100+
validateLab(modifier.$set.file))){ //check for labfile errors
101+
return false;
102+
}
103+
else{
104+
if(modifier) {modifier.$set.updated = Date.now(); }
105+
doc.updated = Date.now();
106+
}
107+
}
85108
}
86109
labs.before.update(LabValidator);
87110
labs.before.insert(LabValidator);

collections/tuxlab.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
var tuxlab = function(){}
2+
3+
tuxlab.prototype.init = function(){
4+
var slf = this;
5+
var ts = { prnt: slf,
6+
next: null,
7+
nextTask: function(tsk){
8+
this.next = tsk;
9+
this.prnt.taskList.push(tsk);
10+
return tsk;
11+
}
12+
}
13+
this.currentTask = ts;
14+
return ts;
15+
}
16+
17+
tuxlab.prototype.currentTask = null;
18+
tuxlab.prototype.taskList = [];
19+
tuxlab.prototype.setup;
20+
tuxlab.prototype.tasks;
21+
tuxlab.prototype.newTask = function(ttl, mdown,sFn, vFn, opt){
22+
var slf = this;
23+
var ts = { prnt: slf,
24+
setupFn: sFn,
25+
verifyFn: vFn,
26+
opts: opt,
27+
markdown: mdown,
28+
title: ttl,
29+
next: null,
30+
completed: false,
31+
nextTask: function(tsk){
32+
this.next = tsk;
33+
this.prnt.taskList.push(tsk);
34+
return tsk;
35+
},
36+
isLast: function(){ return this.next === null; }
37+
}
38+
return ts;
39+
}
40+
module.exports = new tuxlab();

server/imports/lab/methods.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
declare var Collections : any;
22
Meteor.methods({
33
'prepareLab': function(courseId : String,labId : Number){
4-
var course = Collections.courses.findOne({_id: courseId}).fetch();
4+
console.log("here");
5+
// var course = Collections.courses.findOne({_id: courseId}).fetch();
56
//var t = require('../api/labExec.js');
6-
return course.labs.find((l) => { return l._id == labId; });
7+
// return course.labs.find((l) => { return l._id == labId; });
78
}
89
});
910

tests/example_data/badlabfile1.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
var tuxlab = require('./tuxlab.js');
2+
3+
tuxlab.setup = 5;
4+
tuxlab.tasks = function(env){
5+
var s1 = function(){
6+
env.start()
7+
.then(env.createVm({dockerodeCreateOptions: {name: "derek"}}))
8+
.then(env.shell("labVm","cd ~./home/usr/derek"))
9+
.then(function(sOut){ console.log("succ: "+sOut); },
10+
function(sOut,sErr,sDock){ throw sOut+sErr+sDock; });
11+
}
12+
var v1 = function(){
13+
env.shell("labVm","pwd")
14+
.then(function(sOut){ if(sOut === "/usr/home/derek") return true; else return false; });
15+
}
16+
var s2 = function(){}
17+
var v2 = function(){}
18+
var s3 = function(){}
19+
var v3 = function(){}
20+
var s4 = function(){}
21+
var v4 = function(){}
22+
var task1 = tuxlab.newTask('TASK1','MD1',s1,v1)
23+
var task2 = tuxlab.newTask('TASK2','MD2',s2,v2)
24+
var task3 = tuxlab.newTask('TASK3','MD3',s3,v3)
25+
var task4 = tuxlab.newTask('TASK4','MD4',s4,v4)
26+
return tuxlab.init()
27+
.nextTask(task1)
28+
.nextTask(task2)
29+
.nextTask(task3)
30+
.nextTask(task4);
31+
}
32+
module.exports = tuxlab;
33+
//export tuxlab

tests/example_data/labfile1.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ tuxlab.tasks = function(env){
3838
.nextTask(task4);
3939
}
4040
module.exports = tuxlab;
41+
//export tuxlab

tests/example_data/tuxlab.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
var tuxlab = function(){}
2+
/*
3+
tuxlab.prototype.init = function(){
4+
var slf = this;
5+
var ts = { prnt: slf,
6+
next: null,
7+
nextTask: function(tsk){
8+
this.next = tsk;
9+
this.prnt.taskList.push(tsk);
10+
return tsk;
11+
}
12+
}
13+
this.currentTask = ts;
14+
return ts;
15+
}
16+
*/
17+
tuxlab.prototype.currentTask = null;
18+
tuxlab.prototype.taskList = [];
19+
tuxlab.prototype.setup;
20+
tuxlab.prototype.tasks;/*
21+
tuxlab.prototype.newTask = function(ttl, mdown,sFn, vFn, opt){
22+
var slf = this;
23+
var ts = { prnt: slf,
24+
setupFn: sFn,
25+
verifyFn: vFn,
26+
opts: opt,
27+
markdown: mdown,
28+
title: ttl,
29+
next: null,
30+
completed: false,
31+
nextTask: function(tsk){
32+
this.next = tsk;
33+
this.prnt.taskList.push(tsk);
34+
return tsk;
35+
},
36+
isLast: function(){ return this.next === null; }
37+
}
38+
return ts;
39+
}*/
40+
module.exports = new tuxlab();

tests/tuxlab.db.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ describe('Example Database', function(){
9292
});
9393

9494
// Validate that Records Exists
95-
if('should have uploaded these records', function(){
95+
/* it('should have uploaded these records', function(){
9696
return server.execute(function(course_id, lab_id){
9797
var course = Collections.findOne(course_id).fetch();
9898
@@ -106,6 +106,6 @@ describe('Example Database', function(){
106106
107107
}, [course_id, lab_id]);
108108
});
109-
109+
*/
110110

111111
});

0 commit comments

Comments
 (0)