You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Created a Makefile and a script for fast and easy deployment of the site design document
* Added documentation how to compile the site design document
* The RPC server now supports www-form-urlencoded requests and JSONP for the User ID request sent by the web frontend
Misc:
* Moved all design documents out of the code and into separate files in apps/ecoinpool/priv
* Implemented functions for checking if all design documents exist
"validate_doc_update": "function(newDoc, oldDoc, userCtx) {\n switch ((newDoc._deleted ? oldDoc.type : newDoc.type)) {\n case 'configuration':\n if (userCtx.roles.indexOf('_admin') === -1)\n throw({forbidden: 'Only admins may edit the root configuration'});\n break;\n case 'sub-pool':\n if (userCtx.roles.indexOf('_admin') === -1)\n throw({forbidden: 'Only admins may edit Subpool configurations'});\n break;\n case 'worker':\n if (!newDoc._deleted) {\n if (newDoc.sub_pool_id === undefined)\n throw({forbidden: 'The sub_pool_id field is missing'});\n if (typeof newDoc.name != 'string' || newDoc.name == '')\n throw({forbidden: 'The name field is missing or invalid'});\n if (userCtx.roles.indexOf('_admin') === -1) {\n if (oldDoc !== null) {\n if (oldDoc.sub_pool_id != newDoc.sub_pool_id)\n throw({forbidden: 'You cannot change the sub_pool_id field'});\n else if (oldDoc.user_id != newDoc.user_id)\n throw({forbidden: 'You cannot change the user_id field'});\n }\n if (typeof newDoc.user_id !== 'number')\n throw({forbidden: 'user_id must be a number'});\n if (userCtx.roles.indexOf('user_id:' + newDoc.sub_pool_id + ':' + newDoc.user_id) === -1)\n throw({forbidden: 'You may only create or update your own workers'});\n if (newDoc.name != userCtx.name && (newDoc.name.indexOf('_') === -1 || newDoc.name.substr(0, newDoc.name.indexOf('_')) != userCtx.name))\n throw({forbidden: 'Worker names must have the format \"username[_suffix]\"'});\n }\n }\n else if (userCtx.roles.indexOf('_admin') === -1) {\n if (userCtx.roles.indexOf('user_id:' + oldDoc.sub_pool_id + ':' + oldDoc.user_id) === -1)\n throw({forbidden: 'You may only delete your own workers'});\n }\n break;\n default:\n throw({forbidden: 'Invalid document type'});\n }\n}"
"reduce": "function(keys, values, rereduce) {var cmp = function (a, b) {for (var i in a) {if (a[i] != b[i]) return (a[i] < b[i]);} return false;}; var best = null; for (var i in values) {if (best === null || cmp(best[0], values[i][0])) best = values[i];} return best;}"
"validate_doc_update": "function(newDoc, oldDoc, userCtx) {\n if (newDoc.name && newDoc.name.indexOf(\"_\") != -1)\n throw({forbidden: 'The username must not contain an underscore'});\n}",
5
+
"views": {
6
+
"user_ids": {
7
+
"map": "function(doc) {\n for (var i in doc.roles) {\n var spl = doc.roles[i].split(\":\");\n if (spl.length == 3 && spl[0] == \"user_id\")\n emit([spl[1], doc.name], parseInt(spl[2]));\n }\n}",
8
+
"reduce": "function(keys, values, rereduce) {\n var best = null;\n for (var i in values) {\n if (best === null || best < values[i])\n best = values[i];\n }\n return best;\n}"
{<<"reduce">>, <<"function(keys, values, rereduce) {var cmp = function (a, b) {for (var i in a) {if (a[i] != b[i]) return (a[i] < b[i]);} return false;}; var best = null; for (var i in values) {if (best === null || cmp(best[0], values[i][0])) best = values[i];} return best;}">>}
278
-
]}}
279
-
]}}
280
-
]}),
281
-
{ok, _} =couchbeam:save_doc(DB, {[
282
-
{<<"_id">>, <<"_design/auth">>},
283
-
{<<"language">>, <<"javascript">>},
284
-
{<<"validate_doc_update">>, <<"function(newDoc, oldDoc, userCtx) {if (userCtx.roles.indexOf('_admin') !== -1) return; else throw({forbidden: 'Only admins may edit the database'});}">>}
0 commit comments