Created
April 27, 2016 06:34
-
-
Save mkorkmaz/27bcd48c4f4604cca59ffbe7ede250e8 to your computer and use it in GitHub Desktop.
CouchDB readonly database design document.
This file contains 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
# 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