Merge branch with master

This commit is contained in:
Kenneth Jao 2016-08-18 18:48:32 -04:00
commit 80459a006b
6 changed files with 306 additions and 218 deletions

View File

@ -12,3 +12,4 @@ notices-for-facebook-graph-api-2
1.2.0-breaking-changes 1.2.0-breaking-changes
1.3.0-split-minifiers-package 1.3.0-split-minifiers-package
1.4.0-remove-old-dev-bundle-link 1.4.0-remove-old-dev-bundle-link
1.4.1-add-shell-server-package

View File

@ -6,23 +6,23 @@
meteor-base@1.0.4 # Packages every Meteor app needs to have meteor-base@1.0.4 # Packages every Meteor app needs to have
mobile-experience@1.0.4 # Packages for a great mobile UX mobile-experience@1.0.4 # Packages for a great mobile UX
mongo@1.1.10 # The database Meteor supports right now mongo@1.1.11 # The database Meteor supports right now
blaze-html-templates@1.0.4 # Compile .html files into Meteor Blaze views blaze-html-templates@1.0.4 # Compile .html files into Meteor Blaze views
reactive-var@1.0.10 # Reactive variable for tracker reactive-var@1.0.10 # Reactive variable for tracker
jquery@1.11.9 # Helpful client-side library jquery@1.11.9 # Helpful client-side library
tracker@1.1.0 # Meteor's client-side reactive programming library tracker@1.1.0 # Meteor's client-side reactive programming library
standard-minifier-css@1.1.8 # CSS minifier run for production mode standard-minifier-css@1.2.0 # CSS minifier run for production mode
standard-minifier-js@1.1.8 # JS minifier run for production mode standard-minifier-js@1.2.0 # JS minifier run for production mode
es5-shim@4.6.13 # ECMAScript 5 compatibility for older browsers. es5-shim@4.6.14 # ECMAScript 5 compatibility for older browsers.
ecmascript@0.5.7 # Enable ECMAScript2015+ syntax in app code ecmascript@0.5.8 # Enable ECMAScript2015+ syntax in app code
fortawesome:fontawesome fortawesome:fontawesome
session session@1.1.6
proyk:meteor-cookies proyk:meteor-cookies
aldeed:simple-schema aldeed:simple-schema
accounts-google accounts-google@1.0.10
accounts-ui accounts-ui@1.1.9
iron:router iron:router
ongoworks:security ongoworks:security
mizzao:autocomplete mizzao:autocomplete
@ -30,3 +30,4 @@ alanning:roles
rzymek:fullcalendar rzymek:fullcalendar
momentjs:moment momentjs:moment
eternicode:bootstrap-datepicker eternicode:bootstrap-datepicker
shell-server

View File

@ -1 +1 @@
METEOR@1.4.0.1 METEOR@1.4.1

View File

@ -1,4 +1,4 @@
accounts-base@1.2.9 accounts-base@1.2.11
accounts-google@1.0.10 accounts-google@1.0.10
accounts-oauth@1.1.13 accounts-oauth@1.1.13
accounts-ui@1.1.9 accounts-ui@1.1.9
@ -6,41 +6,41 @@ accounts-ui-unstyled@1.1.12
alanning:roles@1.2.15 alanning:roles@1.2.15
aldeed:simple-schema@1.5.3 aldeed:simple-schema@1.5.3
allow-deny@1.0.5 allow-deny@1.0.5
autoupdate@1.2.11 autoupdate@1.3.11
babel-compiler@6.9.0 babel-compiler@6.9.1
babel-runtime@0.1.10 babel-runtime@0.1.11
base64@1.0.9 base64@1.0.9
binary-heap@1.0.9 binary-heap@1.0.9
blaze@2.1.8 blaze@2.1.8
blaze-html-templates@1.0.4 blaze-html-templates@1.0.4
blaze-tools@1.0.9 blaze-tools@1.0.9
boilerplate-generator@1.0.9 boilerplate-generator@1.0.9
caching-compiler@1.0.6 caching-compiler@1.1.7
caching-html-compiler@1.0.6 caching-html-compiler@1.0.6
callback-hook@1.0.9 callback-hook@1.0.9
check@1.2.3 check@1.2.3
coffeescript@1.0.17 coffeescript@1.2.4
dandv:caret-position@2.1.1 dandv:caret-position@2.1.1
ddp@1.2.5 ddp@1.2.5
ddp-client@1.2.9 ddp-client@1.3.1
ddp-common@1.2.6 ddp-common@1.2.6
ddp-rate-limiter@1.0.5 ddp-rate-limiter@1.0.5
ddp-server@1.2.10 ddp-server@1.3.10
deps@1.0.12 deps@1.0.12
diff-sequence@1.0.6 diff-sequence@1.0.6
ecmascript@0.5.7 ecmascript@0.5.8
ecmascript-runtime@0.3.12 ecmascript-runtime@0.3.14
ejson@1.0.12 ejson@1.0.12
es5-shim@4.6.13 es5-shim@4.6.14
eternicode:bootstrap-datepicker@1.6.0_3 eternicode:bootstrap-datepicker@1.6.0_3
fastclick@1.0.12 fastclick@1.0.12
fortawesome:fontawesome@4.5.0 fortawesome:fontawesome@4.5.0
geojson-utils@1.0.9 geojson-utils@1.0.9
google@1.1.13 google@1.1.14
hot-code-push@1.0.4 hot-code-push@1.0.4
html-tools@1.0.10 html-tools@1.0.10
htmljs@1.0.10 htmljs@1.0.10
http@1.1.8 http@1.2.9
id-map@1.0.8 id-map@1.0.8
iron:controller@1.0.12 iron:controller@1.0.12
iron:core@1.0.11 iron:core@1.0.11
@ -52,31 +52,31 @@ iron:router@1.0.13
iron:url@1.0.11 iron:url@1.0.11
jquery@1.11.9 jquery@1.11.9
launch-screen@1.0.12 launch-screen@1.0.12
less@2.6.5 less@2.7.5
livedata@1.0.18 livedata@1.0.18
localstorage@1.0.11 localstorage@1.0.11
logging@1.1.14 logging@1.1.15
mdg:validation-error@0.2.0 mdg:validation-error@0.5.1
meteor@1.2.16 meteor@1.2.17
meteor-base@1.0.4 meteor-base@1.0.4
minifier-css@1.2.13 minifier-css@1.2.14
minifier-js@1.2.13 minifier-js@1.2.14
minimongo@1.0.17 minimongo@1.0.17
mizzao:autocomplete@0.5.1 mizzao:autocomplete@0.5.1
mobile-experience@1.0.4 mobile-experience@1.0.4
mobile-status-bar@1.0.12 mobile-status-bar@1.0.12
modules@0.7.5 modules@0.7.6
modules-runtime@0.7.5 modules-runtime@0.7.6
momentjs:moment@2.8.4 momentjs:moment@2.14.4
mongo@1.1.10 mongo@1.1.11
mongo-id@1.0.5 mongo-id@1.0.5
npm-mongo@1.5.45 npm-mongo@1.5.46
oauth@1.1.11 oauth@1.1.11
oauth2@1.1.10 oauth2@1.1.10
observe-sequence@1.0.12 observe-sequence@1.0.12
ongoworks:security@2.0.1 ongoworks:security@2.0.1
ordered-dict@1.0.8 ordered-dict@1.0.8
promise@0.8.3 promise@0.8.4
proyk:meteor-cookies@0.0.1 proyk:meteor-cookies@0.0.1
random@1.0.10 random@1.0.10
rate-limit@1.0.5 rate-limit@1.0.5
@ -88,15 +88,16 @@ routepolicy@1.0.11
rzymek:fullcalendar@2.7.2 rzymek:fullcalendar@2.7.2
service-configuration@1.0.10 service-configuration@1.0.10
session@1.1.6 session@1.1.6
shell-server@0.2.1
spacebars@1.0.12 spacebars@1.0.12
spacebars-compiler@1.0.12 spacebars-compiler@1.0.12
standard-minifier-css@1.1.8 standard-minifier-css@1.2.0
standard-minifier-js@1.1.8 standard-minifier-js@1.2.0
templating@1.1.14 templating@1.2.14
templating-tools@1.0.4 templating-tools@1.0.4
tracker@1.1.0 tracker@1.1.0
ui@1.0.11 ui@1.0.11
underscore@1.0.9 underscore@1.0.9
url@1.0.10 url@1.0.10
webapp@1.3.10 webapp@1.3.11
webapp-hashing@1.0.9 webapp-hashing@1.0.9

View File

@ -24,8 +24,8 @@ var themeColors = {
}; };
var workColors = { var workColors = {
"normal": "#2E4F74", "normal": "#2E4F74",
"quiz": "#409333", "quiz": "#409333",
"test": "#AD3C44", "test": "#AD3C44",
"project": "#E6E619", "project": "#E6E619",
"other": "#852E6D" "other": "#852E6D"
@ -57,35 +57,50 @@ Template.registerHelper('overlayDim', (part) => {
}); });
Template.registerHelper('myClasses', () => { Template.registerHelper('myClasses', () => {
if (Meteor.user().profile.classes === undefined || Meteor.user().profile.classes.length === 0) { if (Meteor.user().profile.classes === undefined || Meteor.user().profile.classes.length === 0) {
Session.set("noclass",true); Session.set("noclass",true);
return []; return [];
} else { } else {
var array = []; var array = [];
var courses = Meteor.user().profile.classes; var courses = Meteor.user().profile.classes;
for(var i = 0; i < courses.length; i++) { for(var i = 0; i < courses.length; i++) {
found = classes.findOne({_id:courses[i]}); found = classes.findOne({_id:courses[i]});
found.subscribers = found.subscribers.length; found.subscribers = found.subscribers.length;
if(found.admin === Meteor.userId()) found.box = " owned"; if(found.admin === Meteor.userId()) found.box = " owned";
array.push(found); array.push(found);
var thisWork = work.find({class: courses[i]}).fetch(); var thisWork = work.find({class: courses[i]}).fetch();
for(var j = 0; j < thisWork.length; j++) { for(var j = 0; j < thisWork.length; j++) {
thisWork[j].dueDate = getReadableDate(thisWork[j].dueDate); thisWork[j].dueDate = moment(thisWork[j].dueDate).calendar(null, {
thisWork[j].typeColor = workColors[thisWork[j].type]; sameDay: '[Today]',
} nextDay: '[Tomorrow]',
array[i].thisClassWork = thisWork; nextWeek: 'dddd',
} lastDay: '[Yesterday]',
lastWeek: '[Last] dddd',
sameElse: 'MMMM Do'
});
thisWork[j].typeColor = workColors[thisWork[j].type];
}
array[i].thisClassWork = thisWork;
}
Session.set("noclass",false); Session.set("noclass",false);
<<<<<<< HEAD
console.log(array); console.log(array);
return array; return array;
=======
return array;
>>>>>>> afd60acb9ab69a32ee86ae92e86e0d67e39af7be
} }
}); });
Template.main.helpers({ Template.main.helpers({
schoolName() { schoolName() {
<<<<<<< HEAD
Session.set("calendarclasses", Meteor.user().profile.classes); Session.set("calendarclasses", Meteor.user().profile.classes);
=======
Session.set("calendarclasses", Meteor.user().profile.classes);
>>>>>>> afd60acb9ab69a32ee86ae92e86e0d67e39af7be
return " - " + Meteor.user().profile.school; return " - " + Meteor.user().profile.school;
}, },
iconColor(icon) { iconColor(icon) {
@ -175,31 +190,31 @@ Template.main.helpers({
}, },
work(value) { work(value) {
if(Session.get("currentWork") === null) return; if(Session.get("currentWork") === null) return;
return Session.get("currentReadableWork")[value]; return Session.get("currentReadableWork")[value];
}, },
workType() { workType() {
if(Session.get("currentWork") === null) return; if(Session.get("currentWork") === null) return;
type = Session.get("currentWork").type; type = Session.get("currentWork").type;
if(type.includes("edit")) { if(type.includes("edit")) {
return; return;
} else { } else {
return workColors[type]; return workColors[type];
} }
}, },
newWork() { newWork() {
return Session.get("newWork"); return Session.get("newWork");
}, },
inRole() { inRole() {
if(Session.get("newWork")) { if(Session.get("newWork")) {
return true; return true;
} else { } else {
if(Meteor.userId() === Session.get("currentWork").creator || if(Meteor.userId() === Session.get("currentWork").creator ||
Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']) || Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']) ||
classes.findOne({_id: Session.get("currentWork")._id}).moderators.indexOf(Meteor.userId()) !== -1|| classes.findOne({_id: Session.get("currentWork")._id}).moderators.indexOf(Meteor.userId()) !== -1||
classes.findOne({_id: Session.get("currentWork")._id}).blockEdit.indexOf(Meteor.userId()) !== -1 || classes.findOne({_id: Session.get("currentWork")._id}).blockEdit.indexOf(Meteor.userId()) !== -1 ||
classes.findOne({_id: Session.get("currentWork")._id}).banned.indexOf(Meteor.userId()) !== -1 classes.findOne({_id: Session.get("currentWork")._id}).banned.indexOf(Meteor.userId()) !== -1
) return true; ) return true;
} }
} }
}); });
@ -257,13 +272,13 @@ Template.main.events({
Session.set("sidebar", null); Session.set("sidebar", null);
} }
if(e === "overlay") { if(e === "overlay") {
closeDivFade(document.getElementsByClassName("overlay")[0]); closeDivFade(document.getElementsByClassName("overlay")[0]);
if(!Session.get("newWork")) { if(!Session.get("newWork")) {
if(getHomeworkFormData() === null) return; if(getHomeworkFormData() === null) return;
Session.set("serverData",Session.get("currentWork")); Session.set("serverData",Session.get("currentWork"));
sendData("editWork"); sendData("editWork");
} }
Session.set("newWork",null); Session.set("newWork",null);
} }
if (event.target.id !== sessval && if (event.target.id !== sessval &&
@ -273,9 +288,9 @@ Template.main.events({
closeInput(sessval); closeInput(sessval);
} }
if (!event.target.className.includes("radio") && if (!event.target.className.includes("radio") &&
!Session.equals("radioDiv", null) && !Session.equals("radioDiv", null) &&
!event.target.parentNode.className.includes("workOptions") && !event.target.parentNode.className.includes("workOptions") &&
event.target.readOnly !== true) { event.target.readOnly !== true) {
var opnum = (parseInt(Session.get("radioDiv")) - parseInt(Session.get("radioOffset"))).toString(); var opnum = (parseInt(Session.get("radioDiv")) - parseInt(Session.get("radioOffset"))).toString();
for (var i = 0; i < document.getElementsByClassName("workOptions").length; i++) { for (var i = 0; i < document.getElementsByClassName("workOptions").length; i++) {
try { try {
@ -287,20 +302,20 @@ Template.main.events({
} }
}, },
'click .creWork' (event) { 'click .creWork' (event) {
if(event.target.className !== "creWork") { if(event.target.className !== "creWork") {
var attr = event.target.parentNode.getAttribute("classid"); var attr = event.target.parentNode.getAttribute("classid");
} else { } else {
var attr = event.target.getAttribute("classid"); var attr = event.target.getAttribute("classid");
} }
Session.set("newWork", true); Session.set("newWork", true);
Session.set("currentReadableWork", Session.set("currentReadableWork",
{ {
name:"Name | Click here to edit...", name:"Name | Click here to edit...",
class:attr, class:attr,
dueDate:"Click here to edit...", dueDate:"Click here to edit...",
description:"Click here to edit...", description:"Click here to edit...",
type:"Click here to edit..." type:"Click here to edit..."
}); });
Session.set("currentWork",{class:attr}); Session.set("currentWork",{class:attr});
openDivFade(document.getElementsByClassName("overlay")[0]); openDivFade(document.getElementsByClassName("overlay")[0]);
}, },
@ -329,11 +344,11 @@ Template.main.events({
input.style.height = 3 * dim.height.toString() + "px"; input.style.height = 3 * dim.height.toString() + "px";
input.rows = "4"; input.rows = "4";
} else if (typ !== null) { } else if (typ !== null) {
input.type = typ; input.type = typ;
input.style.height = 0.9 * dim.height.toString() + "px"; input.style.height = 0.9 * dim.height.toString() + "px";
} else { } else {
input.typ = "text"; input.typ = "text";
input.style.height = 0.9 * dim.height.toString() + "px"; input.style.height = 0.9 * dim.height.toString() + "px";
} }
input.value = ele.childNodes[0].nodeValue; input.value = ele.childNodes[0].nodeValue;
input.className = "changeInput"; input.className = "changeInput";
@ -351,7 +366,7 @@ Template.main.events({
input.select(); input.select();
} }
if(ele.id === "workDate") { if(ele.id === "workDate") {
input.className += " form-control"; input.className += " form-control";
} }
input.focus(); input.focus();
if (ele.getAttribute("restrict") !== null) { if (ele.getAttribute("restrict") !== null) {
@ -424,37 +439,38 @@ Template.main.events({
} }
}, },
'click #workSubmit' () { 'click #workSubmit' () {
if(getHomeworkFormData() === null) return; if(getHomeworkFormData() === null) return;
Session.set("serverData",Session.get("currentWork")); Session.set("serverData",Session.get("currentWork"));
if(Session.get("newWork")) { if(Session.get("newWork")) {
sendData("createWork"); sendData("createWork");
} else { } else {
sendData("editWork"); sendData("editWork");
} }
Session.set("newWork",null); Session.set("newWork",null);
closeDivFade(document.getElementsByClassName("overlay")[0]); closeDivFade(document.getElementsByClassName("overlay")[0]);
}, },
'focus .op' (event) { 'focus .op' (event) {
event.target.click(); event.target.click();
}, },
'click .workCard' (event) { 'click .workCard' (event) {
var dom = event.target; var dom = event.target;
while(event.target.className !== "workCard") event.target = event.target.parentNode; while(event.target.className !== "workCard") event.target = event.target.parentNode;
workid = event.target.getAttribute("workid"); workid = event.target.getAttribute("workid");
Session.set("newWork",false); Session.set("newWork",false);
var thisWork = work.findOne({_id:workid}); var thisWork = work.findOne({_id:workid});
Session.set("currentWork",thisWork); Session.set("currentWork",thisWork);
var thisReadWork = formReadable(thisWork); var thisReadWork = formReadable(thisWork);
Session.set("currentReadableWork",thisReadWork); Session.set("currentReadableWork",thisReadWork);
openDivFade(document.getElementsByClassName("overlay")[0]); openDivFade(document.getElementsByClassName("overlay")[0]);
}, },
'focus #workDatea' () { 'focus #workDatea' () {
$('#workDatea').datepicker({ $('#workDatea').datepicker({
format: 'DD, MM d, yyyy', format: 'DD, MM d, yyyy',
startDate: 'mm-dd-yyyy', startDate: 'd',
autoclose: true, todayHighlight: true,
autoclose: true
}); });
} }
}); });
@ -494,59 +510,59 @@ function closeInput(sessval) {
span.style.display = "initial"; span.style.display = "initial";
Session.set("modifying", null); Session.set("modifying", null);
if(!Session.get("newWork")) { if(!Session.get("newWork")) {
if(getHomeworkFormData() === null) return; if(getHomeworkFormData() === null) return;
Session.set("serverData",Session.get("currentWork")); Session.set("serverData",Session.get("currentWork"));
sendData("editWork"); sendData("editWork");
} }
} }
function getHomeworkFormData() { function getHomeworkFormData() {
var inputs = document.getElementsByClassName("req"); var inputs = document.getElementsByClassName("req");
var stop; var stop;
for(var i = 0; i < inputs.length; i++) { for(var i = 0; i < inputs.length; i++) {
var value = inputs[i].childNodes[0].nodeValue; var value = inputs[i].childNodes[0].nodeValue;
if(value.includes("Click here to edit")) { if(value.includes("Click here to edit")) {
inputs[i].childNodes[0].nodeValue = "Missing field"; inputs[i].childNodes[0].nodeValue = "Missing field";
inputs[i].style.color = "#FF1A1A"; inputs[i].style.color = "#FF1A1A";
stop = true; stop = true;
} }
} }
var desc = document.getElementById("workDesc"); var desc = document.getElementById("workDesc");
if(desc.childNodes[0].nodeValue.includes("Click here to edit")) { if(desc.childNodes[0].nodeValue.includes("Click here to edit")) {
desc.childNodes[0].nodeValue = "Missing field"; desc.childNodes[0].nodeValue = "Missing field";
desc.style.color = "#FF1A1A"; desc.style.color = "#FF1A1A";
stop = true; stop = true;
} }
if(stop) return null; if(stop) return null;
var data = Session.get("currentWork"); var data = Session.get("currentWork");
data.name = document.getElementById("workName").childNodes[0].nodeValue; data.name = document.getElementById("workName").childNodes[0].nodeValue;
data.dueDate = toDate(document.getElementById("workDate").childNodes[0].nodeValue); data.dueDate = toDate(document.getElementById("workDate").childNodes[0].nodeValue);
data.description = document.getElementById("workDesc").childNodes[0].nodeValue; data.description = document.getElementById("workDesc").childNodes[0].nodeValue;
data.type = document.getElementById("workType").childNodes[0].nodeValue.toLowerCase(); data.type = document.getElementById("workType").childNodes[0].nodeValue.toLowerCase();
Session.set("currentWork", data); Session.set("currentWork", data);
var readableData = formReadable(data); var readableData = formReadable(data);
Session.set("currentReadableWork", readableData); Session.set("currentReadableWork", readableData);
} }
var days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]; var days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
var months = ["January","February","March","April","May","June","July","August","September","October","November","December"]; var months = ["January","February","March","April","May","June","July","August","September","October","November","December"];
function getReadableDate(date) { function getReadableDate(date) {
return days[date.getDay()]+", "+months[date.getMonth()]+" "+date.getDate()+", "+date.getFullYear(); return days[date.getDay()]+", "+months[date.getMonth()]+" "+date.getDate()+", "+date.getFullYear();
} }
function toDate(date) { function toDate(date) {
date = date.substring(date.search(",")+2,date.length); date = date.substring(date.search(",")+2,date.length);
month = months.indexOf(date.substring(0,date.search(" "))); month = months.indexOf(date.substring(0,date.search(" ")));
day = date.substring(date.search(" ")+1,date.search(",")); day = date.substring(date.search(" ")+1,date.search(","));
year = date.substring(date.search(",")+2,date.length); year = date.substring(date.search(",")+2,date.length);
return new Date(year,month,day,11,59,59); return new Date(year,month,day,11,59,59);
} }
function formReadable(input) { function formReadable(input) {
input.dueDate = getReadableDate(input.dueDate); input.dueDate = getReadableDate(input.dueDate);
input.type = input.type[0].toUpperCase() + input.type.slice(1); input.type = input.type[0].toUpperCase() + input.type.slice(1);
return input; return input;
} }

View File

@ -5,18 +5,13 @@ import {
Mongo Mongo
} from 'meteor/mongo'; } from 'meteor/mongo';
_uuid4 = function(cc) {
var rr = Math.random() * 16 | 0;
return (cc === 'x' ? rr : (rr & 0x3 | 0x8)).toString(16);
};
superadmins = [ superadmins = [
"ybq987@gmail.com", "ybq987@gmail.com",
"ksjdragon@gmail.com" "ksjdragon@gmail.com"
]; ];
worktype = ["test", "quiz", "project", "normal"]; worktype = ["test", "quiz", "project", "normal", "other"];
var possiblelist = ["moderators","banned"]; var possiblelist = ["moderators", "banned"];
for (var i = 0; i < superadmins.length; i++) { for (var i = 0; i < superadmins.length; i++) {
var superadmin = superadmins[i]; var superadmin = superadmins[i];
@ -81,7 +76,11 @@ Meteor.publish('users', function() {
if (Roles.userIsInRole(this.userId, ['superadmin', 'admin'])) { if (Roles.userIsInRole(this.userId, ['superadmin', 'admin'])) {
return Meteor.users.find(); return Meteor.users.find();
} else { } else {
return Meteor.users.find({}, {fields: {'services.google.email': 1}}); return Meteor.users.find({}, {
fields: {
'services.google.email': 1
}
});
} }
}); });
@ -89,7 +88,7 @@ Security.permit(['insert', 'update', 'remove']).collections([schools, classes, w
Meteor.methods({ Meteor.methods({
'genCode': function() { 'genCode': function() {
return 'xxxxxx'.replace(/[x]/g, _uuid4); return Math.random().toString(36).substring(7);
}, },
'createSchool': function(schoolname) { 'createSchool': function(schoolname) {
if (Meteor.user() !== null && if (Meteor.user() !== null &&
@ -153,41 +152,69 @@ Meteor.methods({
classes.insert(input, function(err, result) { classes.insert(input, function(err, result) {
Meteor.call('joinClass', [result, input.code]); Meteor.call('joinClass', [result, input.code]);
}); });
return 1; return 1;
} else { } else {
throw "Unauthorized"; throw "Unauthorized";
} }
}, },
'changeAdmin': function(input) { 'changeAdmin': function(input) {
var found = Meteor.users.find({_id: input[0]}); var found = Meteor.users.find({
var foundclass = classes.find({_id: input[1]}); _id: input[0]
});
var foundclass = classes.find({
_id: input[1]
});
if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) { if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) {
classes.update({_id: input[1]}, {$set: {admin: input[0]}}); classes.update({
_id: input[1]
}, {
$set: {
admin: input[0]
}
});
} else if (found && foundclass && foundclass.admin == Meteor.userId() && } else if (found && foundclass && foundclass.admin == Meteor.userId() &&
foundclass.banned.indexOf(input[0]) === -1 && foundclass.banned.indexOf(input[0]) === -1 &&
foundclass.subscribers.indexOf(input[0]) !== -1) { foundclass.subscribers.indexOf(input[0]) !== -1) {
classes.update({_id: input[1]}, {$set: {admin: input[0]}}); classes.update({
_id: input[1]
}, {
$set: {
admin: input[0]
}
});
} else { } else {
throw "Unauthorized"; throw "Unauthorized";
} }
}, },
'trackUserInClass': function(input) { 'trackUserInClass': function(input) {
var foundclass = classes.findOne({_id: input[1]}); var foundclass = classes.findOne({
_id: input[1]
});
var userlist = input[2]; var userlist = input[2];
var index = possiblelist.indexOf(input[2]); var index = possiblelist.indexOf(input[2]);
var set = {}; var set = {};
set[userlist] = foundclass[userlist].concat(input[0]); set[userlist] = foundclass[userlist].concat(input[0]);
if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) { if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) {
classes.update({_id: input[1]}, {$set: set}); classes.update({
_id: input[1]
}, {
$set: set
});
} else if (foundclass && foundclass.admin == Meteor.userId() && index !== -1 && } else if (foundclass && foundclass.admin == Meteor.userId() && index !== -1 &&
(index === 1 || foundclass.moderators.indexOf(Meteor.userId()) !== -1) && (index === 1 || foundclass.moderators.indexOf(Meteor.userId()) !== -1) &&
foundclass[userlist].indexOf(input[0]) === -1) { foundclass[userlist].indexOf(input[0]) === -1) {
classes.update({_id: input[1]}, {$set: set}); classes.update({
_id: input[1]
}, {
$set: set
});
} }
}, },
'untrackUserInClass': function(input) { 'untrackUserInClass': function(input) {
var foundclass = classes.findOne({_id: input[1]}); var foundclass = classes.findOne({
_id: input[1]
});
var userlist = input[2]; var userlist = input[2];
var index = possiblelist.indexOf(input[2]); var index = possiblelist.indexOf(input[2]);
var set = {}; var set = {};
@ -195,21 +222,31 @@ Meteor.methods({
set[userlist] = foundclass[userlist]; set[userlist] = foundclass[userlist];
if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) { if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) {
classes.update({_id: input[1]}, {$set: set}); classes.update({
_id: input[1]
}, {
$set: set
});
} else if (foundclass && foundclass.admin == Meteor.userId() && index !== -1 && } else if (foundclass && foundclass.admin == Meteor.userId() && index !== -1 &&
(index === 1 || foundclass.moderators.indexOf(Meteor.userId()) !== -1) && (index === 1 || foundclass.moderators.indexOf(Meteor.userId()) !== -1) &&
foundclass[userlist].indexOf(input[0]) !== -1) { foundclass[userlist].indexOf(input[0]) !== -1) {
classes.update({_id: input[1]}, {$set: set}); classes.update({
_id: input[1]
}, {
$set: set
});
} }
}, },
'deleteClass': function(classid) { 'deleteClass': function(classid) {
var found = classes.findOne({ var found = classes.findOne({
_id: classid _id: classid
}); });
if (Meteor.user() !== null && found !== null && if (Meteor.user() !== null && found !== null &&
(found.admin === Meteor.user()._id || Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']))) { (found.admin === Meteor.user()._id || Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']))) {
for (var i = 0; i < found.subscribers.length; i++) { for (var i = 0; i < found.subscribers.length; i++) {
var current = Meteor.users.findOne({_id:found.subscribers[i]}).profile; var current = Meteor.users.findOne({
_id: found.subscribers[i]
}).profile;
var index = current.classes.indexOf(classid); var index = current.classes.indexOf(classid);
current.classes.splice(index, 1); current.classes.splice(index, 1);
Meteor.users.update({ Meteor.users.update({
@ -226,7 +263,9 @@ Meteor.methods({
} }
}, },
'createWork': function(input) { 'createWork': function(input) {
var ref = new Date().getTime(); var ref = new Date();
ref.setHours(0,0,0,0);
ref = ref.getTime();
input.creator = Meteor.userId(); input.creator = Meteor.userId();
work.schema.validate(input); work.schema.validate(input);
var found = classes.findOne({ var found = classes.findOne({
@ -234,12 +273,12 @@ Meteor.methods({
}); });
if (Meteor.user() !== null && if (Meteor.user() !== null &&
found !== null && found !== null &&
Meteor.user().profile.classes.indexOf(input.class) !== -1 && Meteor.user().profile.classes.indexOf(input.class) !== -1 &&
found.banned.indexOf(Meteor.userId()) === -1 && found.banned.indexOf(Meteor.userId()) === -1 &&
input.dueDate instanceof Date && input.dueDate.getTime() >= ref && input.dueDate instanceof Date && input.dueDate.getTime() >= ref &&
worktype.indexOf(input.type) != -1 && worktype.indexOf(input.type) != -1 &&
input.name.length <= 50 && input.description.length <= 150) { input.name.length <= 50 && input.description.length <= 150) {
input.confirmations = [Meteor.userId()]; input.confirmations = [Meteor.userId()];
input.reports = []; input.reports = [];
@ -251,8 +290,9 @@ Meteor.methods({
}, },
'editWork': function(change) { 'editWork': function(change) {
var ref = new Date().getTime(); var ref = new Date();
ref.setHours(0,0,0,0);
ref = ref.getTime();
var currentclass = classes.findOne({ var currentclass = classes.findOne({
_id: work.findOne({ _id: work.findOne({
_id: change._id _id: change._id
@ -284,7 +324,7 @@ Meteor.methods({
_id: change._id _id: change._id
}).creator) { }).creator) {
if (change.name.length <= 50 && worktype.indexOf(change.type) != -1 && if (change.name.length <= 50 && worktype.indexOf(change.type) != -1 &&
input.dueDate instanceof Date && input.dueDate.getTime() >= ref) { input.dueDate instanceof Date && input.dueDate.getTime() >= ref) {
Meteor.update({ Meteor.update({
_id: change._id _id: change._id
}, { }, {
@ -310,15 +350,15 @@ Meteor.methods({
}); });
var user = Meteor.userId(); var user = Meteor.userId();
if (typeof comment === "string" && comment.length <= 200 && if (typeof comment === "string" && comment.length <= 200 &&
currentclass.subscribers.indexOf(Meteor.userId()) != -1 && currentclass.subscribers.indexOf(Meteor.userId()) != -1 &&
currentclass.banned.indexOf(Meteor.userId()) === -1) { currentclass.banned.indexOf(Meteor.userId()) === -1) {
var comments = workobject.comments.concat(comment); var comments = workobject.comments.concat(comment);
work.update({ work.update({
_id: input[1] _id: input[1]
}, { }, {
$set: { $set: {
comments: comments, comments: comments,
user:user, user: user,
time: new Date() time: new Date()
} }
}); });
@ -331,8 +371,7 @@ Meteor.methods({
var currentclass = classes.findOne({ var currentclass = classes.findOne({
_id: workobject.class _id: workobject.class
}); });
if (currentclass.subscribers.indexOf(Meteor.userId()) != -1 && if (currentclass.subscribers.indexOf(Meteor.userId()) != -1 && ["confirmations", "reports", "done"].indexOf(input[1]) != -1) {
["confirmations", "reports", "done"].indexOf(input[1]) != -1) {
userindex = workobject[input[1]].indexOf(Meteor.userId()); userindex = workobject[input[1]].indexOf(Meteor.userId());
if (userindex === -1) { if (userindex === -1) {
workobject[input[1]] = workobject[input[1]].concat(Meteor.userId()); workobject[input[1]] = workobject[input[1]].concat(Meteor.userId());
@ -374,10 +413,10 @@ Meteor.methods({
current.banner = change.banner; current.banner = change.banner;
current.preferences = change.preferences; current.preferences = change.preferences;
if (schools.findOne({ if (schools.findOne({
name: current.school name: current.school
}) !== null && }) !== null &&
Number.isInteger(current.grade) && Number.isInteger(current.grade) &&
current.grade >= 9 && current.grade <= 12) { current.grade >= 9 && current.grade <= 12) {
if (current.description && current.description.length > 50) { if (current.description && current.description.length > 50) {
current.description = current.description.slice(0, 50); current.description = current.description.slice(0, 50);
@ -403,10 +442,16 @@ Meteor.methods({
status: true status: true
}); });
if (Meteor.user() !== null && if (Meteor.user() !== null &&
found !== null && found !== null &&
pass === found.code && pass === found.code &&
prof.classes.indexOf(change) === -1) { prof.classes.indexOf(change) === -1) {
classes.update({_id: found._id}, {$set: {subscribers: found.subscribers.concat(Meteor.userId())}}); classes.update({
_id: found._id
}, {
$set: {
subscribers: found.subscribers.concat(Meteor.userId())
}
});
var current = Meteor.user().profile; var current = Meteor.user().profile;
current.classes = current.classes.concat(change); current.classes = current.classes.concat(change);
Meteor.users.update({ Meteor.users.update({
@ -422,13 +467,29 @@ Meteor.methods({
} }
}, },
'joinPrivateClass': function(input) { 'joinPrivateClass': function(input) {
var found = classes.findOne({status: true, privacy: true, code:input}); var found = classes.findOne({
status: true,
privacy: true,
code: input
});
var current = Meteor.user().profile; var current = Meteor.user().profile;
if (found !== undefined && input !== undefined && if (found !== undefined && input !== undefined &&
current.classes.indexOf(found._id) === -1) { current.classes.indexOf(found._id) === -1) {
classes.update({_id: found._id}, {$set: {subscribers: found.subscribers.concat(Meteor.userId())}}); classes.update({
_id: found._id
}, {
$set: {
subscribers: found.subscribers.concat(Meteor.userId())
}
});
current.classes = current.classes.concat(found._id); current.classes = current.classes.concat(found._id);
Meteor.users.update({_id: Meteor.userId()}, {$set: {profile: current}}); Meteor.users.update({
_id: Meteor.userId()
}, {
$set: {
profile: current
}
});
return true; return true;
} else { } else {
return false; return false;
@ -450,8 +511,16 @@ Meteor.methods({
profile: current profile: current
} }
}); });
var newstudents = classes.findOne({_id: change}).subscribers.splice(Meteor.userId(), 1); var newstudents = classes.findOne({
classes.update({_id: change}, {$set: {subscribers: newstudents}}); _id: change
}).subscribers.splice(Meteor.userId(), 1);
classes.update({
_id: change
}, {
$set: {
subscribers: newstudents
}
});
return 1; return 1;
} else { } else {
throw "You are currently the admin of this class. Transfer ownership in order to leave this class."; throw "You are currently the admin of this class. Transfer ownership in order to leave this class.";