Server bug fixes
This commit is contained in:
parent
b9d22b9958
commit
379f903507
@ -94,7 +94,7 @@ Meteor.methods({
|
|||||||
'createSchool': function(schoolname) {
|
'createSchool': function(schoolname) {
|
||||||
if (Meteor.user() !== null &&
|
if (Meteor.user() !== null &&
|
||||||
schools.findOne({
|
schools.findOne({
|
||||||
name: input.school
|
name: schoolname
|
||||||
}) !== null &&
|
}) !== null &&
|
||||||
schools.findOne({
|
schools.findOne({
|
||||||
status: false,
|
status: false,
|
||||||
@ -135,7 +135,7 @@ Meteor.methods({
|
|||||||
} else {
|
} else {
|
||||||
input.status = false;
|
input.status = false;
|
||||||
}
|
}
|
||||||
input.subscribers = [Meteor.userId()];
|
input.subscribers = [];
|
||||||
input.admin = Meteor.userId();
|
input.admin = Meteor.userId();
|
||||||
if (input.privacy) {
|
if (input.privacy) {
|
||||||
Meteor.call('genCode', function(error, result) {
|
Meteor.call('genCode', function(error, result) {
|
||||||
@ -149,8 +149,11 @@ Meteor.methods({
|
|||||||
}
|
}
|
||||||
input.moderators = [];
|
input.moderators = [];
|
||||||
input.banned = [];
|
input.banned = [];
|
||||||
classes.insert(input);
|
|
||||||
Meteor.call('joinClass', classes.findOne(input)._id, input.code, function(error, result) {});
|
classes.insert(input, function(err, result) {
|
||||||
|
Meteor.call('joinClass', [result, input.code]);
|
||||||
|
});
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
throw "Unauthorized";
|
throw "Unauthorized";
|
||||||
@ -203,9 +206,12 @@ Meteor.methods({
|
|||||||
var found = classes.findOne({
|
var found = classes.findOne({
|
||||||
_id: classid
|
_id: classid
|
||||||
});
|
});
|
||||||
if (Meteor.user() !== null && found !== null && (found.admin === Meteor.user()._id || Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']))) {
|
if (Meteor.user() !== null && found !== null &&
|
||||||
|
(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++) {
|
||||||
profile.classes.splice(index, 1);
|
var current = Meteor.users.findOne({_id:found.subscribers[i]}).profile;
|
||||||
|
var index = current.classes.indexOf(classid);
|
||||||
|
current.classes.splice(index, 1);
|
||||||
Meteor.users.update({
|
Meteor.users.update({
|
||||||
_id: found.subscribers[i]
|
_id: found.subscribers[i]
|
||||||
}, {
|
}, {
|
||||||
@ -228,19 +234,18 @@ 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 = [];
|
||||||
input.done = [];
|
input.done = [];
|
||||||
input.numberdone = 0;
|
input.numberdone = 0;
|
||||||
input.comments = [];
|
input.comments = [];
|
||||||
console.log(input);
|
|
||||||
work.insert(input);
|
work.insert(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,7 +256,7 @@ Meteor.methods({
|
|||||||
var currentclass = classes.findOne({
|
var currentclass = classes.findOne({
|
||||||
_id: work.findOne({
|
_id: work.findOne({
|
||||||
_id: change._id
|
_id: change._id
|
||||||
}).class
|
})["class"]
|
||||||
});
|
});
|
||||||
var authorized = currentclass.moderators.concat(currentclass.admin);
|
var authorized = currentclass.moderators.concat(currentclass.admin);
|
||||||
if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) {
|
if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) {
|
||||||
@ -305,8 +310,8 @@ 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]
|
||||||
@ -326,7 +331,8 @@ Meteor.methods({
|
|||||||
var currentclass = classes.findOne({
|
var currentclass = classes.findOne({
|
||||||
_id: workobject.class
|
_id: workobject.class
|
||||||
});
|
});
|
||||||
if (currentclass.subscribers.indexOf(Meteor.userId()) != -1 && ["confirmations", "reports", "done"].indexOf(input[1]) != -1) {
|
if (currentclass.subscribers.indexOf(Meteor.userId()) != -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());
|
||||||
@ -344,7 +350,7 @@ Meteor.methods({
|
|||||||
var currentclass = classes.findOne({
|
var currentclass = classes.findOne({
|
||||||
_id: work.findOne({
|
_id: work.findOne({
|
||||||
_id: workId
|
_id: workId
|
||||||
}).class
|
})["class"]
|
||||||
});
|
});
|
||||||
var authorized = currentclass.moderators.concat(currentclass.admin);
|
var authorized = currentclass.moderators.concat(currentclass.admin);
|
||||||
if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']) ||
|
if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']) ||
|
||||||
@ -368,10 +374,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);
|
||||||
@ -397,12 +403,12 @@ 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.concat(change);
|
current.classes = current.classes.concat(change);
|
||||||
Meteor.users.update({
|
Meteor.users.update({
|
||||||
_id: Meteor.userId()
|
_id: Meteor.userId()
|
||||||
}, {
|
}, {
|
||||||
@ -421,7 +427,7 @@ Meteor.methods({
|
|||||||
var found = classes.findOne(input);
|
var found = classes.findOne(input);
|
||||||
current = Meteor.user().profile;
|
current = Meteor.user().profile;
|
||||||
if (found !== undefined && input.code !== undefined &&
|
if (found !== undefined && input.code !== 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.concat(found._id);
|
current.concat(found._id);
|
||||||
Meteor.users.update({_id: Meteor.userId()}, {$set: {profile: current}});
|
Meteor.users.update({_id: Meteor.userId()}, {$set: {profile: current}});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user