unsavedEdits.js 740 B

12345678910111213141516171819202122232425262728293031323334
  1. // This collection shouldn't be manipulated directly by instead throw the
  2. // `UnsavedEdits` API on the client.
  3. UnsavedEditCollection = new Mongo.Collection('unsaved-edits');
  4. UnsavedEditCollection.attachSchema(new SimpleSchema({
  5. fieldName: {
  6. type: String,
  7. },
  8. docId: {
  9. type: String,
  10. },
  11. value: {
  12. type: String,
  13. },
  14. userId: {
  15. type: String,
  16. },
  17. }));
  18. if (Meteor.isServer) {
  19. function isAuthor(userId, doc, fieldNames = []) {
  20. return userId === doc.userId && fieldNames.indexOf('userId') === -1;
  21. }
  22. UnsavedEditCollection.allow({
  23. insert: isAuthor,
  24. update: isAuthor,
  25. remove: isAuthor,
  26. fetch: ['userId'],
  27. });
  28. }
  29. UnsavedEditCollection.before.insert((userId, doc) => {
  30. doc.userId = userId;
  31. });