oreilly / couchdb-guide

CouchDB: The Definitive Guide
http://guide.couchdb.org/
501 stars 139 forks source link

Comment on "Validations functions" #400

Open jeroenvandijk opened 13 years ago

jeroenvandijk commented 13 years ago

The unchanged validation function doesn't seem to allow deletion of docs. I think it should be the following instead (note the _delete check):

function (newDoc, oldDoc, userCtx) {
  function unchanged(field) {
    if (oldDoc && !newDoc._deleted && toJSON(oldDoc[field]) != toJSON(newDoc[field]))
      throw({forbidden : "Field can't be changed: " + field});
  }
  unchanged("created_at");
}

This will not allow changes to the created_at field, but does allow deletion.

ido-ran commented 12 years ago

You should also check the very important author field otherwise the whole point of limit only the author to be able to change the document has gone.