Skip to content

Instantly share code, notes, and snippets.

@rcy
Last active August 29, 2015 14:05
Show Gist options
  • Save rcy/4592235d7e0ea5c6f439 to your computer and use it in GitHub Desktop.
Save rcy/4592235d7e0ea5c6f439 to your computer and use it in GitHub Desktop.
a user can insert a document one time into a collection, after that, the insert is denied
// some random collection
Things = new Meteor.Collection('things');
// collection used to track users who are blocked from inserting
Blocked = new Meteor.Collection('blocked');
if (Meteor.isServer) {
Meteor.startup(function () {
// remove all documents on startup for testing purposes
Blocked.remove({});
Things.remove({});
});
// allow inserting generally...
Things.allow({
insert: function () {
return true;
}
});
// track inserting in Blocked collection, only allow one insert on Things per userId
Things.deny({
insert: function (userId, doc) {
if (Blocked.findOne({userId: userId})) {
return true;
} else {
Blocked.insert({userId: userId});
return false;
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment