2
0

unsavedEdits.js 899 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. autoValue() { // eslint-disable-line consistent-return
  17. if (this.isInsert && !this.isSet) {
  18. return this.userId;
  19. }
  20. },
  21. },
  22. }));
  23. if (Meteor.isServer) {
  24. function isAuthor(userId, doc, fieldNames = []) {
  25. return userId === doc.userId && fieldNames.indexOf('userId') === -1;
  26. }
  27. Meteor.startup(() => {
  28. UnsavedEditCollection._collection._ensureIndex({ userId: 1 });
  29. });
  30. UnsavedEditCollection.allow({
  31. insert: isAuthor,
  32. update: isAuthor,
  33. remove: isAuthor,
  34. fetch: ['userId'],
  35. });
  36. }