summaryrefslogtreecommitdiffstats
path: root/models/unsavedEdits.js
diff options
context:
space:
mode:
Diffstat (limited to 'models/unsavedEdits.js')
-rw-r--r--models/unsavedEdits.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/models/unsavedEdits.js b/models/unsavedEdits.js
new file mode 100644
index 00000000..87a70e22
--- /dev/null
+++ b/models/unsavedEdits.js
@@ -0,0 +1,34 @@
+// This collection shouldn't be manipulated directly by instead throw the
+// `UnsavedEdits` API on the client.
+UnsavedEditCollection = new Mongo.Collection('unsaved-edits');
+
+UnsavedEditCollection.attachSchema(new SimpleSchema({
+ fieldName: {
+ type: String,
+ },
+ docId: {
+ type: String,
+ },
+ value: {
+ type: String,
+ },
+ userId: {
+ type: String,
+ },
+}));
+
+if (Meteor.isServer) {
+ function isAuthor(userId, doc, fieldNames = []) {
+ return userId === doc.userId && fieldNames.indexOf('userId') === -1;
+ }
+ UnsavedEditCollection.allow({
+ insert: isAuthor,
+ update: isAuthor,
+ remove: isAuthor,
+ fetch: ['userId'],
+ });
+}
+
+UnsavedEditCollection.before.insert((userId, doc) => {
+ doc.userId = userId;
+});