Sorry, that is supposed to be:
ddoc = {
validates: [
{
match: function(document) { return document.type == 'user'; }
validate: function(new_doc, old_doc, user_context) {
if (!user_context.admin || old_doc.username == user_context.username)
throw 'forbidden', ...;
}
}
]
}And you'd go from top to bottom calling match, and if match returned true, call validate.
