personal edit and delete work

This commit is contained in:
Yaman Qalieh 2016-09-03 21:34:06 -04:00
parent 09dd53fb6f
commit b94003fcaf

View File

@ -67,7 +67,9 @@ Meteor.publish('classes', function() {
}); });
} else { } else {
Meteor.call('createProfile', this.userId); Meteor.call('createProfile', this.userId);
return classes.find({_id: null}); return classes.find({
_id: null
});
} }
} }
}); });
@ -88,7 +90,9 @@ Meteor.publish('work', function() {
}); });
} else { } else {
Meteor.call('createProfile', this.userId); Meteor.call('createProfile', this.userId);
return classes.find({_id: null}); return classes.find({
_id: null
});
} }
} }
@ -312,8 +316,8 @@ Meteor.methods({
if (Meteor.user() && if (Meteor.user() &&
((found && _.contains(Meteor.user().profile.classes, input.class) && ((found && _.contains(Meteor.user().profile.classes, input.class) &&
!_.contains(found.banned, Meteor.userId())) || !_.contains(found.banned, Meteor.userId())) ||
(Meteor.userId() === input.class)) && (Meteor.userId() === input.class)) &&
input.dueDate instanceof Date && input.dueDate.getTime() >= ref && input.dueDate instanceof Date && input.dueDate.getTime() >= ref &&
_.contains(worktype, input.type) && _.contains(worktype, input.type) &&
input.name.length <= 50 && input.description.length <= 150) { input.name.length <= 50 && input.description.length <= 150) {
@ -333,38 +337,23 @@ Meteor.methods({
var ref = new Date(); var ref = new Date();
ref.setHours(0, 0, 0, 0); ref.setHours(0, 0, 0, 0);
ref = ref.getTime(); ref = ref.getTime();
var currentwork = change._id;
var currentclass = classes.findOne({ var currentclass = classes.findOne({
_id: work.findOne({ _id: currentwork.class
_id: change._id
})["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'])) {
work.update({ work.update({
_id: change._id _id: currentwork._id
}, { }, {
$set: change $set: change
}); });
} else if (_.contains(authorized, Meteor.userId())) { } else if ((_.contains(authorized, Meteor.userId()) ||
if (change.name.length <= 50 && change.description.length <= 150 && _.contains(worktype, change.type)) { currentwork.class === Meteor.userId() ||
work.update({ Meteor.userId() === currentwork.creator) &&
_id: change._id change.name.length <= 50 && change.description.length <= 150 &&
}, { change.dueDate instanceof Date && change.dueDate.getTime() >= ref &&
$set: { _.contains(worktype, change.type)){
name: change.name,
dueDate: change.dueDate,
description: change.description,
comments: change.comments,
attachments: change.attachments,
type: change.type
}
});
}
} else if (Meteor.userId() === work.findOne({
_id: change._id
}).creator) {
if (change.name.length <= 50 && _.contains(worktype, change.type) &&
change.dueDate instanceof Date && change.dueDate.getTime() >= ref) {
work.update({ work.update({
_id: change._id _id: change._id
}, { }, {
@ -376,7 +365,6 @@ Meteor.methods({
type: change.type type: change.type
} }
}); });
}
} else { } else {
throw new Meteor.Error("unauthorized", "You are not authorized to complete this action."); throw new Meteor.Error("unauthorized", "You are not authorized to complete this action.");
} }
@ -442,15 +430,13 @@ Meteor.methods({
} }
}, },
'deleteWork': function(workId) { 'deleteWork': function(workId) {
var currentwork = wokr.findOne({_id: workId});
var currentclass = classes.findOne({ var currentclass = classes.findOne({
_id: work.findOne({ _id: currentwork.class
_id: workId
})["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']) ||
_.contains(authorized, Meteor.userId())) { _.contains(authorized, Meteor.userId()) || Meteor.userId() === currentwork.class) {
work.remove({ work.remove({
_id: workId _id: workId
}); });