added requests collection for admin requests
This commit is contained in:
parent
0de9853dc4
commit
860bed577d
@ -1,6 +1,7 @@
|
|||||||
schools = new Mongo.Collection("Schools");
|
schools = new Mongo.Collection("Schools");
|
||||||
classes = new Mongo.Collection("Classes");
|
classes = new Mongo.Collection("Classes");
|
||||||
work = new Mongo.Collection("Work");
|
work = new Mongo.Collection("Work");
|
||||||
|
requests = new Mongo.Collection("Requests");
|
||||||
|
|
||||||
schools.schema = new SimpleSchema({
|
schools.schema = new SimpleSchema({
|
||||||
name: {type: String},
|
name: {type: String},
|
||||||
@ -37,3 +38,9 @@ work.schema = new SimpleSchema({
|
|||||||
done: {type: [String], optional: true},
|
done: {type: [String], optional: true},
|
||||||
type: {type: String}
|
type: {type: String}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
requests.schema = new SimpleSchema({
|
||||||
|
requestor: {type: String},
|
||||||
|
request: {type: String},
|
||||||
|
timeRequested: {type: Date}
|
||||||
|
});
|
||||||
|
|||||||
@ -7,6 +7,7 @@ Router.route('/', {
|
|||||||
Meteor.subscribe('classes',this.params._id),
|
Meteor.subscribe('classes',this.params._id),
|
||||||
Meteor.subscribe('schools',this.params._id),
|
Meteor.subscribe('schools',this.params._id),
|
||||||
Meteor.subscribe('work',this.params._id),
|
Meteor.subscribe('work',this.params._id),
|
||||||
|
Meteor.subscribe('requests',this.params._id),
|
||||||
Meteor.subscribe('users',this.params._id)
|
Meteor.subscribe('users',this.params._id)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -35,6 +36,7 @@ Router.route('/profile', {
|
|||||||
Meteor.subscribe('classes',this.params._id),
|
Meteor.subscribe('classes',this.params._id),
|
||||||
Meteor.subscribe('schools',this.params._id),
|
Meteor.subscribe('schools',this.params._id),
|
||||||
Meteor.subscribe('work',this.params._id),
|
Meteor.subscribe('work',this.params._id),
|
||||||
|
Meteor.subscribe('requests',this.params._id),
|
||||||
Meteor.subscribe('users',this.params._id)
|
Meteor.subscribe('users',this.params._id)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -72,6 +72,14 @@ Meteor.publish('work', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Meteor.publish('requests', function() {
|
||||||
|
if (Roles.userIsInRole(this.userId, ['superadmin', 'admin'])) {
|
||||||
|
return requests.find();
|
||||||
|
} else {
|
||||||
|
return requests.find({requestor: this.userId});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Meteor.publish('users', function() {
|
Meteor.publish('users', function() {
|
||||||
if (Roles.userIsInRole(this.userId, ['superadmin', 'admin'])) {
|
if (Roles.userIsInRole(this.userId, ['superadmin', 'admin'])) {
|
||||||
return Meteor.users.find();
|
return Meteor.users.find();
|
||||||
@ -89,7 +97,9 @@ Security.permit(['insert', 'update', 'remove']).collections([schools, classes, w
|
|||||||
Meteor.methods({
|
Meteor.methods({
|
||||||
'genCode': function() {
|
'genCode': function() {
|
||||||
currcode = Math.random().toString(36).substr(2, 6);
|
currcode = Math.random().toString(36).substr(2, 6);
|
||||||
while (classes.findOne({code: currcode}) !== undefined) {
|
while (classes.findOne({
|
||||||
|
code: currcode
|
||||||
|
}) !== undefined) {
|
||||||
currcode = Math.random().toString(36).substr(2, 6);
|
currcode = Math.random().toString(36).substr(2, 6);
|
||||||
}
|
}
|
||||||
return currcode;
|
return currcode;
|
||||||
@ -268,7 +278,7 @@ Meteor.methods({
|
|||||||
},
|
},
|
||||||
'createWork': function(input) {
|
'createWork': function(input) {
|
||||||
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();
|
||||||
input.creator = Meteor.userId();
|
input.creator = Meteor.userId();
|
||||||
work.schema.validate(input);
|
work.schema.validate(input);
|
||||||
@ -295,7 +305,7 @@ Meteor.methods({
|
|||||||
},
|
},
|
||||||
'editWork': function(change) {
|
'editWork': function(change) {
|
||||||
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 currentclass = classes.findOne({
|
var currentclass = classes.findOne({
|
||||||
_id: work.findOne({
|
_id: work.findOne({
|
||||||
@ -532,6 +542,8 @@ Meteor.methods({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw "Unauthorized";
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'createAdmin': function(userId) {
|
'createAdmin': function(userId) {
|
||||||
@ -543,5 +555,19 @@ Meteor.methods({
|
|||||||
if (Roles.userIsInRole(Meteor.user()._id, ['superadmin'])) {
|
if (Roles.userIsInRole(Meteor.user()._id, ['superadmin'])) {
|
||||||
Roles.removeUsersToRoles(userId, ['admin']);
|
Roles.removeUsersToRoles(userId, ['admin']);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
'createRequest': function(request) {
|
||||||
|
if (request.length <= 500 && Meteor.userId() !== null) {
|
||||||
|
requests.insert({
|
||||||
|
requestor: Meteor.userId(),
|
||||||
|
request: request,
|
||||||
|
timeRequested: new Date()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'deleteRequest': function(requestId) {
|
||||||
|
if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) {
|
||||||
|
requests.remove({_id: requestId});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user