This commit is contained in:
Kenneth Jao 2016-08-10 14:43:09 -04:00
commit f1d7e180f0
3 changed files with 19 additions and 3 deletions

View File

@ -29,3 +29,4 @@ iron:router
ongoworks:security ongoworks:security
mizzao:autocomplete mizzao:autocomplete
alanning:roles alanning:roles
rzymek:fullcalendar

View File

@ -68,6 +68,7 @@ mobile-experience@1.0.4
mobile-status-bar@1.0.12 mobile-status-bar@1.0.12
modules@0.7.5 modules@0.7.5
modules-runtime@0.7.5 modules-runtime@0.7.5
momentjs:moment@2.8.4
mongo@1.1.10 mongo@1.1.10
mongo-id@1.0.5 mongo-id@1.0.5
npm-mongo@1.5.45 npm-mongo@1.5.45
@ -85,6 +86,7 @@ reactive-var@1.0.10
reload@1.1.10 reload@1.1.10
retry@1.0.8 retry@1.0.8
routepolicy@1.0.11 routepolicy@1.0.11
rzymek:fullcalendar@2.7.2
service-configuration@1.0.10 service-configuration@1.0.10
session@1.1.6 session@1.1.6
spacebars@1.0.12 spacebars@1.0.12

View File

@ -11,17 +11,23 @@ Meteor.methods({
return 'xxxxxx'.replace(/[x]/g, _uuid4); return 'xxxxxx'.replace(/[x]/g, _uuid4);
}, },
'createSchool': function(schoolname) { 'createSchool': function(schoolname) {
// if superadmin, no need for approval
if (Meteor.user() != null && schools.findOne({name:input.school}) != null && if (Meteor.user() != null && schools.findOne({name:input.school}) != null &&
schools.findOne({status: false, creator: Meteor.userId()}) != null) { schools.findOne({status: false, creator: Meteor.userId()}) != null) {
schools.insert({name: schoolname, status: false, creator: Meteor.userId()}); schools.insert({name: schoolname, status: false, creator: Meteor.userId()});
} }
},
'deleteSchool': function(schoolid) {
// alanning:roles implementation here
schools.remove({_id: schoolid})
}, },
'createClass': function(input) { 'createClass': function(input) {
// if superadmin, no need for approval
classes.schema.validate(input); classes.schema.validate(input);
if(Meteor.user() != null && classes.find({status:false, admin:Meteor.userId()}).fetch().length < 5 && if(Meteor.user() != null && classes.find({status:false, admin:Meteor.userId()}).fetch().length < 5 &&
schools.findOne({name:input.school}) != null && input.status === false) { schools.findOne({name:input.school}) != null) {
input.status = false;
input.subscribers = 0; input.subscribers = 0;
input.admin = Meteor.userId() input.admin = Meteor.userId()
if (input.privacy) { if (input.privacy) {
@ -44,6 +50,13 @@ Meteor.methods({
return 0; return 0;
} }
}, },
'deleteClass': function(classid) {
found = classes.findOne({_id: classid});
// Add roles
if (Meteor.user() != null && found != null && found.admin === Meteor.user()._id) {
classes.remove({_id: classid})
}
},
'editProfile': function(change) { 'editProfile': function(change) {
current = Meteor.user().profile; current = Meteor.user().profile;
current.school = change[0]; current.school = change[0];
@ -61,7 +74,7 @@ Meteor.methods({
}, },
'joinClass': function(change, pass) { 'joinClass': function(change, pass) {
found = classes.findOne({_id: change, status: true}); found = classes.findOne({_id: change, status: true});
if (Meteor.user() != null && found.length > 0 && pass === found[0].code && Meteor.user().profile.classes.indexOf(change) === -1) { if (Meteor.user() != null && found != null && pass === found.code && Meteor.user().profile.classes.indexOf(change) === -1) {
current = Meteor.user().profile; current = Meteor.user().profile;
current.classes.append(change); current.classes.append(change);
Meteor.users.update({_id: Meteor.userId()}, {$set: {profile: current}}); Meteor.users.update({_id: Meteor.userId()}, {$set: {profile: current}});