unsavedEdits.js 801 B

1234567891011121314151617181920212223242526272829303132333435
  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. UnsavedEditCollection.allow({
  28. insert: isAuthor,
  29. update: isAuthor,
  30. remove: isAuthor,
  31. fetch: ['userId'],
  32. });
  33. }