Added user in each comment

This commit is contained in:
Kenneth Jao 2016-08-13 16:12:25 -04:00
commit 72913d728a
4 changed files with 84 additions and 30 deletions

View File

@ -17,7 +17,6 @@ standard-minifier-js@1.1.8 # JS minifier run for production mode
es5-shim@4.6.13 # ECMAScript 5 compatibility for older browsers. es5-shim@4.6.13 # ECMAScript 5 compatibility for older browsers.
ecmascript@0.5.7 # Enable ECMAScript2015+ syntax in app code ecmascript@0.5.7 # Enable ECMAScript2015+ syntax in app code
insecure@1.0.7 # Allow all DB writes from clients (for prototyping)
fortawesome:fontawesome fortawesome:fontawesome
session session
proyk:meteor-cookies proyk:meteor-cookies

View File

@ -41,7 +41,6 @@ html-tools@1.0.10
htmljs@1.0.10 htmljs@1.0.10
http@1.1.8 http@1.1.8
id-map@1.0.8 id-map@1.0.8
insecure@1.0.7
iron:controller@1.0.12 iron:controller@1.0.12
iron:core@1.0.11 iron:core@1.0.11
iron:dynamic-template@1.0.12 iron:dynamic-template@1.0.12

View File

@ -95,7 +95,7 @@ Template.profile.helpers({
avatar() { avatar() {
var dim = window.innerWidth * 1600 / 1920 * 0.16; var dim = window.innerWidth * 1600 / 1920 * 0.16;
if (Meteor.user().profile.avatar) { if (Meteor.user().profile.avatar) {
var pic = Meteor.user().profile.avatar; var pic = Meteor.user().profile.avatar + ".png";
} else { } else {
var pic = "Avatars/" + (Math.floor(Math.random() * (11 - 1)) + 1).toString(); + ".png"; var pic = "Avatars/" + (Math.floor(Math.random() * (11 - 1)) + 1).toString(); + ".png";
currentprofile = Meteor.user().profile; currentprofile = Meteor.user().profile;

View File

@ -20,8 +20,8 @@ worktype = ["test", "quiz", "project", "normal"];
for (var i = 0; i < superadmins.length; i++) { for (var i = 0; i < superadmins.length; i++) {
var superadmin = superadmins[i]; var superadmin = superadmins[i];
if (Meteor.users.findOne({ if (Meteor.users.findOne({
"services.google.email": superadmin "services.google.email": superadmin
})) { })) {
var userId = Meteor.users.findOne({ var userId = Meteor.users.findOne({
"services.google.email": superadmin "services.google.email": superadmin
})._id; })._id;
@ -42,7 +42,7 @@ Meteor.publish('classes', function() {
privacy: false privacy: false
}, { }, {
_id: { _id: {
$in: this.user().profile.classes $in: Meteor.users.findOne(this.userId).profile.classes
} }
}] }]
}, { }, {
@ -70,13 +70,15 @@ Meteor.publish('work', function() {
} else { } else {
return work.find({ return work.find({
class: { class: {
$in: this.user().profile.classes $in: Meteor.users.findOne(this.userId).profile.classes
} }
}); });
} }
}); });
Security.permit(['insert', 'update', 'remove']).collections([schools, classes, work]).ifHasRole('superadmin');
Meteor.methods({ Meteor.methods({
'genCode': function() { 'genCode': function() {
return 'xxxxxx'.replace(/[x]/g, _uuid4); return 'xxxxxx'.replace(/[x]/g, _uuid4);
@ -189,50 +191,100 @@ Meteor.methods({
var month = ref.getMonth + 1; var month = ref.getMonth + 1;
ref = new Date(ref.getFullYear() + "-" + month.toString() + "-" + ref.getDate()).getTime(); ref = new Date(ref.getFullYear() + "-" + month.toString() + "-" + ref.getDate()).getTime();
var currentclass = classes.findOne({_id: work.findOne({_id: workId}).class}); var currentclass = classes.findOne({
_id: work.findOne({
_id: workId
}).class
});
var authorized = currentclass.moderators.push(currentclass.admin); var authorized = currentclass.moderators.push(currentclass.admin);
if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) { if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) {
Meteor.update({_id: change._id}, {$set: change}); Meteor.update({
_id: change._id
}, {
$set: change
});
} else if (authorized.indexOf(Meteor.userId()) != -1) { } else if (authorized.indexOf(Meteor.userId()) != -1) {
if (change.name.length <= 50 && worktype.indexOf(type) != -1) { if (change.name.length <= 50 && worktype.indexOf(type) != -1) {
Meteor.update({_id: change._id}, {$set: {name: change.name, dueDate: change.dueDate, comments: change.comments, attachments: change.attachments, type: change.type}}); Meteor.update({
_id: change._id
}, {
$set: {
name: change.name,
dueDate: change.dueDate,
comments: change.comments,
attachments: change.attachments,
type: change.type
}
});
} }
} else if (Meteor.userId() === work.findOne({_id: change._id}).creator) { } else if (Meteor.userId() === work.findOne({
_id: change._id
}).creator) {
if (change.name.length <= 50 && worktype.indexOf(type) != -1 && input.dueDate.getTime() >= ref) { if (change.name.length <= 50 && worktype.indexOf(type) != -1 && input.dueDate.getTime() >= ref) {
Meteor.update({_id: change._id}, {$set: {name: change.name, dueDate: change.dueDate, attachments: change.attachments, type: change.type}}); Meteor.update({
_id: change._id
}, {
$set: {
name: change.name,
dueDate: change.dueDate,
attachments: change.attachments,
type: change.type
}
});
} }
} else { } else {
throw "Unauthorized." throw "Unauthorized.";
} }
}, },
'addComment': function(input) { 'addComment': function(input) {
var comment = input[0]; var workobject = work.findOne({
var workobject = work.findOne({_id: input[1]}); _id: input[1]
});
var currentclass = classes.findOne({
_id: workobject.class
});
var user = Meteor.userId(); var user = Meteor.userId();
var currentclass = classes.findOne({_id: workobject.class});
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.blockEdit.indexOf(Meteor.userId()) === -1) { currentclass.blockEdit.indexOf(Meteor.userId()) === -1) {
var comments = workobject.comments.push({comment:comment,user:user}); var comments = workobject.comments.push(comment);
work.update({_id: input[1]}, {$set: {comments: comments}}); work.update({
_id: input[1]
}, {
$set: {
comments: comments,
user:user
}
});
} }
}, },
'toggleWork': function(input) { 'toggleWork': function(input) {
var workobject = work.findOne({_id: input[0]}); var workobject = work.findOne({
var currentclass = classes.findOne({_id: workobject.class}); _id: input[0]
if (currentclass.subscribers.indexOf(Meteor.userId()) != -1 && });
["confirmations", "reports", "done"].indexOf(input[1]) != -1) { var currentclass = classes.findOne({
userindex = workobject[input[1]].indexOf(Meteor.userId()) _id: workobject.class
});
if (currentclass.subscribers.indexOf(Meteor.userId()) != -1 && ["confirmations", "reports", "done"].indexOf(input[1]) != -1) {
userindex = workobject[input[1]].indexOf(Meteor.userId());
if (userindex === -1) { if (userindex === -1) {
workobject[input[1]] = workobject[input[1]].push(Meteor.userId()); workobject[input[1]] = workobject[input[1]].push(Meteor.userId());
} else { } else {
workobject[input[1]] = workobject[input[1]].splice(userindex, 1); workobject[input[1]] = workobject[input[1]].splice(userindex, 1);
} }
work.update({_id: input[1]}, {$set: workobject}); work.update({
_id: input[1]
}, {
$set: workobject
});
} }
}, },
'deleteWork': function(workId) { 'deleteWork': function(workId) {
var currentclass = classes.findOne({_id: work.findOne({_id: workId}).class}); var currentclass = classes.findOne({
_id: work.findOne({
_id: workId
}).class
});
var authorized = currentclass.moderators.push(currentclass.admin); var authorized = currentclass.moderators.push(currentclass.admin);
if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']) || if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']) ||
authorized.indexOf(Meteor.userId()) != -1) { authorized.indexOf(Meteor.userId()) != -1) {
@ -246,13 +298,17 @@ Meteor.methods({
var current = Meteor.user().profile; var current = Meteor.user().profile;
current.school = change.school; current.school = change.school;
current.grade = change.grade; current.grade = change.grade;
current.classes = change.classes;
if (!current.classes) {
current.classes = [];
}
current.description = change.description; current.description = change.description;
current.avatar = change.avatar; current.avatar = change.avatar;
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) {
@ -305,8 +361,8 @@ Meteor.methods({
var index = profile.classes.indexOf(change); var index = profile.classes.indexOf(change);
if (index >= 0) { if (index >= 0) {
if (classes.findOne({ if (classes.findOne({
_id: change _id: change
}).admin != Meteor.userId()) { }).admin != Meteor.userId()) {
profile.classes.splice(index, 1); profile.classes.splice(index, 1);
Meteor.users.update({ Meteor.users.update({
_id: Meteor.userId() _id: Meteor.userId()