server formatting
This commit is contained in:
parent
15f1ba4085
commit
8fe801020c
@ -81,7 +81,11 @@ Meteor.publish('users', function() {
|
||||
if (Roles.userIsInRole(this.userId, ['superadmin', 'admin'])) {
|
||||
return Meteor.users.find();
|
||||
} else {
|
||||
return Meteor.users.find({}, {fields: {'services.google.email': 1}});
|
||||
return Meteor.users.find({}, {
|
||||
fields: {
|
||||
'services.google.email': 1
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@ -160,34 +164,62 @@ Meteor.methods({
|
||||
}
|
||||
},
|
||||
'changeAdmin': function(input) {
|
||||
var found = Meteor.users.find({_id: input[0]});
|
||||
var foundclass = classes.find({_id: input[1]});
|
||||
var found = Meteor.users.find({
|
||||
_id: input[0]
|
||||
});
|
||||
var foundclass = classes.find({
|
||||
_id: input[1]
|
||||
});
|
||||
if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) {
|
||||
classes.update({_id: input[1]}, {$set: {admin: input[0]}});
|
||||
classes.update({
|
||||
_id: input[1]
|
||||
}, {
|
||||
$set: {
|
||||
admin: input[0]
|
||||
}
|
||||
});
|
||||
} else if (found && foundclass && foundclass.admin == Meteor.userId() &&
|
||||
foundclass.banned.indexOf(input[0]) === -1 &&
|
||||
foundclass.subscribers.indexOf(input[0]) !== -1) {
|
||||
classes.update({_id: input[1]}, {$set: {admin: input[0]}});
|
||||
classes.update({
|
||||
_id: input[1]
|
||||
}, {
|
||||
$set: {
|
||||
admin: input[0]
|
||||
}
|
||||
});
|
||||
} else {
|
||||
throw "Unauthorized";
|
||||
}
|
||||
},
|
||||
'trackUserInClass': function(input) {
|
||||
var foundclass = classes.findOne({_id: input[1]});
|
||||
var foundclass = classes.findOne({
|
||||
_id: input[1]
|
||||
});
|
||||
var userlist = input[2];
|
||||
var index = possiblelist.indexOf(input[2]);
|
||||
var set = {};
|
||||
set[userlist] = foundclass[userlist].concat(input[0]);
|
||||
if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) {
|
||||
classes.update({_id: input[1]}, {$set: set});
|
||||
classes.update({
|
||||
_id: input[1]
|
||||
}, {
|
||||
$set: set
|
||||
});
|
||||
} else if (foundclass && foundclass.admin == Meteor.userId() && index !== -1 &&
|
||||
(index === 1 || foundclass.moderators.indexOf(Meteor.userId()) !== -1) &&
|
||||
foundclass[userlist].indexOf(input[0]) === -1) {
|
||||
classes.update({_id: input[1]}, {$set: set});
|
||||
classes.update({
|
||||
_id: input[1]
|
||||
}, {
|
||||
$set: set
|
||||
});
|
||||
}
|
||||
},
|
||||
'untrackUserInClass': function(input) {
|
||||
var foundclass = classes.findOne({_id: input[1]});
|
||||
var foundclass = classes.findOne({
|
||||
_id: input[1]
|
||||
});
|
||||
var userlist = input[2];
|
||||
var index = possiblelist.indexOf(input[2]);
|
||||
var set = {};
|
||||
@ -195,11 +227,19 @@ Meteor.methods({
|
||||
set[userlist] = foundclass[userlist];
|
||||
|
||||
if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) {
|
||||
classes.update({_id: input[1]}, {$set: set});
|
||||
classes.update({
|
||||
_id: input[1]
|
||||
}, {
|
||||
$set: set
|
||||
});
|
||||
} else if (foundclass && foundclass.admin == Meteor.userId() && index !== -1 &&
|
||||
(index === 1 || foundclass.moderators.indexOf(Meteor.userId()) !== -1) &&
|
||||
foundclass[userlist].indexOf(input[0]) !== -1) {
|
||||
classes.update({_id: input[1]}, {$set: set});
|
||||
classes.update({
|
||||
_id: input[1]
|
||||
}, {
|
||||
$set: set
|
||||
});
|
||||
}
|
||||
},
|
||||
'deleteClass': function(classid) {
|
||||
@ -209,7 +249,9 @@ Meteor.methods({
|
||||
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++) {
|
||||
var current = Meteor.users.findOne({_id:found.subscribers[i]}).profile;
|
||||
var current = Meteor.users.findOne({
|
||||
_id: found.subscribers[i]
|
||||
}).profile;
|
||||
var index = current.classes.indexOf(classid);
|
||||
current.classes.splice(index, 1);
|
||||
Meteor.users.update({
|
||||
@ -331,8 +373,7 @@ Meteor.methods({
|
||||
var currentclass = classes.findOne({
|
||||
_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());
|
||||
if (userindex === -1) {
|
||||
workobject[input[1]] = workobject[input[1]].concat(Meteor.userId());
|
||||
@ -406,7 +447,13 @@ Meteor.methods({
|
||||
found !== null &&
|
||||
pass === found.code &&
|
||||
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;
|
||||
current.classes = current.classes.concat(change);
|
||||
Meteor.users.update({
|
||||
@ -422,13 +469,29 @@ Meteor.methods({
|
||||
}
|
||||
},
|
||||
'joinPrivateClass': function(input) {
|
||||
var found = classes.findOne({status: true, privacy: true, code:input});
|
||||
var found = classes.findOne({
|
||||
status: true,
|
||||
privacy: true,
|
||||
code: input
|
||||
});
|
||||
var current = Meteor.user().profile;
|
||||
if (found !== undefined && input !== undefined &&
|
||||
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.classes = current.classes.concat(found._id);
|
||||
Meteor.users.update({_id: Meteor.userId()}, {$set: {profile: current}});
|
||||
Meteor.users.update({
|
||||
_id: Meteor.userId()
|
||||
}, {
|
||||
$set: {
|
||||
profile: current
|
||||
}
|
||||
});
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@ -450,8 +513,16 @@ Meteor.methods({
|
||||
profile: current
|
||||
}
|
||||
});
|
||||
var newstudents = classes.findOne({_id: change}).subscribers.splice(Meteor.userId(), 1);
|
||||
classes.update({_id: change}, {$set: {subscribers: newstudents}});
|
||||
var newstudents = classes.findOne({
|
||||
_id: change
|
||||
}).subscribers.splice(Meteor.userId(), 1);
|
||||
classes.update({
|
||||
_id: change
|
||||
}, {
|
||||
$set: {
|
||||
subscribers: newstudents
|
||||
}
|
||||
});
|
||||
return 1;
|
||||
} else {
|
||||
throw "You are currently the admin of this class. Transfer ownership in order to leave this class.";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user