Last active
August 29, 2015 14:05
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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