Skip to content

Instantly share code, notes, and snippets.

@zimt28 zimt28/entries.js
Created Apr 30, 2014

Embed
What would you like to do?
Meteor app - Allow rules
Meteor.Collection.prototype.addTimestamps = function () {
this.deny({
insert: function(userId, doc) {
doc.createdAt = Date.now();
doc.updatedAt = Date.now();
return false;
},
update: function(userId, doc, fieldNames, modifier) {
modifier.$set.updatedAt = Date.now();
return false;
},
});
};
Entries.addTimestamps();
Entries.allowed = ['_id', 'content', 'createdAt', 'updatedAt'];
Entries.allow({
insert: function (userId, doc) {
doc = _(doc).pick(Entries.allowed);
doc.userId = userId;
return !! userId;
},
update: function (userId, doc, fieldNames, modifier) {
return doc.userId === userId;
},
remove: function (userId, doc) {
return doc.userId === userId;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.