implemented alanning:roles
This commit is contained in:
parent
63652db9ac
commit
d3080dbb9a
@ -10,13 +10,25 @@ _uuid4 = function(cc) {
|
|||||||
return (cc === 'x' ? rr : (rr & 0x3 | 0x8)).toString(16);
|
return (cc === 'x' ? rr : (rr & 0x3 | 0x8)).toString(16);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
superadmins = [
|
||||||
|
"ybq987@gmail.com",
|
||||||
|
"ksjdragon@gmail.com"
|
||||||
|
];
|
||||||
|
|
||||||
|
for (var i = 0; i < superadmins.length; i++) {
|
||||||
|
var superadmin = superadmins[i];
|
||||||
|
if (Meteor.users.findOne({"services.google.email": superadmin})) {
|
||||||
|
var userId = Meteor.users.findOne({"services.google.email": superadmin})._id;
|
||||||
|
Roles.addUsersToRoles(userId, ['superadmin']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
worktype = ["test", "quiz", "project", "normal"];
|
worktype = ["test", "quiz", "project", "normal"];
|
||||||
Meteor.methods({
|
Meteor.methods({
|
||||||
'genCode': function() {
|
'genCode': function() {
|
||||||
return 'xxxxxx'.replace(/[x]/g, _uuid4);
|
return 'xxxxxx'.replace(/[x]/g, _uuid4);
|
||||||
},
|
},
|
||||||
'createSchool': function(schoolname) {
|
'createSchool': function(schoolname) {
|
||||||
// if superadmin, no need for approval
|
|
||||||
if (Meteor.user() !== null &&
|
if (Meteor.user() !== null &&
|
||||||
schools.findOne({
|
schools.findOne({
|
||||||
name: input.school
|
name: input.school
|
||||||
@ -26,21 +38,26 @@ Meteor.methods({
|
|||||||
creator: Meteor.userId()
|
creator: Meteor.userId()
|
||||||
}) !== null) {
|
}) !== null) {
|
||||||
|
|
||||||
|
if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) {
|
||||||
|
stat = true;
|
||||||
|
} else {
|
||||||
|
stat = false;
|
||||||
|
}
|
||||||
schools.insert({
|
schools.insert({
|
||||||
name: schoolname,
|
name: schoolname,
|
||||||
status: false,
|
status: stat,
|
||||||
creator: Meteor.userId()
|
creator: Meteor.userId()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'deleteSchool': function(schoolid) {
|
'deleteSchool': function(schoolId) {
|
||||||
// alanning:roles implementation here
|
if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) {
|
||||||
schools.remove({
|
schools.remove({
|
||||||
_id: schoolid
|
_id: schoolId
|
||||||
});
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
'createClass': function(input) {
|
'createClass': function(input) {
|
||||||
// if superadmin, no need for approval
|
|
||||||
classes.schema.validate(input);
|
classes.schema.validate(input);
|
||||||
if (Meteor.user() !== null &&
|
if (Meteor.user() !== null &&
|
||||||
classes.find({
|
classes.find({
|
||||||
@ -50,8 +67,11 @@ Meteor.methods({
|
|||||||
schools.findOne({
|
schools.findOne({
|
||||||
name: input.school
|
name: input.school
|
||||||
}) !== null) {
|
}) !== null) {
|
||||||
|
if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) {
|
||||||
|
input.status = true;
|
||||||
|
} else {
|
||||||
input.status = false;
|
input.status = false;
|
||||||
|
}
|
||||||
input.subscribers = 0;
|
input.subscribers = 0;
|
||||||
input.admin = Meteor.userId();
|
input.admin = Meteor.userId();
|
||||||
if (input.privacy) {
|
if (input.privacy) {
|
||||||
@ -78,8 +98,7 @@ Meteor.methods({
|
|||||||
found = classes.findOne({
|
found = classes.findOne({
|
||||||
_id: classid
|
_id: classid
|
||||||
});
|
});
|
||||||
// Add roles
|
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) {
|
|
||||||
classes.remove({
|
classes.remove({
|
||||||
_id: classid
|
_id: classid
|
||||||
});
|
});
|
||||||
@ -197,6 +216,16 @@ Meteor.methods({
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
'createAdmin': function(userId) {
|
||||||
|
if (Roles.userIsInRole(Meteor.user()._id, ['superadmin'])) {
|
||||||
|
Roles.addUsersToRoles(userId, ['admin']);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'deleteAdmin': function(userId) {
|
||||||
|
if (Roles.userIsInRole(Meteor.user()._id, ['superadmin'])) {
|
||||||
|
Roles.removeUsersToRoles(userId, ['admin']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user