674 lines
20 KiB
JavaScript
Raw Normal View History

2016-08-25 22:35:44 -04:00
//meteor things
2016-08-12 12:13:26 -04:00
import {
Meteor
} from 'meteor/meteor';
import {
Mongo
} from 'meteor/mongo';
2016-08-01 19:30:32 +08:00
2016-08-25 22:35:44 -04:00
// Defines who the admins are - not added
2016-08-12 19:10:54 -04:00
superadmins = [
"ybq987@gmail.com",
"ksjdragon@gmail.com"
];
2016-08-25 22:35:44 -04:00
2016-08-18 17:13:59 -04:00
worktype = ["test", "quiz", "project", "normal", "other"];
2016-08-18 06:54:22 -04:00
var possiblelist = ["moderators", "banned"];
2016-08-12 21:52:14 -04:00
2016-08-23 21:35:10 -04:00
// Adds roles to superadmins
// Not necessary on every run
2016-08-25 22:35:44 -04:00
// Makes superadmins superadmins
2016-08-12 19:10:54 -04:00
for (var i = 0; i < superadmins.length; i++) {
var superadmin = superadmins[i];
2016-08-12 20:11:26 -04:00
if (Meteor.users.findOne({
2016-08-13 13:32:40 -04:00
"services.google.email": superadmin
})) {
2016-08-12 20:11:26 -04:00
var userId = Meteor.users.findOne({
"services.google.email": superadmin
})._id;
2016-08-12 19:10:54 -04:00
Roles.addUsersToRoles(userId, ['superadmin']);
}
}
2016-08-25 22:35:44 -04:00
//
2016-08-26 21:32:17 -04:00
2016-08-12 20:11:26 -04:00
Meteor.publish('schools', function() {
return schools.find();
});
2016-08-25 22:35:44 -04:00
// Returns the code for classes (for debug)
2016-08-12 20:11:26 -04:00
Meteor.publish('classes', function() {
2016-08-12 20:42:29 -04:00
if (Roles.userIsInRole(this.userId, ['superadmin', 'admin'])) {
2016-08-12 20:11:26 -04:00
return classes.find();
} else {
2016-08-23 21:35:10 -04:00
// Return user classes (if private) and public classes.
2016-08-24 21:09:34 -04:00
userclasses = Meteor.users.findOne(this.userId).profile.classes;
if (userclasses !== undefined) {
return classes.find({
$or: [{
privacy: false
}, {
_id: {
$in: Meteor.users.findOne(this.userId).profile.classes
}
}]
2016-08-12 20:11:26 -04:00
}, {
2016-08-24 21:09:34 -04:00
// Return non-sensitive fields
fields: {
school: 1,
name: 1,
hour: 1,
teacher: 1,
admin: 1,
status: 1,
privacy: 1,
category: 1,
moderators: 1,
banned: 1,
subscribers: 1
2016-08-12 20:11:26 -04:00
}
2016-08-24 21:09:34 -04:00
});
} else {
2016-08-24 21:15:16 -04:00
Meteor.call('createProfile', this.userId);
2016-08-24 21:09:34 -04:00
return classes.find({
_id: null
});
}
2016-08-12 20:11:26 -04:00
}
});
2016-08-25 22:35:44 -04:00
//Gives everything in work if superadmin
2016-08-12 20:11:26 -04:00
Meteor.publish('work', function() {
2016-08-12 20:42:29 -04:00
if (Roles.userIsInRole(this.userId, ['superadmin', 'admin'])) {
2016-08-12 20:11:26 -04:00
return work.find();
} else {
2016-08-24 21:15:16 -04:00
userclasses = Meteor.users.findOne(this.userId).profile.classes;
if (userclasses !== undefined) {
2016-08-26 21:32:17 -04:00
return work.find({
// Only return work of enrolled classes
class: {
$in: Meteor.users.findOne(this.userId).profile.classes
}
});
} else {
2016-08-24 21:15:16 -04:00
2016-08-26 21:32:17 -04:00
Meteor.call('createProfile', this.userId);
return classes.find({
_id: null
});
}
2016-08-24 21:15:16 -04:00
2016-08-12 20:11:26 -04:00
}
});
2016-08-25 22:35:44 -04:00
//Returns issues in sites (not implemented on client)
Meteor.publish('requests', function() {
if (Roles.userIsInRole(this.userId, ['superadmin', 'admin'])) {
return requests.find();
} else {
2016-08-24 21:09:34 -04:00
return requests.find({
requestor: this.userId
});
}
});
2016-08-25 22:35:44 -04:00
//Publishes every-persons email and user-ids
2016-08-15 20:55:21 -04:00
Meteor.publish('users', function() {
if (Roles.userIsInRole(this.userId, ['superadmin', 'admin'])) {
return Meteor.users.find();
} else {
2016-08-18 06:54:22 -04:00
return Meteor.users.find({}, {
2016-08-23 21:35:10 -04:00
// Only return necessary fields
2016-08-18 06:54:22 -04:00
fields: {
'services.google.email': 1
}
});
2016-08-15 20:55:21 -04:00
}
});
2016-08-23 21:35:10 -04:00
// Allows only superadmins to edit collections from client
Security.permit(['insert', 'update', 'remove']).collections([schools, classes, work]).ifHasRole('superadmin');
2016-08-23 21:35:10 -04:00
2016-08-08 20:55:02 -04:00
Meteor.methods({
2016-08-25 22:35:44 -04:00
//Stuff that is accessible in client
2016-08-26 21:32:17 -04:00
2016-08-25 22:35:44 -04:00
//Generates private codes for classes - like google classroom
2016-08-12 12:13:26 -04:00
'genCode': function() {
2016-08-18 19:08:58 -04:00
currcode = Math.random().toString(36).substr(2, 6);
while (classes.findOne({
code: currcode
}) !== undefined) {
2016-08-18 19:08:58 -04:00
currcode = Math.random().toString(36).substr(2, 6);
}
return currcode;
2016-08-12 12:13:26 -04:00
},
2016-08-23 21:35:10 -04:00
// School Functions
2016-08-25 22:35:44 -04:00
//Ability to create schools for selections
2016-08-12 12:13:26 -04:00
'createSchool': function(schoolname) {
2016-08-25 21:57:22 -04:00
if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) {
2016-08-12 12:13:26 -04:00
schools.insert({
2016-08-25 21:57:22 -04:00
name: schoolname
2016-08-12 12:13:26 -04:00
});
2016-08-21 10:02:07 -04:00
} else {
throw "Unauthorized";
2016-08-12 12:13:26 -04:00
}
},
2016-08-25 22:35:44 -04:00
//Deletes school
2016-08-12 19:10:54 -04:00
'deleteSchool': function(schoolId) {
if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) {
schools.remove({
_id: schoolId
});
2016-08-21 10:02:07 -04:00
} else {
throw "Unauthorized";
2016-08-12 19:10:54 -04:00
}
2016-08-12 12:13:26 -04:00
},
2016-08-23 21:35:10 -04:00
// Class Functions
2016-08-12 12:13:26 -04:00
'createClass': function(input) {
classes.schema.validate(input);
if (Meteor.user() !== null &&
classes.find({
status: false,
admin: Meteor.userId()
}).fetch().length < 5 &&
schools.findOne({
name: input.school
}) !== null) {
2016-08-12 19:10:54 -04:00
if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) {
input.status = true;
} else {
input.status = false;
}
2016-08-17 22:32:33 -04:00
input.subscribers = [];
2016-08-12 12:13:26 -04:00
input.admin = Meteor.userId();
if (input.privacy) {
Meteor.call('genCode', function(error, result) {
input.code = result;
});
} else {
input.code = "";
}
if (input.category != "class" && input.category != "club") {
input.category = "other";
}
input.moderators = [];
input.banned = [];
2016-08-17 22:32:33 -04:00
classes.insert(input, function(err, result) {
Meteor.call('joinClass', [result, input.code]);
});
2016-08-18 06:54:22 -04:00
2016-08-12 12:13:26 -04:00
return 1;
} else {
2016-08-15 22:32:00 -04:00
throw "Unauthorized";
}
},
2016-08-27 09:34:23 -04:00
// For class admins to get code
'getCode': function(classId) {
var foundclass = classes.find({_id: classId});
if (foundclass && foundclass.admin == Meteor.userId()) {
return foundclass.code;
} else {
throw "Unauthorized";
}
},
2016-08-15 22:32:00 -04:00
'changeAdmin': function(input) {
2016-08-18 06:54:22 -04:00
var found = Meteor.users.find({
_id: input[0]
});
var foundclass = classes.find({
_id: input[1]
});
2016-08-15 22:32:00 -04:00
if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) {
2016-08-18 06:54:22 -04:00
classes.update({
_id: input[1]
}, {
$set: {
admin: input[0]
}
});
2016-08-15 22:32:00 -04:00
} else if (found && foundclass && foundclass.admin == Meteor.userId() &&
2016-08-18 06:54:22 -04:00
foundclass.banned.indexOf(input[0]) === -1 &&
foundclass.subscribers.indexOf(input[0]) !== -1) {
classes.update({
_id: input[1]
}, {
$set: {
admin: input[0]
}
});
2016-08-15 22:32:00 -04:00
} else {
throw "Unauthorized";
}
},
2016-08-25 22:35:44 -04:00
// Allows someone to manage the class
2016-08-15 22:32:00 -04:00
'trackUserInClass': function(input) {
2016-08-18 06:54:22 -04:00
var foundclass = classes.findOne({
_id: input[1]
});
2016-08-15 22:32:00 -04:00
var userlist = input[2];
var index = possiblelist.indexOf(input[2]);
2016-08-16 18:14:07 -04:00
var set = {};
set[userlist] = foundclass[userlist].concat(input[0]);
2016-08-15 22:32:00 -04:00
if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) {
2016-08-18 06:54:22 -04:00
classes.update({
_id: input[1]
}, {
$set: set
});
2016-08-15 22:32:00 -04:00
} else if (foundclass && foundclass.admin == Meteor.userId() && index !== -1 &&
2016-08-18 06:54:22 -04:00
(index === 1 || foundclass.moderators.indexOf(Meteor.userId()) !== -1) &&
foundclass[userlist].indexOf(input[0]) === -1) {
classes.update({
_id: input[1]
}, {
$set: set
});
2016-08-21 10:02:07 -04:00
} else {
throw "Unauthorized";
2016-08-15 22:32:00 -04:00
}
},
'untrackUserInClass': function(input) {
2016-08-18 06:54:22 -04:00
var foundclass = classes.findOne({
_id: input[1]
});
2016-08-15 22:32:00 -04:00
var userlist = input[2];
var index = possiblelist.indexOf(input[2]);
2016-08-16 17:53:27 -04:00
var set = {};
2016-08-16 18:22:02 -04:00
foundclass[userlist].splice(foundclass[userlist].indexOf(input[0]), 1);
set[userlist] = foundclass[userlist];
2016-08-15 22:32:00 -04:00
if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) {
2016-08-18 06:54:22 -04:00
classes.update({
_id: input[1]
}, {
$set: set
});
2016-08-15 22:32:00 -04:00
} else if (foundclass && foundclass.admin == Meteor.userId() && index !== -1 &&
2016-08-18 06:54:22 -04:00
(index === 1 || foundclass.moderators.indexOf(Meteor.userId()) !== -1) &&
foundclass[userlist].indexOf(input[0]) !== -1) {
classes.update({
_id: input[1]
}, {
$set: set
});
2016-08-21 10:02:07 -04:00
} else {
throw "Unauthorized";
2016-08-12 12:13:26 -04:00
}
},
'deleteClass': function(classid) {
2016-08-12 21:52:14 -04:00
var found = classes.findOne({
2016-08-12 12:13:26 -04:00
_id: classid
});
2016-08-18 06:54:22 -04:00
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++) {
2016-08-18 06:54:22 -04:00
var current = Meteor.users.findOne({
_id: found.subscribers[i]
}).profile;
2016-08-17 22:32:33 -04:00
var index = current.classes.indexOf(classid);
current.classes.splice(index, 1);
Meteor.users.update({
_id: found.subscribers[i]
}, {
$set: {
profile: current
}
});
2016-08-15 22:32:00 -04:00
}
2016-08-12 12:13:26 -04:00
classes.remove({
_id: classid
});
2016-08-21 10:02:07 -04:00
} else {
throw "Unauthorized";
2016-08-12 12:13:26 -04:00
}
},
2016-08-23 21:35:10 -04:00
// Work Functions
2016-08-12 12:13:26 -04:00
'createWork': function(input) {
2016-08-18 17:13:59 -04:00
var ref = new Date();
ref.setHours(0, 0, 0, 0);
2016-08-18 17:13:59 -04:00
ref = ref.getTime();
2016-08-12 21:52:14 -04:00
input.creator = Meteor.userId();
2016-08-12 12:13:26 -04:00
work.schema.validate(input);
2016-08-13 17:26:07 -04:00
var found = classes.findOne({
2016-08-12 12:13:26 -04:00
_id: input.class
2016-08-09 17:10:08 -04:00
});
2016-08-12 12:13:26 -04:00
if (Meteor.user() !== null &&
2016-08-18 06:54:22 -04:00
found !== null &&
Meteor.user().profile.classes.indexOf(input.class) !== -1 &&
found.banned.indexOf(Meteor.userId()) === -1 &&
input.dueDate instanceof Date && input.dueDate.getTime() >= ref &&
worktype.indexOf(input.type) != -1 &&
input.name.length <= 50 && input.description.length <= 150) {
2016-08-12 12:13:26 -04:00
input.confirmations = [Meteor.userId()];
input.reports = [];
input.done = [];
input.numberdone = 0;
2016-08-12 21:00:32 -04:00
input.comments = [];
2016-08-12 12:13:26 -04:00
work.insert(input);
2016-08-21 10:02:07 -04:00
} else {
throw "Unauthorized";
2016-08-12 12:13:26 -04:00
}
2016-08-10 17:42:07 -04:00
2016-08-12 12:13:26 -04:00
},
2016-08-12 21:52:14 -04:00
'editWork': function(change) {
2016-08-18 17:13:59 -04:00
var ref = new Date();
ref.setHours(0, 0, 0, 0);
2016-08-18 17:13:59 -04:00
ref = ref.getTime();
2016-08-13 13:32:40 -04:00
var currentclass = classes.findOne({
_id: work.findOne({
_id: change._id
2016-08-17 22:32:33 -04:00
})["class"]
2016-08-13 13:32:40 -04:00
});
2016-08-16 18:14:07 -04:00
var authorized = currentclass.moderators.concat(currentclass.admin);
2016-08-12 22:05:06 -04:00
if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) {
work.update({
2016-08-13 13:32:40 -04:00
_id: change._id
}, {
$set: change
});
2016-08-12 21:52:14 -04:00
} else if (authorized.indexOf(Meteor.userId()) != -1) {
if (change.name.length <= 50 && change.description.length <= 150 && worktype.indexOf(change.type) != -1) {
2016-08-18 19:32:39 -04:00
work.update({
2016-08-13 13:32:40 -04:00
_id: change._id
}, {
$set: {
name: change.name,
dueDate: change.dueDate,
2016-08-13 17:26:07 -04:00
description: change.description,
2016-08-13 13:32:40 -04:00
comments: change.comments,
attachments: change.attachments,
2016-08-15 22:32:00 -04:00
type: change.type
2016-08-13 13:32:40 -04:00
}
});
2016-08-12 21:52:14 -04:00
}
2016-08-13 13:32:40 -04:00
} else if (Meteor.userId() === work.findOne({
_id: change._id
}).creator) {
2016-08-15 13:58:46 -04:00
if (change.name.length <= 50 && worktype.indexOf(change.type) != -1 &&
2016-08-18 19:32:39 -04:00
change.dueDate instanceof Date && change.dueDate.getTime() >= ref) {
work.update({
2016-08-13 13:32:40 -04:00
_id: change._id
}, {
$set: {
name: change.name,
dueDate: change.dueDate,
2016-08-13 17:26:07 -04:00
description: change.description,
2016-08-13 13:32:40 -04:00
attachments: change.attachments,
type: change.type
}
});
2016-08-12 21:52:14 -04:00
}
} else {
2016-08-21 10:02:07 -04:00
throw "Unauthorized";
2016-08-12 21:52:14 -04:00
}
},
'addComment': function(input) {
2016-08-22 16:52:04 -04:00
var comment = input[0];
2016-08-13 13:32:40 -04:00
var workobject = work.findOne({
_id: input[1]
});
var currentclass = classes.findOne({
_id: workobject.class
});
2016-08-13 16:10:01 -04:00
var user = Meteor.userId();
2016-08-22 16:52:04 -04:00
foundsubs = currentclass.subscribers;
2016-08-12 21:52:14 -04:00
if (typeof comment === "string" && comment.length <= 200 &&
2016-08-22 16:52:04 -04:00
foundsubs.indexOf(Meteor.userId()) != -1 &&
2016-08-18 06:54:22 -04:00
currentclass.banned.indexOf(Meteor.userId()) === -1) {
2016-08-16 18:14:07 -04:00
var comments = workobject.comments.concat(comment);
2016-08-13 13:32:40 -04:00
work.update({
_id: input[1]
}, {
$set: {
2016-08-13 16:12:25 -04:00
comments: comments,
2016-08-18 06:54:22 -04:00
user: user,
2016-08-13 16:18:04 -04:00
time: new Date()
2016-08-13 13:32:40 -04:00
}
});
2016-08-21 10:02:07 -04:00
} else {
throw "Unauthorized";
2016-08-12 21:52:14 -04:00
}
},
2016-08-26 21:32:17 -04:00
2016-08-12 22:35:28 -04:00
'toggleWork': function(input) {
2016-08-13 13:32:40 -04:00
var workobject = work.findOne({
_id: input[0]
});
var currentclass = classes.findOne({
_id: workobject.class
});
2016-08-18 06:54:22 -04:00
if (currentclass.subscribers.indexOf(Meteor.userId()) != -1 && ["confirmations", "reports", "done"].indexOf(input[1]) != -1) {
userindex = workobject[input[1]].indexOf(Meteor.userId());
if (userindex === -1) {
2016-08-16 18:14:07 -04:00
workobject[input[1]] = workobject[input[1]].concat(Meteor.userId());
2016-08-12 22:35:28 -04:00
} else {
workobject[input[1]] = workobject[input[1]].splice(userindex, 1);
}
2016-08-13 13:32:40 -04:00
work.update({
_id: input[1]
}, {
$set: workobject
});
2016-08-21 10:02:07 -04:00
} else {
throw "Unauthorized";
2016-08-12 21:52:14 -04:00
}
},
2016-08-12 21:00:32 -04:00
'deleteWork': function(workId) {
2016-08-13 13:32:40 -04:00
var currentclass = classes.findOne({
_id: work.findOne({
_id: workId
2016-08-17 22:32:33 -04:00
})["class"]
2016-08-13 13:32:40 -04:00
});
2016-08-16 18:14:07 -04:00
var authorized = currentclass.moderators.concat(currentclass.admin);
2016-08-12 21:52:14 -04:00
if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']) ||
authorized.indexOf(Meteor.userId()) != -1) {
work.remove({
_id: workId
});
2016-08-21 10:02:07 -04:00
} else {
throw "Unauthorized";
2016-08-12 21:00:32 -04:00
}
2016-08-12 12:13:26 -04:00
},
2016-08-23 21:35:10 -04:00
// User Functions
2016-08-12 12:13:26 -04:00
'editProfile': function(change) {
2016-08-12 21:52:14 -04:00
var current = Meteor.user().profile;
2016-08-12 12:13:26 -04:00
current.school = change.school;
current.grade = change.grade;
current.classes = change.classes;
if (!current.classes) {
current.classes = [];
}
2016-08-12 12:13:26 -04:00
current.description = change.description;
current.avatar = change.avatar;
current.banner = change.banner;
current.preferences = change.preferences;
if (schools.findOne({
2016-08-18 06:54:22 -04:00
name: current.school
}) !== null &&
Number.isInteger(current.grade) &&
current.grade >= 9 && current.grade <= 12) {
2016-08-12 19:10:54 -04:00
2016-08-12 18:27:03 -04:00
if (current.description && current.description.length > 50) {
2016-08-12 20:11:26 -04:00
current.description = current.description.slice(0, 50);
2016-08-12 18:27:03 -04:00
}
2016-08-12 12:13:26 -04:00
Meteor.users.update({
_id: Meteor.userId()
}, {
$set: {
profile: current
}
});
2016-08-21 10:02:07 -04:00
return true;
2016-08-12 12:13:26 -04:00
} else {
2016-08-21 10:02:07 -04:00
throw "Unauthorized";
2016-08-12 12:13:26 -04:00
}
},
2016-08-24 21:09:34 -04:00
'createProfile': function(userId) {
current = Meteor.users.findOne({
_id: userId
}).profile;
current.classes = [];
Meteor.users.update({
_id: userId
}, {
$set: {
profile: current
}
});
},
2016-08-12 12:13:26 -04:00
'joinClass': function(input) {
2016-08-12 21:52:14 -04:00
var change = input[0];
var pass = input[1];
var prof = Meteor.user().profile;
var found = classes.findOne({
2016-08-12 12:13:26 -04:00
_id: change,
status: true
});
if (Meteor.user() !== null &&
2016-08-18 06:54:22 -04:00
found !== null &&
pass === found.code &&
prof.classes.indexOf(change) === -1) {
2016-08-20 20:56:05 -04:00
foundsubs = found.subscribers + '';
2016-08-18 06:54:22 -04:00
classes.update({
_id: found._id
}, {
$set: {
2016-08-20 20:56:05 -04:00
subscribers: foundsubs.concat(Meteor.userId())
2016-08-18 06:54:22 -04:00
}
});
2016-08-12 21:52:14 -04:00
var current = Meteor.user().profile;
2016-08-17 22:32:33 -04:00
current.classes = current.classes.concat(change);
2016-08-12 12:13:26 -04:00
Meteor.users.update({
_id: Meteor.userId()
}, {
$set: {
profile: current
}
});
2016-08-21 10:02:07 -04:00
return true;
2016-08-09 18:23:02 -04:00
} else {
2016-08-21 10:02:07 -04:00
throw "Unauthorized";
2016-08-09 18:23:02 -04:00
}
2016-08-12 12:13:26 -04:00
},
2016-08-17 18:45:50 -04:00
'joinPrivateClass': function(input) {
2016-08-18 06:54:22 -04:00
var found = classes.findOne({
status: true,
privacy: true,
code: input
});
var current = Meteor.user().profile;
if (found !== undefined && input !== undefined &&
2016-08-18 06:54:22 -04:00
current.classes.indexOf(found._id) === -1) {
classes.update({
_id: found._id
}, {
$set: {
subscribers: found.subscribers.concat(Meteor.userId())
}
});
current.classes = current.classes.concat(found._id);
2016-08-18 06:54:22 -04:00
Meteor.users.update({
_id: Meteor.userId()
}, {
$set: {
profile: current
}
});
return true;
} else {
2016-08-21 10:02:07 -04:00
throw "Unauthorized";
2016-08-17 18:45:50 -04:00
}
},
2016-08-12 12:13:26 -04:00
'leaveClass': function(change) {
if (Meteor.user() !== null) {
2016-08-21 22:48:15 -04:00
var current = Meteor.user().profile;
var index = current.classes.indexOf(change);
2016-08-12 12:13:26 -04:00
if (index >= 0) {
if (classes.findOne({
2016-08-13 13:32:40 -04:00
_id: change
}).admin != Meteor.userId()) {
2016-08-21 22:48:15 -04:00
current.classes.splice(index, 1);
2016-08-12 12:13:26 -04:00
Meteor.users.update({
_id: Meteor.userId()
}, {
$set: {
profile: current
}
});
2016-08-18 06:54:22 -04:00
var newstudents = classes.findOne({
_id: change
}).subscribers.splice(Meteor.userId(), 1);
classes.update({
_id: change
}, {
$set: {
subscribers: newstudents
}
});
2016-08-21 10:02:07 -04:00
return true;
2016-08-12 12:13:26 -04:00
} else {
throw "You are currently the admin of this class. Transfer ownership in order to leave this class.";
}
}
2016-08-09 18:03:31 -04:00
} else {
throw "Unauthorized";
2016-08-12 12:13:26 -04:00
}
2016-08-12 19:10:54 -04:00
},
2016-08-23 21:35:10 -04:00
// Admin Functions
2016-08-12 19:10:54 -04:00
'createAdmin': function(userId) {
if (Roles.userIsInRole(Meteor.user()._id, ['superadmin'])) {
Roles.addUsersToRoles(userId, ['admin']);
2016-08-21 10:02:07 -04:00
} else {
throw "Unauthorized";
2016-08-12 19:10:54 -04:00
}
},
'deleteAdmin': function(userId) {
if (Roles.userIsInRole(Meteor.user()._id, ['superadmin'])) {
Roles.removeUsersToRoles(userId, ['admin']);
2016-08-21 10:02:07 -04:00
} else {
throw "Unauthorized";
2016-08-12 19:10:54 -04:00
}
},
'createRequest': function(request) {
if (request.length <= 500 && Meteor.userId() !== null) {
requests.insert({
requestor: Meteor.userId(),
request: request,
timeRequested: new Date()
});
2016-08-21 10:02:07 -04:00
} else {
throw "Unauthorized";
}
},
'deleteRequest': function(requestId) {
if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) {
2016-08-24 21:09:34 -04:00
requests.remove({
_id: requestId
});
2016-08-21 10:02:07 -04:00
} else {
throw "Unauthorized";
}
2016-08-09 18:03:31 -04:00
}
});