Skip to content

Instantly share code, notes, and snippets.

Created March 5, 2019 16:02
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
couchdb read-only _design/read_only
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(
IS_DB_ADMIN = true;
for(var i = 0; i < userCtx.roles; i++)
if(~ secObj.admins.roles.indexOf(userCtx.roles[i]))
IS_DB_ADMIN = true;
throw ({forbidden:"read-only"});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment