Created
July 5, 2018 17:21
-
-
Save ThibaultJanBeyer/389bca37f4b6973b84908895300bb7de to your computer and use it in GitHub Desktop.
read only couchdb: add this to the design documents of the database you want to protect. Now, only users with role admin will be able to edit or add documents to this database.
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
{ | |
"_id": "_design/auth", | |
"language": "javascript", | |
"validate_doc_update": "function(newDoc, oldDoc, userCtx) { if (userCtx.roles.indexOf('admin') !== -1) { return; } else { throw ({ forbidden: 'Only admins may edit the database' }); } }" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With cURL:
Replace
username
,password
anddatabase
accordingly.Change
userCtx.roles.indexOf('admin') !== -1
touserCtx.name === 'admin'
if you want to check for a specific username.