diff --git a/chromebook-checkout-meteor/collections/carts.js b/chromebook-checkout-meteor/collections/carts.js index 90f3004..8e3892b 100644 --- a/chromebook-checkout-meteor/collections/carts.js +++ b/chromebook-checkout-meteor/collections/carts.js @@ -4,7 +4,7 @@ carts.allow({ return Roles.userIsInRole(userId, ['admin']); }, update: function (userId, doc) { - return (userId != null); + return Roles.userIsInRole(userId, ['admin', 'teacher']; }, remove: function (userId, doc) { return Roles.userIsInRole(userId, ['admin']); diff --git a/chromebook-checkout-meteor/collections/chromebooks.js b/chromebook-checkout-meteor/collections/chromebooks.js index 759cc02..21a0a2d 100644 --- a/chromebook-checkout-meteor/collections/chromebooks.js +++ b/chromebook-checkout-meteor/collections/chromebooks.js @@ -4,7 +4,13 @@ Chromebooks.allow({ return Roles.userIsInRole(userId, ['admin']); }, update: function (userId, doc) { - return (userId != null); + if ((Chromebooks.findOne({userid: Meteor.userId()}) === undefined) + || (Roles.userIsInRole(Meteor.userId(), ['admin', 'teacher']))) { + Chromebooks.update(this._id, {$set: {status: 1}}); + Chromebooks.update(this._id, {$set: {last_checkout: new Date()}}); + Chromebooks.update(this._id, {$set: {userid: Meteor.userId()}}); + Chromebooks.update(this._id, {$set: {user: Meteor.user().profile.name}}); + } }, remove: function (userId, doc) { return Roles.userIsInRole(userId, ['admin']);