From 2c4b480e9d336cb294d951ec5baf216c8fcbf162 Mon Sep 17 00:00:00 2001 From: Yaman Qalieh Date: Fri, 12 Aug 2016 20:11:26 -0400 Subject: [PATCH] add publish to server --- hourglass/server/main.js | 66 +++++++++++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 7 deletions(-) diff --git a/hourglass/server/main.js b/hourglass/server/main.js index 0623a26..680563d 100644 --- a/hourglass/server/main.js +++ b/hourglass/server/main.js @@ -17,12 +17,64 @@ superadmins = [ for (var i = 0; i < superadmins.length; i++) { var superadmin = superadmins[i]; - if (Meteor.users.findOne({"services.google.email": superadmin})) { - var userId = Meteor.users.findOne({"services.google.email": superadmin})._id; + if (Meteor.users.findOne({ + "services.google.email": superadmin + })) { + var userId = Meteor.users.findOne({ + "services.google.email": superadmin + })._id; Roles.addUsersToRoles(userId, ['superadmin']); } } +Meteor.publish('schools', function() { + return schools.find(); +}); + +Meteor.publish('classes', function() { + if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) { + return classes.find(); + } else { + return classes.find({ + $or: [{ + privacy: false + }, { + _id: { + $in: Meteor.user().profile.classes + } + }] + }, { + fields: { + school: 1, + name: 1, + hour: 1, + teacher: 1, + admin: 1, + status: 1, + privacy: 1, + category: 1, + moderators: 1, + banned: 1, + blockEdit: 1, + subscribers: 1 + } + }); + } +}); + +Meteor.publish('work', function() { + if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) { + return work.find(); + } else { + return work.find({ + class: { + $in: Meteor.user().profile.classes + } + }); + } + +}); + worktype = ["test", "quiz", "project", "normal"]; Meteor.methods({ 'genCode': function() { @@ -145,13 +197,13 @@ Meteor.methods({ current.banner = change.banner; current.preferences = change.preferences; if (schools.findOne({ - name: current.school - }) !== null && + name: current.school + }) !== null && Number.isInteger(current.grade) && current.grade >= 9 && current.grade <= 12) { if (current.description && current.description.length > 50) { - current.description = current.description.slice(0,50); + current.description = current.description.slice(0, 50); } Meteor.users.update({ _id: Meteor.userId() @@ -199,8 +251,8 @@ Meteor.methods({ index = profile.classes.indexOf(change); if (index >= 0) { if (classes.findOne({ - _id: change - }).admin != Meteor.userId()) { + _id: change + }).admin != Meteor.userId()) { profile.classes.splice(index, 1); Meteor.users.update({ _id: Meteor.userId()