@@ -3,6 +3,8 @@ import { Meteor } from 'meteor/meteor';
33
44import { Roles } from './users.ts' ;
55
6+ declare var validateLab : any ;
7+ import validateLab = require( '../server/imports/lab/checkLab' ) ;
68export const labs : any = new Mongo . Collection ( 'labs' ) ;
79
810/**
@@ -93,10 +95,30 @@ labs.allow({
9395 if ( Meteor . isServer ) {
9496 Meteor . startup ( function ( ) {
9597 var LabValidator = function ( userid , doc , fieldNames ?, modifier ?, options ?) {
96- if ( typeof fieldNames === "undefined" || fieldNames . includes ( 'tasks' ) || fieldNames . includes ( 'file' ) ) {
98+ if ( typeof fieldNames === "undefined" ) {
99+ console . log ( "inserting" ) ;
100+ if ( ! ( doc . course_id && doc . file && //check for lab fields
101+ ( Meteor . isServer || Roles . isInstructorFor ( doc . course_id , userid ) ) && //check for instructor authorization
102+ validateLab ( doc . file ) ) ) { //check for labfile errors
103+ return false ;
104+ }
105+
97106 //TODO @CEM : Validate Lab
98107 //TODO @CEM : Generate tasks array
99108 }
109+ else if ( fieldNames . includes ( 'tasks' ) && ! fieldNames . includes ( 'file' ) ) {
110+ return false ;
111+ }
112+ else if ( fieldNames . includes ( 'file' ) ) {
113+ if ( ! ( ( Meteor . isServer || Roles . isInstructorFor ( doc . course_id , userid ) ) && //check for instructor authorization
114+ validateLab ( modifier . $set . file ) ) ) { //check for labfile errors
115+ return false ;
116+ }
117+ else {
118+ if ( modifier ) { modifier . $set . updated = Date . now ( ) ; }
119+ doc . updated = Date . now ( ) ;
120+ }
121+ }
100122 }
101123 labs . before . update ( LabValidator ) ;
102124 labs . before . insert ( LabValidator ) ;
0 commit comments