Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
DerekTBrown committed Aug 6, 2016
2 parents c214643 + 8b6f348 commit 2c34c78
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 37 deletions.
7 changes: 2 additions & 5 deletions client/imports/ui/pages/lab/labview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ export default class LabView extends MeteorComponent {
ngAfterViewInit(){
var slf = this;
Meteor.call('prepareLab',"1", function(err,res){
console.log('here');
console.log("fired",err,res);
//slf.labMarkdown = "# Sander \n ## are you sure this will work?";

slf.tasks = res.taskList;
slf.toTask(slf.tasks[0]);
slf.labProgress = "0 / "+slf.tasks.length;
Expand All @@ -94,7 +92,6 @@ export default class LabView extends MeteorComponent {
Meteor.call('verifyTask',"1",function(err,res){
var slf = this;
if(err){
console.log("something went horribly wrong");
}
else{
if(res.verified){
Expand All @@ -110,12 +107,12 @@ export default class LabView extends MeteorComponent {

// Called by Next button
nextTask(){
console.log("proceeding");
var slf = this;
Meteor.call('nextTask',"1",function(err,res){
if(err){
slf.nextButton = false;
console.log("try again");
//TODO: @sandershihacker, change this from console.log to alert/something else
}
else{
console.log(res);
Expand Down
5 changes: 1 addition & 4 deletions client/imports/ui/routes/course.guard.course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,13 @@ export class CourseGuardRecord implements CanActivate{
var obs : Observable<boolean> = Observable.fromPromise(new Promise<boolean> (function(resolve, reject){

Meteor.subscribe('courses', function(){

// Enroll Authenticated Users
var course_record = Collections.course_records.findOne({user_id: slf.user._id, course_id: course_id});
var course = Collections.course_records.findOne({user_id: slf.user._id, course_id: course_id});
if (typeof course_record !== "undefined" && course_record !== null){
resolve(true);
}
else{

}

});
}));

Expand Down
3 changes: 2 additions & 1 deletion collections/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ if (Meteor.isServer){
defaultValue: []
},
sessions:{
type: sessionSchema
type: [sessionSchema],
defaultValue: []
}
});
(<any> Meteor.users).attachSchema(userSchema);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"es6-promise": "^3.2.1",
"es6-shim": "^0.35.1",
"eval": "^0.1.1",
"http-proxy": "^1.14.0",
"marked": "^0.3.5",
"meteor-node-stubs": "^0.2.3",
"mongodb": "^2.1.18",
Expand Down
7 changes: 5 additions & 2 deletions server/imports/api/lab.env.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ env.prototype.system = {
key: "",
os_family: "",
image: "",
labVm_id: "",
containers: [],
ssh_port: null,
node_ip: null
}
Expand Down Expand Up @@ -97,7 +99,8 @@ env.deleteRecords = function(user,callback){
{dockerodeStartOptions: {--your options here--}}
*/
env.prototype.init = function(system){
console.log("env.init");

TuxLog.log("trace","initalizing the user environment");
var slf = this;

/* create unique labVm name to avoid collisions
Expand Down Expand Up @@ -366,6 +369,7 @@ env.prototype.createVm = function(opts) {

//add container to slf.vmList to keep track
slf.vmList[crtOpt.name] = cName;
slf.system.containers.push(container.id);
resolve();
}
});
Expand Down Expand Up @@ -497,7 +501,6 @@ env.prototype.shell = function(vmName,command,opts) {
}
});
stream.on('end',function(){
console.log(dat);
resolve(dat,stdErr);
});
}
Expand Down
5 changes: 0 additions & 5 deletions server/imports/api/lab.session.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ session.prototype.env = null;
session.prototype.lab = null;
session.prototype.student = null;
session.prototype.pass = null;
session.prototype.started = false;
session.prototype.courseId = null;
session.prototype.user = null;
session.prototype.userId = null;
Expand Down Expand Up @@ -80,10 +79,6 @@ session.prototype.fromJson = function(data, callback){
});

}
session.prototype.changeStarted = function(){
this.started = true;
console.log(this.started);
}
/* init: pulls labFile and initializes session object from it
*/
session.prototype.init = function(user,userId,labId,callback){
Expand Down
90 changes: 86 additions & 4 deletions server/imports/lab/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ declare var TuxLog : any;
declare var SessionCache : any;
declare var nconf : any;
declare var _ : any;
declare var async : any;

import{ Roles } from '../../../collections/users.ts';
//import session constructor
var LabSession = require('../api/lab.session.js');

Expand All @@ -21,12 +23,11 @@ Meteor.methods({
* implement loading wheel, md fetch, course record create in callback
*/
'prepareLab': function(labId : string){

TuxLog.log("trace","preparing lab");

// Meteor.user().sessions.push({labId: labId,started: Date.now()});
(<any>Meteor.user()).sessions.push({labId: labId,started: Date.now()});

// Collections.users.update({_id: Meteor.userId()},{$set:{sessions: this.user.sessions}});
Meteor.users.update({_id: Meteor.userId()},{$set:{sessions: this.user.sessions}});
//get course Id
var courseId = Collections.labs.findOne({_id: labId}).course_id;

Expand Down Expand Up @@ -141,7 +142,7 @@ Meteor.methods({
},

'getLastLab' : function(){
var sessions = Collections.users.findOne({_id: Meteor.userId()}).sessions;
var sessions = (<any>Meteor.user()).sessions;

var labId = sessions.reduce(function(total,current){
if(current.started < total){
Expand All @@ -153,5 +154,86 @@ Meteor.methods({
var courseId = Collections.labs.findOne({_id: labId}).course_id;

return {labId: labId, courseId: courseId};
},

'addInstructor' : function(course_id, instructor_id){

if(!(Roles.isAdministratorFor(course_id, Meteor.userId()) || Roles.isInstructorFor(course_id,instructor_id))){
throw new Meteor.Error("only administrators or instructors can modify instructors");
}
else{
var inst : any = Meteor.users.findOne({_id: instructor_id});

if(!inst){
throw new Meteor.Error("no user found with given id");
}
else{
inst.roles.instructor.push(course_id);

Meteor.users.update({id: instructor_id},{$set: {roles: inst.roles}});

var instructor = {
name: inst.profile.first_name + " "+ inst.profile.last_name,
id: instructor_id
};

Collections.courses.update({_id: course_id},{$push:{instructors: instructor}});
}
}
},

'removeInstructor' : function(course_id, instructor_id){

if(!(Roles.isAdministratorFor(course_id, Meteor.userId()) || Roles.isInstructorFor(course_id, instructor_id))){
throw new Meteor.Error("only administrators or instructors can modify instructors");
}
else{
var inst : any = Meteor.users.findOne({_id: instructor_id});

if(!inst){
throw new Meteor.Error("no user found with given id");
}
else{
Collections.courses.update({_id: course_id},{$pull:{instructors: {id: instructor_id}}});

inst.roles.instructor.delete(inst.roles.instructor.indexOf(course_id));
Meteor.users.update({_id: instructor_id},{$set: {roles: inst.roles}});
}
}
},

'createCourse' : function(course_name, userId, course_number){
if(!Roles.isGlobalAdministrator(Meteor.userId())){
throw new Meteor.Error("only administrators can create courses")
}
else{
var user = Meteor.users.findOne({_id: userId});
if(!user){
throw new Meteor.Error("the instructor id does not match that of a registered user");
}
else{
if(!course_number){
course_number = "";
}
var course = {
course_number: course_number,
course_name: course_name,
}
var courseId = Collections.courses.insert(course);

Meteor.call('addInstructor',courseId, userId);
}
}
},

'deleteCourse' : function(course_id){
var course = Collections.courses.findOne({_id: course_id});

var instructors = course.instructors;

async.map(instructors,function(instructor){
Meteor.call('removeInstructor',course_id,instructor.id);
});

}
});
2 changes: 1 addition & 1 deletion server/imports/startup/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Accounts.onCreateUser(function(options, user){
'instructor' : [],
'administrator' : []
}

user.sessions = [];
// Return User
return user;
});
Expand Down
9 changes: 3 additions & 6 deletions server/imports/startup/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ var Session = require('../api/lab.session.js');
else{
try{
var data = etcd.getSync('/tuxlab/sessions/'+userid+'/'+labid);
console.log("DATA",data);
if(data && data.body && data.body.node && data.body.node.value){
TuxLog.log("warn","Pulling session from etcd");
var sess = new Session();
Expand Down Expand Up @@ -91,7 +90,7 @@ var Session = require('../api/lab.session.js');
callback(success) - returns boolean if success
*/
SessionCache.add = function(userid, labid, session){
console.log("in add");
TuxLog.log("trace","adding session to cache");
async.series([
function(cb){
SessionCache._NodeCache.set(userid+'#'+labid, session, function(err, success){
Expand All @@ -100,25 +99,23 @@ var Session = require('../api/lab.session.js');
cb(true);
}
else{
TuxLog.log("trace","added session to cache successfully");
cb(false);
}
});
},
function(cb){
//TODO @cemersoz to_data method

var json = {
taskNo: session.lab.taskNo,
system: session.env.system,
taskUpdates: session.taskUpdates,
pass: session.pass,
user:session.user,
userId: session.userId,
labId: labid,
courseId: session.courseId
};

console.log("setting: "+json);

etcd.set('tuxlab/sessions/'+session.env.system.node_ip+ '/' + userid + '/' + labid, JSON.stringify(json), function(err){
if(err){
TuxLog.log("warn","etcd.set err");
Expand Down
10 changes: 1 addition & 9 deletions wercker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,10 @@ build:
name: install meteor
code: "curl https://install.meteor.com/ | sh"

- script:
name: install typings
code: sudo meteor npm install -g typings

- script:
name: install npm dependencies
code: meteor npm install

- script:
name: typings install
code: typings install


- script:
name: running gagarin tests
code: meteor npm test
Expand Down

0 comments on commit 2c34c78

Please sign in to comment.