You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by jc...@apache.org on 2010/02/14 19:19:10 UTC

svn commit: r910055 - in /couchdb/branches/0.11.x: ./ etc/default/couchdb share/www/script/futon.browse.js share/www/script/jquery.dialog.js

Author: jchris
Date: Sun Feb 14 18:19:09 2010
New Revision: 910055

URL: http://svn.apache.org/viewvc?rev=910055&view=rev
Log:
Merging r910054 into 'branches/0.11.x':
fix futon to use _security object. thanks Filipe Manana, closes COUCHDB-654

Modified:
    couchdb/branches/0.11.x/   (props changed)
    couchdb/branches/0.11.x/etc/default/couchdb   (props changed)
    couchdb/branches/0.11.x/share/www/script/futon.browse.js
    couchdb/branches/0.11.x/share/www/script/jquery.dialog.js

Propchange: couchdb/branches/0.11.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun Feb 14 18:19:09 2010
@@ -6,4 +6,4 @@
 /couchdb/branches/list-iterator:782292-784593
 /couchdb/branches/tail_header:775760-778477
 /couchdb/tags/0.10.0:825400
-/couchdb/trunk:909247
+/couchdb/trunk:909247,910054

Propchange: couchdb/branches/0.11.x/etc/default/couchdb
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun Feb 14 18:19:09 2010
@@ -6,5 +6,5 @@
 /couchdb/branches/list-iterator/etc/default/couchdb:782292-784593
 /couchdb/branches/tail_header/etc/default/couchdb:775760-778477
 /couchdb/tags/0.10.0/etc/default/couchdb:825400
-/couchdb/trunk/etc/default/couchdb:909247
+/couchdb/trunk/etc/default/couchdb:909247,910054
 /incubator/couchdb/trunk/etc/default/couchdb:642419-694440

Modified: couchdb/branches/0.11.x/share/www/script/futon.browse.js
URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/share/www/script/futon.browse.js?rev=910055&r1=910054&r2=910055&view=diff
==============================================================================
--- couchdb/branches/0.11.x/share/www/script/futon.browse.js [utf-8] (original)
+++ couchdb/branches/0.11.x/share/www/script/futon.browse.js [utf-8] Sun Feb 14 18:19:09 2010
@@ -182,25 +182,69 @@
       this.databaseSecurity = function() {
         $.showDialog("dialog/_database_security.html", {
           load : function(d) {
-            ["admin", "reader"].forEach(function(key) {
-              db.getDbProperty("_"+key+"s", {
-                success : function(r) {
-                  $("input[name="+key+"_names]",d).val(JSON.stringify(r.names||[]));
-                  $("input[name="+key+"_roles]",d).val(JSON.stringify(r.roles||[]));
-                }
-              });
+            db.getDbProperty("_security", {
+              success: function(r) {
+                ["admin", "reader"].forEach(function(key) {
+                  var names = [];
+                  var roles = [];
+
+                  if (r && typeof r[key + "s"] === "object") {
+                    if ($.isArray(r[key + "s"]["names"])) {
+                      names = r[key + "s"]["names"];
+                    }
+                    if ($.isArray(r[key + "s"]["roles"])) {
+                      roles = r[key + "s"]["roles"];
+                    }
+                  }
+
+                  $("input[name=" + key + "_names]", d).val(JSON.stringify(names));
+                  $("input[name=" + key + "_roles]", d).val(JSON.stringify(roles));
+                });
+              }
             });
           },
           // maybe this should be 2 forms
           submit: function(data, callback) {
+            var errors = {};
+            var secObj = {
+              admins: {
+                names: [],
+                roles: []
+              },
+              readers: {
+                names: [],
+                roles: []
+              }
+            };
+
             ["admin", "reader"].forEach(function(key) {
-              var new_value = {
-                names : JSON.parse(data[key+"_names"]),
-                roles : JSON.parse(data[key+"_roles"])
-              };
-              db.setDbProperty("_"+key+"s", new_value);
+              var names, roles;
+
+              try {
+                names = JSON.parse(data[key + "_names"]);
+              } catch(e) { }
+              try {
+                roles = JSON.parse(data[key + "_roles"]);
+              } catch(e) { }
+
+              if ($.isArray(names)) {
+                secObj[key + "s"]["names"] = names;
+              } else {
+                errors[key + "_names"] = "The " + key +
+                  " names must be an array of strings";
+              }
+              if ($.isArray(roles)) {
+                secObj[key + "s"]["roles"] = roles;
+              } else {
+                errors[key + "_roles"] = "The " + key +
+                  " roles must be an array of strings";
+              }
             });
-            callback();
+
+            if ($.isEmptyObject(errors)) {
+              db.setDbProperty("_security", secObj);
+            }
+            callback(errors);
           }
         });
       }

Modified: couchdb/branches/0.11.x/share/www/script/jquery.dialog.js
URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/share/www/script/jquery.dialog.js?rev=910055&r1=910054&r2=910055&view=diff
==============================================================================
--- couchdb/branches/0.11.x/share/www/script/jquery.dialog.js [utf-8] (original)
+++ couchdb/branches/0.11.x/share/www/script/jquery.dialog.js [utf-8] Sun Feb 14 18:19:09 2010
@@ -79,7 +79,7 @@
             data[this.name] = this.value; // file inputs need special handling
           });
           options.submit(data, function callback(errors) {
-            if (errors == null || errors == {}) {
+            if ($.isEmptyObject(errors)) {
               dismiss();
             } else {
               for (var name in errors) {