Allow & Deny vs Methods is one of the big debates within the Meteor community. Personally I tend to fall more on the side of Methods, simply because Allow & Deny is very hard to get right.
To illustrate this, I decided to hold a simple coding challenge:
Alright. I’ve updated my answer again. This should really be NSA proof!
Messages.allow
update: (userId, doc, fields, modifier) ->
true
# change this!
Messages.deny
update: (userId, doc, fields, modifier) ->
return true if !userId or 'createdAt' in fields or 'userId' in fields
return true if modifier.$addToSet?.likes and doc.likes.indexOf(userId) != -1
if 'likesCount' in fields
return true if !modifier.$addToSet?.likes
return true if !modifier.$inc?.likesCount
return true if modifier.$inc.likesCount != 1
return true if userId != doc.userId and 'body' in fields
return false
I have a more “refined” opinion on this topic now, I wonder what you think:
Allow/Deny is fine for insert, remove, and a hypothetical read; there’s only one concern that you might want computed properties on create, but collection hooks take care of that.
It can be tricky for insert as well, depending on what you want to do. Unless you combine it with collection hooks, that can work too.
Another rule I came up with: allow/deny is ok when you’re updating your own documents, but not a good idea when you want to give users permission to change something on other user’s documents.
I modified this a bit to use the socialize:likeable package which I authored but it still does the same basic thing and I believe satisfies all of the requirements.
Man. I can’t believe I missed that. It’s pretty obvious now that I think about my implementation (on mobile can’t see it). I’m partial to meteor methods for stuff like this for that exact reason.