summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFilipe David Borba Manana <fdmanana@apache.org>2010-11-17 11:41:44 +0000
committerFilipe David Borba Manana <fdmanana@apache.org>2010-11-17 11:41:44 +0000
commite058233672db611c9046f1af69952d093db09606 (patch)
tree19ec539bdf03543e930014bbcb8995bd892afa78 /src
parent2fd61c4f5174e297ca09dd63f6916820328d3ebd (diff)
Replicator DB: removed some restrictions from the default document update validation function and added some logging.
1) Now it's easier to replicate to the replicator DB and by default it's writable by any user (just like any user can POST to /_replicate/); 2) The logging in the document validation function allows us to see in the log, after a replication, why a document was not written to the target replicator DB. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@1035986 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/couchdb/couch_js_functions.hrl53
-rw-r--r--src/couchdb/couch_rep.erl2
2 files changed, 15 insertions, 40 deletions
diff --git a/src/couchdb/couch_js_functions.hrl b/src/couchdb/couch_js_functions.hrl
index f850dd4c..e2121aa9 100644
--- a/src/couchdb/couch_js_functions.hrl
+++ b/src/couchdb/couch_js_functions.hrl
@@ -99,55 +99,32 @@
-define(REP_DB_DOC_VALIDATE_FUN, <<"
function(newDoc, oldDoc, userCtx) {
- var isAdmin = (userCtx.roles.indexOf('_admin') >= 0);
- var isReplicator = (userCtx.roles.indexOf('_replicator') >= 0);
-
- if (oldDoc && !newDoc._deleted && !isReplicator) {
- throw({forbidden:
- 'Only the replicator can edit replication documents. ' +
- 'Admins can only add and delete replication documents.'
- });
- } else if (!isAdmin) {
- throw({forbidden:
- 'Only admins may add/delete replication documents.'
- });
- }
-
- if (!oldDoc && newDoc.state) {
- throw({forbidden:
- 'The state field can only be set by the replicator.'
- });
- }
+ if (newDoc.user_ctx) {
- if (!oldDoc && newDoc.replication_id) {
- throw({forbidden:
- 'The replication_id field can only be set by the replicator.'
- });
- }
+ function reportError(error_msg) {
+ log('Error writing document ' + newDoc._id +
+ ' to replicator DB: ' + error_msg);
+ throw({forbidden: error_msg});
+ }
- if (newDoc.user_ctx) {
var user_ctx = newDoc.user_ctx;
if (typeof user_ctx !== 'object') {
- throw({forbidden: 'The user_ctx property must be an object.'});
+ reportError('The user_ctx property must be an object.');
}
if (!(user_ctx.name === null ||
(typeof user_ctx.name === 'undefined') ||
((typeof user_ctx.name === 'string') &&
user_ctx.name.length > 0))) {
- throw({forbidden:
- 'The name property of the user_ctx must be a ' +
- 'non-empty string.'
- });
+ reportError('The name property of the user_ctx must be a ' +
+ 'non-empty string.');
}
if ((typeof user_ctx.roles !== 'undefined') &&
(typeof user_ctx.roles.length !== 'number')) {
- throw({forbidden:
- 'The roles property of the user_ctx must be ' +
- 'an array of strings.'
- });
+ reportError('The roles property of the user_ctx must be ' +
+ 'an array of strings.');
}
if (user_ctx.roles) {
@@ -155,13 +132,11 @@
var role = user_ctx.roles[i];
if (typeof role !== 'string' || role.length === 0) {
- throw({forbidden: 'Roles must be non-empty strings.'});
+ reportError('Each role must be a non-empty string.');
}
if (role[0] === '_') {
- throw({forbidden:
- 'System roles (starting with underscore) ' +
- 'are not allowed.'
- });
+ reportError('System roles (starting with underscore) ' +
+ 'are not allowed.');
}
}
}
diff --git a/src/couchdb/couch_rep.erl b/src/couchdb/couch_rep.erl
index d35471c5..e288efa6 100644
--- a/src/couchdb/couch_rep.erl
+++ b/src/couchdb/couch_rep.erl
@@ -862,7 +862,7 @@ maybe_set_triggered({RepProps} = RepDoc, RepId) ->
ensure_rep_db_exists() ->
DbName = ?l2b(couch_config:get("replicator", "db", "_replicator")),
Opts = [
- {user_ctx, #user_ctx{roles=[<<"_admin">>, <<"_replicator">>]}},
+ {user_ctx, #user_ctx{roles=[<<"_admin">>]}},
sys_db
],
case couch_db:open(DbName, Opts) of