Skip to content

Instantly share code, notes, and snippets.

@mkorkmaz
Created April 27, 2016 06:34
Show Gist options
  • Save mkorkmaz/27bcd48c4f4604cca59ffbe7ede250e8 to your computer and use it in GitHub Desktop.
Save mkorkmaz/27bcd48c4f4604cca59ffbe7ede250e8 to your computer and use it in GitHub Desktop.
CouchDB readonly database design document.
# set validate_doc_update value as:
function(newDoc, oldDoc, userCtx, secObj) {
var ddoc = this;
secObj.admins = secObj.admins || {};
secObj.admins.names = secObj.admins.names || [];
secObj.admins.roles = secObj.admins.roles || [];
var IS_DB_ADMIN = false;
if(~ userCtx.roles.indexOf('_admin')){
IS_DB_ADMIN = true;
}
if(~ secObj.admins.names.indexOf(userCtx.name)){
IS_DB_ADMIN = true;
}
for(var i = 0; i < userCtx.roles; i++){
if(~ secObj.admins.roles.indexOf(userCtx.roles[i])){
IS_DB_ADMIN = true;
}
}
if(IS_DB_ADMIN){
log('Admin change on read-only db: ' + newDoc._id);
}
else{
throw {'forbidden':'This database is read-only'};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment