Created
March 5, 2019 16:02
-
-
Save nbari/0cc78a09739c3d4ac07adc1f18bbb66a to your computer and use it in GitHub Desktop.
couchdb read-only _design/read_only
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
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) | |
throw ({forbidden:"read-only"}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment