Skip to content

Instantly share code, notes, and snippets.

@zimt28
Created April 30, 2014 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zimt28/3d1e8c4e9c054467e916 to your computer and use it in GitHub Desktop.
Save zimt28/3d1e8c4e9c054467e916 to your computer and use it in GitHub Desktop.
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