Continued work on the historical pages.
This commit is contained in:
@@ -1,4 +1,10 @@
|
||||
import {Mongo} from "meteor/mongo";
|
||||
import {Meteor} from "meteor/meteor";
|
||||
import {check} from "meteor/check";
|
||||
import {Assets} from "/imports/api/assets";
|
||||
import {Students} from "/imports/api/students";
|
||||
import {Staff} from "/imports/api/staff";
|
||||
import {AssetTypes} from "/imports/api/asset-types";
|
||||
|
||||
export const AssetAssignmentHistory = new Mongo.Collection('assetAssignmentHistory');
|
||||
|
||||
@@ -17,4 +23,62 @@ startCondition: One of the condition options: [New, Like New, Good, Okay, Damage
|
||||
endCondition: One of the condition options: [New, Like New, Good, Okay, Damaged] (see assets.unassign for details).
|
||||
startConditionDetails: An optional text block for details on the condition.
|
||||
endConditionDetails: An optional text block for details on the condition.
|
||||
*/
|
||||
*/
|
||||
|
||||
|
||||
if (Meteor.isServer) {
|
||||
Meteor.methods({
|
||||
/**
|
||||
* Collects historical data on asset assignments.
|
||||
* @param params An object with a single attribute. The attribute must be one of: assetId, serial, staffId, or studentId. It will find all Assignment data for the given attribute value.
|
||||
* @returns {any} Array of Asset Assignment History objects.
|
||||
*/
|
||||
'AssetAssignmentHistory.get'(params) {
|
||||
if(Roles.userIsInRole(Meteor.userId(), "laptop-management", {anyScope:true})) {
|
||||
let query = {};
|
||||
|
||||
if(params.studentId) check(params.studentId, String)
|
||||
if(params.staffId) check(params.staffId, String)
|
||||
if(params.assetId) check(params.assetId, String)
|
||||
if(params.serial) check(params.serial, String)
|
||||
|
||||
if(params.serial) query.serial = params.serial;
|
||||
else if(params.assetId) query.assetId = params.assetId;
|
||||
else if(params.studentId) {
|
||||
query.assigneeId = params.studentId
|
||||
query.assigneeType = "Student"
|
||||
}
|
||||
else if(params.staffId) {
|
||||
query.assigneeId = params.staffId
|
||||
query.assigneeType = "Staff"
|
||||
}
|
||||
else {
|
||||
query = undefined;
|
||||
}
|
||||
|
||||
if(query) {
|
||||
//Sort by the last time the record was updated from most to least recent.
|
||||
let result = AssetAssignmentHistory.find(query, {sort: {endDate: -1}}).fetch();
|
||||
|
||||
//Add some additional data to the records.
|
||||
for(let next of result) {
|
||||
if(next.serial) {
|
||||
next.asset = Assets.findOne({serial: next.serial});
|
||||
}
|
||||
|
||||
if(next.asset) {
|
||||
next.assetType = AssetTypes.findOne({_id: next.asset.assetType})
|
||||
}
|
||||
|
||||
if(next.assigneeId) {
|
||||
next.assignee = next.asset.assigneeType === "Student" ? Students.findOne({_id: next.assigneeId}) : Staff.findOne({_id: next.assigneeId})
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
} else return null;
|
||||
}
|
||||
else return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -46,6 +46,9 @@ if (Meteor.isServer) {
|
||||
if(Roles.userIsInRole(Meteor.userId(), "laptop-management", {anyScope:true})) {
|
||||
let query = {};
|
||||
|
||||
if(params.studentId) check(params.studentId, String)
|
||||
if(params.staffId) check(params.staffId, String)
|
||||
|
||||
// For asset ID's, we need to get the serial from the asset collection first.
|
||||
if(params.assetId) {
|
||||
let asset = Assets.findOne({assetId : params.assetId});
|
||||
@@ -55,6 +58,8 @@ if (Meteor.isServer) {
|
||||
params.regex = false;
|
||||
}
|
||||
}
|
||||
// console.log('chromebook data')
|
||||
// console.log(params)
|
||||
|
||||
if (params.deviceId) query.deviceId = params.regex ? {
|
||||
$regex: params.deviceId,
|
||||
@@ -64,14 +69,19 @@ if (Meteor.isServer) {
|
||||
$regex: params.serial,
|
||||
$options: "i"
|
||||
} : params.serial;
|
||||
// else if (params.assetId) {
|
||||
// let asset = Assets.findOne({assetId: params.assetId});
|
||||
//
|
||||
// if(asset.serial) {
|
||||
// // An exact search.
|
||||
// query.serial = asset.serial;
|
||||
// }
|
||||
// }
|
||||
else if(params.studentId) {
|
||||
const student = Students.findOne({_id: params.studentId})
|
||||
|
||||
console.log(student)
|
||||
if(student) query.email = student.email;
|
||||
else query = undefined
|
||||
}
|
||||
else if(params.staffId) {
|
||||
const staff = Staff.findOne({_id: params.staffId})
|
||||
|
||||
if(staff) query.email = staff.email;
|
||||
else query = undefined
|
||||
}
|
||||
else if (params.email) query.email = params.regex ? {
|
||||
$regex: params.email,
|
||||
$options: "i"
|
||||
@@ -82,6 +92,9 @@ if (Meteor.isServer) {
|
||||
else {
|
||||
query = undefined;
|
||||
}
|
||||
|
||||
// console.log("query")
|
||||
// console.log(query)
|
||||
|
||||
if(query) {
|
||||
// console.log("Collecting Chromebook Data: ");
|
||||
@@ -113,6 +126,8 @@ if (Meteor.isServer) {
|
||||
}
|
||||
}
|
||||
|
||||
// console.log('returning')
|
||||
// console.log(result)
|
||||
return result;
|
||||
} else return null;
|
||||
}
|
||||
|
||||
72
imports/api/users.js
Normal file
72
imports/api/users.js
Normal file
@@ -0,0 +1,72 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { Roles } from 'meteor/alanning:roles';
|
||||
import { check } from 'meteor/check';
|
||||
|
||||
// console.log("Setting Up Users...")
|
||||
|
||||
if (Meteor.isServer) {
|
||||
Meteor.publish(null, function() {
|
||||
if(this.userId) {
|
||||
return Meteor.roleAssignment.find({'user._id': this.userId});
|
||||
}
|
||||
else {
|
||||
this.ready();
|
||||
}
|
||||
});
|
||||
|
||||
Meteor.publish(null, function() {
|
||||
return Meteor.roles.find({});
|
||||
});
|
||||
|
||||
Meteor.publish("allUsers", function() {
|
||||
// console.log(Meteor.isServer);
|
||||
// console.log("AllUsers");
|
||||
// console.log("Meteor.userId(): " + Meteor.userId());
|
||||
// // console.log(Roles.userIsInRole(Meteor.userId(), "laptop-management"));
|
||||
// console.log(Meteor.roleAssignment.find({ 'user._id': Meteor.userId() }).fetch());
|
||||
// console.log(Roles.userIsInRole(Meteor.user(), "admin", {anyScope:true}));
|
||||
|
||||
// Note: For some reason the {anyScope: true} is necessary on the server for the function to actually check roles.
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
//console.log(Meteor.users.find({}).fetch());
|
||||
return Meteor.users.find({});
|
||||
}
|
||||
else {
|
||||
return [];
|
||||
}
|
||||
});
|
||||
Meteor.publish("allRoleAssignments", function() {
|
||||
// Note: For some reason the {anyScope: true} is necessary on the server for the function to actually check roles.
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
return Meteor.roleAssignment.find({});
|
||||
}
|
||||
else {
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
Meteor.methods({
|
||||
'users.setUserRoles'(userId, roles) {
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
check(userId, String);
|
||||
check(roles, Array);
|
||||
Roles.setUserRoles(userId, roles, {anyScope: true});
|
||||
}
|
||||
},
|
||||
// 'tasks.setPrivate'(taskId, setToPrivate) {
|
||||
// check(taskId, String);
|
||||
// check(setToPrivate, Boolean);
|
||||
//
|
||||
// const task = Tasks.findOne(taskId);
|
||||
//
|
||||
// // Make sure only the task owner can make a task private
|
||||
// if (task.owner !== this.userId) {
|
||||
// throw new Meteor.Error('not-authorized');
|
||||
// }
|
||||
//
|
||||
// Tasks.update(taskId, { $set: { private: setToPrivate } });
|
||||
// },
|
||||
});
|
||||
}
|
||||
|
||||
// console.log("Users setup.")
|
||||
Reference in New Issue
Block a user