couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gar...@apache.org
Subject [7/7] git commit: updated refs/heads/route-events to 3ebf299
Date Tue, 14 May 2013 13:29:37 GMT
integrate auth module, auth plugin and session object


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/3ebf2992
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/3ebf2992
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/3ebf2992

Branch: refs/heads/route-events
Commit: 3ebf29925afe1e7dc7e405d2cd75cbcfa54be05d
Parents: 1cbe033
Author: Garren Smith <garren.smith@gmail.com>
Authored: Tue May 14 14:30:47 2013 +0200
Committer: Garren Smith <garren.smith@gmail.com>
Committed: Tue May 14 15:28:42 2013 +0200

----------------------------------------------------------------------
 src/fauxton/app/addons/auth/base.js                |   28 ++--
 src/fauxton/app/addons/auth/resources.js           |  125 ++++++++-------
 .../app/addons/auth/templates/nav_dropdown.html    |   26 +++
 .../app/addons/auth/templates/nav_link.html        |   25 +---
 .../app/addons/auth/templates/nav_link_title.html  |   24 +++
 src/fauxton/app/addons/logs/resources.js           |   12 +-
 src/fauxton/app/api.js                             |  117 +++++++++-----
 src/fauxton/app/modules/databases/routes.js        |    2 +-
 src/fauxton/app/modules/fauxton/base.js            |    8 +-
 src/fauxton/app/router.js                          |   22 ++--
 10 files changed, 235 insertions(+), 154 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/3ebf2992/src/fauxton/app/addons/auth/base.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/auth/base.js b/src/fauxton/app/addons/auth/base.js
index 9f40308..b4a38c1 100644
--- a/src/fauxton/app/addons/auth/base.js
+++ b/src/fauxton/app/addons/auth/base.js
@@ -18,33 +18,31 @@ define([
 
 function(app, FauxtonAPI, Auth) {
 
+  Auth.session = new Auth.Session();
+  FauxtonAPI.setSession(Auth.session);
+
   Auth.initialize = function() {
-    var session = Auth.session = new Auth.Session();
     Auth.navLink = new Auth.NavLink({model: Auth.session});
 
     FauxtonAPI.addHeaderLink({
       title: "Auth", 
       href: "#_auth",
       view: Auth.navLink,
-      establish: [Auth.session.fetchOnce()]
+      establish: [FauxtonAPI.session.fetchUser()]
     });
 
-    var auth = function (roles, layout) {
+    var auth = function (session, roles, layout) {
       var deferred = $.Deferred();
 
-      var sessionDeferred = session.fetchOnce().then(function () {
-        console.log(session);
-
-        if (session.isAdminParty()) {
-          deferred.resolve();
-        } else if(session.matchesRoles(roles)) {
-          deferred.resolve();
-        } else {
-          deferred.reject();
-        }
-      });
+      if (session.isAdminParty()) {
+        deferred.resolve();
+      } else if(session.matchesRoles(roles)) {
+        deferred.resolve();
+      } else {
+        deferred.reject();
+      }
 
-      return [sessionDeferred, deferred];
+      return [deferred];
     };
 
     var authDenied = function () {

http://git-wip-us.apache.org/repos/asf/couchdb/blob/3ebf2992/src/fauxton/app/addons/auth/resources.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/auth/resources.js b/src/fauxton/app/addons/auth/resources.js
index 92cff91..ad7c529 100644
--- a/src/fauxton/app/addons/auth/resources.js
+++ b/src/fauxton/app/addons/auth/resources.js
@@ -46,7 +46,7 @@ function (app, FauxtonAPI) {
     }
   });
 
-  Auth.Session = Backbone.Model.extend({
+  Auth.Session = FauxtonAPI.Session.extend({
     url: '/_session',
 
     isAdminParty: function () {
@@ -59,17 +59,6 @@ function (app, FauxtonAPI) {
       return false;
     },
 
-    user: function () {
-      var userCtx = this.get('userCtx');
-
-      if (!userCtx || !userCtx.name) { return null; }
-
-      return {
-        name: userCtx.name,
-        roles: userCtx.roles
-      };
-    },
-
     userRoles: function () {
       var user = this.user();
 
@@ -94,19 +83,9 @@ function (app, FauxtonAPI) {
       return false;
     },
 
-    fetchOnce: function (opt) {
-      var options = _.extend({}, opt);
-
-      if (!this._deferred || this._deferred.isRejected() || options.forceFetch ) {
-        this._deferred = this.fetch();
-      }
-
-      return this._deferred;
-    },
-
     validateUser: function (username, password, msg) {
       if (_.isEmpty(username) || _.isEmpty(password)) {
-        var deferred = $.Deferred();
+        var deferred = FauxtonAPI.Deferred();
 
         deferred.rejectWith(this, [msg]);
         return deferred;
@@ -115,7 +94,7 @@ function (app, FauxtonAPI) {
 
     validatePasswords: function (password, password_confirm, msg) {
       if (_.isEmpty(password) || _.isEmpty(password_confirm) || (password !== password_confirm))
{
-        var deferred = $.Deferred();
+        var deferred = FauxtonAPI.Deferred();
 
         deferred.rejectWith(this, [msg]);
         return deferred;
@@ -124,7 +103,7 @@ function (app, FauxtonAPI) {
     },
 
     createAdmin: function (username, password, login) {
-      var self = this,
+      var that = this,
           error_promise =  this.validateUser(username, password, 'Authname or password cannot
be blank.');
 
       if (error_promise) { return error_promise; }
@@ -136,9 +115,9 @@ function (app, FauxtonAPI) {
 
       return admin.save().then(function () {
         if (login) {
-          return self.login(username, password);
+          return that.login(username, password);
         } else {
-         return self.fetchOnce({forceFetch: true});
+         return that.fetchUser({forceFetch: true});
         }
       });
     },
@@ -148,7 +127,7 @@ function (app, FauxtonAPI) {
 
       if (error_promise) { return error_promise; }
 
-      var self = this;
+      var that = this;
 
       return $.ajax({
         type: "POST", 
@@ -156,12 +135,12 @@ function (app, FauxtonAPI) {
         dataType: "json",
         data: {name: username, password: password}
       }).then(function () {
-         return self.fetchOnce({forceFetch: true});
+         return that.fetchUser({forceFetch: true});
       });
     },
 
     logout: function () {
-      var self = this;
+      var that = this;
 
       return $.ajax({
         type: "DELETE", 
@@ -170,7 +149,7 @@ function (app, FauxtonAPI) {
         username : "_", 
         password : "_"
       }).then(function () {
-       return self.fetchOnce({forceFetch: true });
+       return that.fetchUser({forceFetch: true });
       });
     },
 
@@ -179,7 +158,7 @@ function (app, FauxtonAPI) {
 
       if (error_promise) { return error_promise; }
 
-      var  self = this,
+      var  that = this,
            info = this.get('info'),
            userCtx = this.get('userCtx');
 
@@ -189,7 +168,7 @@ function (app, FauxtonAPI) {
       });
 
       return admin.save().then(function () {
-        return self.login(userCtx.name, password);
+        return that.login(userCtx.name, password);
       });
     }
   });
@@ -205,6 +184,8 @@ function (app, FauxtonAPI) {
 
     hide_modal: function () {
       this.$('.modal').modal('hide');
+      // force this removal as the navbar
+      //$('.modal-backdrop').remove();
     },
 
     set_error_msg: function (msg) {
@@ -239,19 +220,19 @@ function (app, FauxtonAPI) {
       event.preventDefault();
       this.clear_error_msg();
 
-      var self = this,
+      var that = this,
       username = this.$('#username').val(),
       password = this.$('#password').val();
 
       var promise = this.model.createAdmin(username, password, this.login_after);
 
       promise.then(function () {
-        self.$('.modal').modal('hide');
-        self.hide_modal();
+        that.$('.modal').modal('hide');
+        that.hide_modal();
       });
 
       promise.fail(function (rsp) {
-        self.set_error_msg(rsp);
+        that.set_error_msg(rsp);
       });
     }
 
@@ -268,18 +249,17 @@ function (app, FauxtonAPI) {
       event.preventDefault();
       this.clear_error_msg();
 
-      var self = this,
-      username = this.$('#username').val(),
-      password = this.$('#password').val();
-
-      var promise = this.model.login(username, password);
+      var that = this,
+          username = this.$('#username').val(),
+          password = this.$('#password').val(),
+          promise = this.model.login(username, password);
 
-      promise.done(function () {
-        self.hide_modal();
+      promise.then(function () {
+        that.hide_modal();
       });
 
       promise.fail(function (rsp) {
-        self.set_error_msg(rsp);
+        that.set_error_msg(rsp);
       });
     }
 
@@ -296,29 +276,35 @@ function (app, FauxtonAPI) {
       event.preventDefault();
       this.clear_error_msg();
 
-      var self = this,
+      var that = this,
           new_password = this.$('#password').val(),
           password_confirm = this.$('#password-confirm').val();
 
       var promise = this.model.changePassword(new_password, password_confirm);
 
       promise.done(function () {
-        self.hide_modal();
+        that.hide_modal();
       });
 
       promise.fail(function (rsp) {
-        self.set_error_msg(rsp);
+        that.set_error_msg(rsp);
       });
     }
   });
 
-  Auth.NavLink = FauxtonAPI.View.extend({
-    template: 'addons/auth/templates/nav_link',
-
-    tagName: "li",
-    className: "dropdown",
+  Auth.NavLinkTitle = FauxtonAPI.View.extend({ 
+    template: 'addons/auth/templates/nav_link_title',
+    tagName: 'a',
+    attributes: {
+      id: "user-drop",
+      "class": "dropdown-toggle",
+      role: "button",
+      "data-toggle": "dropdown",
+      href:"#"
+    },
 
-    initialize:function (options) {
+    beforeRender: function () {
+      this.listenTo(this.model, 'change', this.render);
     },
 
     serialize: function () {
@@ -326,8 +312,36 @@ function (app, FauxtonAPI) {
         admin_party: this.model.isAdminParty(),
         user: this.model.user()
       };
+    }
+  });
+
+  Auth.NavDropDown = FauxtonAPI.View.extend({ 
+    template: 'addons/auth/templates/nav_dropdown',
+    tagName: 'ul',
+    attributes: {
+      "class": "dropdown-menu",
+      role:"menu",
+      "aria-labelledby":"user-drop" 
+    },
+
+    beforeRender: function () {
+      this.listenTo(this.model, 'change', this.render);
     },
 
+    serialize: function () {
+      return {
+        admin_party: this.model.isAdminParty(),
+        user: this.model.user()
+      };
+    }
+  });
+
+  Auth.NavLink = FauxtonAPI.View.extend({
+    template: 'addons/auth/templates/nav_link',
+
+    tagName: "li",
+    className: "dropdown",
+
     events: {
       "click #user-create-admin": 'show_admin_modal',
       "click #user-create-more-admin": 'show_create_more_admin_modal',
@@ -337,7 +351,8 @@ function (app, FauxtonAPI) {
     },
 
     beforeRender: function () {
-      this.listenTo(this.model, 'change', this.render);
+      this.nav_link_name = this.insertView(new Auth.NavLinkTitle({model: this.model}));
+      this.nav_link_name = this.insertView(new Auth.NavDropDown({model: this.model}));
       this.create_admin_modal = this.setView('#user-create-admin-modal', new Auth.CreateAdminModal({model:
this.model}));
       this.login_modal = this.setView('#login-modal', new Auth.LoginModal({model: this.model}));
       this.change_password_modal = this.setView('#change-password-modal', new Auth.ChangePasswordModal({model:
this.model}));

http://git-wip-us.apache.org/repos/asf/couchdb/blob/3ebf2992/src/fauxton/app/addons/auth/templates/nav_dropdown.html
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/auth/templates/nav_dropdown.html b/src/fauxton/app/addons/auth/templates/nav_dropdown.html
new file mode 100644
index 0000000..5e07ca0
--- /dev/null
+++ b/src/fauxton/app/addons/auth/templates/nav_dropdown.html
@@ -0,0 +1,26 @@
+<!--
+Licensed under the Apache License, Version 2.0 (the "License"); you may not
+use this file except in compliance with the License. You may obtain a copy of
+the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+License for the specific language governing permissions and limitations under
+the License.
+-->
+
+<!-- dropdown menu links -->
+  <% if (admin_party) { %>
+  <li> <a id="user-create-admin" href="#"> Create Admin </a> </li>
+  <% } else if (user) { %>
+  <li> <a id="user-create-more-admin" href="#"> Create Admins </a> </li>
+  <li> <a id="user-change-password" href="#"> Change Password </a> </li>
+  <li> <a id="user-logout" href="#"> Logout </a> </li> 
+  <% } else { %>
+  <li> <a id="user-login" href="#"> Login </a> </li> 
+  <!--<li> <a id="user-sign-up"> Sign up </a> </li>-->
+  <% } %>
+

http://git-wip-us.apache.org/repos/asf/couchdb/blob/3ebf2992/src/fauxton/app/addons/auth/templates/nav_link.html
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/auth/templates/nav_link.html b/src/fauxton/app/addons/auth/templates/nav_link.html
index ba0a6f9..add5b89 100644
--- a/src/fauxton/app/addons/auth/templates/nav_link.html
+++ b/src/fauxton/app/addons/auth/templates/nav_link.html
@@ -12,30 +12,7 @@ License for the specific language governing permissions and limitations
under
 the License.
 -->
 
-<a id="user-drop" class="dropdown-toggle" role="button" data-toggle="dropdown" href="#">
-  <% if (admin_party) { %>
-  Admin Party!
-  <% } else if (user) { %>
-  <%= user.name %>
-  <% } else { %>
-  Login
-  <% } %>
-  <b class="caret"></b>
-</a>
-<ul class="dropdown-menu" role="menu" aria-labelledby="user-drop">
-  <!-- dropdown menu links -->
-  <% if (admin_party) { %>
-  <li> <a id="user-create-admin" href="#"> Create Admin </a> </li>
-  <% } else if (user) { %>
-  <li> <a id="user-create-more-admin" href="#"> Create Admins </a> </li>
-  <li> <a id="user-change-password" href="#"> Change Password </a> </li>
-  <li> <a id="user-logout" href="#"> Logout </a> </li> 
-  <% } else { %>
-  <li> <a id="user-login" href="#"> Login </a> </li> 
-  <!--<li> <a id="user-sign-up"> Sign up </a> </li>-->
-  <% } %>
-</ul>
-
+<div id="nav-link-title"> </div>
 <div id="user-create-admin-modal"> </div>
 <div id="login-modal"> </div>
 <div id="change-password-modal"> </div>

http://git-wip-us.apache.org/repos/asf/couchdb/blob/3ebf2992/src/fauxton/app/addons/auth/templates/nav_link_title.html
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/auth/templates/nav_link_title.html b/src/fauxton/app/addons/auth/templates/nav_link_title.html
new file mode 100644
index 0000000..90004f3
--- /dev/null
+++ b/src/fauxton/app/addons/auth/templates/nav_link_title.html
@@ -0,0 +1,24 @@
+<!--
+Licensed under the Apache License, Version 2.0 (the "License"); you may not
+use this file except in compliance with the License. You may obtain a copy of
+the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+License for the specific language governing permissions and limitations under
+the License.
+-->
+
+  <% if (admin_party) { %>
+  Admin Party!
+  <% } else if (user) { %>
+  <%= user.name %>
+  <% } else { %>
+  Login
+  <% } %>
+  <b class="caret"></b>
+
+

http://git-wip-us.apache.org/repos/asf/couchdb/blob/3ebf2992/src/fauxton/app/addons/logs/resources.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/logs/resources.js b/src/fauxton/app/addons/logs/resources.js
index 91a9bcb..bf7f657 100644
--- a/src/fauxton/app/addons/logs/resources.js
+++ b/src/fauxton/app/addons/logs/resources.js
@@ -131,7 +131,7 @@ function (app, FauxtonAPI, Backbone) {
     },
 
     createFilteredCollection: function () {
-      var self = this;
+      var that = this;
 
       var filtered = _.reduce(this.filters, function (logs, filter) {
 
@@ -158,14 +158,14 @@ function (app, FauxtonAPI, Backbone) {
     },
 
     startRefreshInterval: function () {
-      var self = this;
+      var that = this;
 
       // Interval already set
-      if (self.intervalId) { return ; }
+      if (that.intervalId) { return ; }
 
-      self.intervalId = setInterval(function () {
-        self.collection.fetch();
-      }, self.refreshTime);
+      that.intervalId = setInterval(function () {
+        that.collection.fetch();
+      }, that.refreshTime);
 
     },
 

http://git-wip-us.apache.org/repos/asf/couchdb/blob/3ebf2992/src/fauxton/app/api.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/api.js b/src/fauxton/app/api.js
index 9c4ecef..16202b7 100644
--- a/src/fauxton/app/api.js
+++ b/src/fauxton/app/api.js
@@ -49,7 +49,7 @@ function(app, Fauxton) {
       return !!this.__manager__.hasRendered;
     },
 
-    reRender: function () {
+    forceRender: function () {
       this.__manager__.hasRendered = false;
     }
   });
@@ -66,6 +66,10 @@ function(app, Fauxton) {
     return $.Deferred();
   };
 
+  FauxtonAPI.when = function (deferreds) {
+    return $.when.apply(null, deferreds);
+  },
+
   FauxtonAPI.addRoute = function(route) {
     app.router.route(route.route, route.name, route.callback);
   };
@@ -108,6 +112,59 @@ function(app, Fauxton) {
     }
   });
 
+  FauxtonAPI.Session = Backbone.Model.extend({
+    url: '/_session',
+    
+    user: function () {
+      var userCtx = this.get('userCtx');
+
+      if (!userCtx || !userCtx.name) { return null; }
+
+      return {
+        name: userCtx.name,
+        roles: userCtx.roles
+      };
+    },
+
+    fetchOnce: function (opt) {
+      var options = _.extend({}, opt);
+
+      if (!this._deferred || this._deferred.state() === "rejected" || options.forceFetch
) {
+        this._deferred = this.fetch();
+      }
+
+      return this._deferred;
+    },
+
+    fetchUser: function (opt) {
+      var that = this,
+          currentUser = this.user();
+
+      return this.fetchOnce(opt).then(function () {
+        var user = that.user();
+
+        // Notify anyone listening on these events that either a user has changed
+        // or current user is the same
+        if (currentUser !== user) {
+          that.trigger('session:userChanged');
+        } else {
+          that.trigger('session:userFetched');
+        }
+        
+        // this will return the user as a value to all function that calls done on this
+        // eg. session.fetchUser().done(user) { .. do something with user ..}
+        return user; 
+      });
+    }
+  });
+
+  FauxtonAPI.setSession = function (newSession) {
+    FauxtonAPI.session = newSession;
+    return FauxtonAPI.session.fetchUser();
+  };
+
+  FauxtonAPI.setSession(new FauxtonAPI.Session());
+
   // This is not exposed externally as it should not need to be accessed or overridden
   var Auth = function (options) {
     this._options = options;
@@ -121,18 +178,10 @@ function(app, Fauxton) {
     authDeniedCb: function() {},
 
     initialize: function() {
-      var self = this;
-
-      $(document).ajaxError(function(event, jqxhr, settings, exception) {
-        console.log("UNAUTH");
-        console.log(arguments);
-        if (exception === "Unauthorized" || exception === "Forbidden") {
-          self.authDeniedCb();
-        }
-      });
+      var that = this;
     },
 
-    authHandlerCb : function (roles, layout) {
+    authHandlerCb : function (roles) {
       var deferred = $.Deferred();
       deferred.resolve();
       return deferred;
@@ -148,12 +197,12 @@ function(app, Fauxton) {
 
     checkAccess: function (roles) {
       var requiredRoles = roles || [],
-          authDeniedCb = this.authDeniedCb,
-          promise = $.when.apply(null, this.authHandlerCb(requiredRoles));
-
-      promise.fail(function () { authDeniedCb();});
+          that = this;
 
-      return promise;
+      return FauxtonAPI.session.fetchUser().then(function (user) {
+        console.log('check', user);
+       return FauxtonAPI.when(that.authHandlerCb(FauxtonAPI.session, requiredRoles));
+      });
     }
   });
 
@@ -170,14 +219,13 @@ function(app, Fauxton) {
   // Piggy-back on Backbone's self-propagating extend function
   FauxtonAPI.RouteObject.extend = Backbone.Model.extend;
 
-  var routeObjectOptions = ["views", "routes", "events", "data", "crumbs", "layout", "apiUrl",
"establish"];
+  var routeObjectOptions = ["views", "routes", "events", "roles", "crumbs", "layout", "apiUrl",
"establish"];
 
   _.extend(FauxtonAPI.RouteObject.prototype, Backbone.Events, {
     // Should these be default vals or empty funcs?
     views: {},
     routes: {},
     events: {},
-    data: {},
     crumbs: [],
     layout: "with_sidebar",
     apiUrl: null,
@@ -188,18 +236,10 @@ function(app, Fauxton) {
     initialize: function() {}
   }, {
 
-    // TODO:: combine this and the renderWith function
-    // All the things should go through establish, as it will resolve
-    // immediately if its already done, but this way the RouteObject.route
-    // function can rebuild the deferred as needed
-    render: function(route, masterLayout, args) {
-      this.renderWith.apply(this, Array.prototype.slice.call(arguments));
-    },
-
     renderWith: function(route, masterLayout, args) {
       var routeObject = this;
 
-      // Can look at replacing this with events eg beforeRender, afterRender
+      // TODO: Can look at replacing this with events eg beforeRender, afterRender function
and events
       this.route.call(this, route, args);
 
       // Only want to redo the template if its a full render
@@ -216,14 +256,13 @@ function(app, Fauxton) {
         }));
       }
 
-      $.when.apply(this, this.establish()).done(function(resp) {
+      FauxtonAPI.when(this.establish()).done(function(resp) {
         _.each(routeObject.getViews(), function(view, selector) {
           if(view.hasRendered()) { return; }
 
           masterLayout.setView(selector, view);
-          console.log('SET SELECTOR AND RENDER ', selector, view); 
 
-          $.when.apply(null, view.establish()).then(function(resp) {
+          FauxtonAPI.when(view.establish()).then(function(resp) {
             masterLayout.renderView(selector);
           }, function(resp) {
             view.establishError = {
@@ -284,29 +323,29 @@ function(app, Fauxton) {
       return this.views;
     },
 
-    // Could move getRouteUrls into the Constructor function and so it defines the urls
-    // only once. This would give us a small speed up.
     getRouteUrls: function () {
       return _.keys(this.get('routes'));
     },
 
     hasRoute: function (route) {
-      if (this.getRouteUrls().indexOf(route) > -1) {
+      if (this.get('routes')[route]) {
         return true;
       }
-
       return false;
     },
 
-    routeCallback: function (route) {
-      var routes = this.get('routes');
-      var routeObj = routes[route];
+    routeCallback: function (route, args) {
+      var routes = this.get('routes'),
+          routeObj = routes[route],
+          routeCallback;
 
       if (typeof routeObj === 'object') {
-        return this[routeObj.route];
+        routeCallback = this[routeObj.route];
       } else {
-        return this[routeObj];
+        routeCallback = this[routeObj];
       }
+
+      routeCallback.apply(this, args);
     },
 
     getRouteRoles: function (routeUrl) {

http://git-wip-us.apache.org/repos/asf/couchdb/blob/3ebf2992/src/fauxton/app/modules/databases/routes.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/modules/databases/routes.js b/src/fauxton/app/modules/databases/routes.js
index 104d876..7b45413 100644
--- a/src/fauxton/app/modules/databases/routes.js
+++ b/src/fauxton/app/modules/databases/routes.js
@@ -65,7 +65,7 @@ function(app, FauxtonAPI, Databases, Views) {
       var deferred = this.deferred;
 
       databases.fetch().done(function(resp) {
-        $.when.apply(null, databases.map(function(database) {
+        FauxtonAPI.when(databases.map(function(database) {
           return database.status.fetch();
         })).done(function(resp) {
           deferred.resolve();

http://git-wip-us.apache.org/repos/asf/couchdb/blob/3ebf2992/src/fauxton/app/modules/fauxton/base.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/modules/fauxton/base.js b/src/fauxton/app/modules/fauxton/base.js
index 7e8f791..af9d122 100644
--- a/src/fauxton/app/modules/fauxton/base.js
+++ b/src/fauxton/app/modules/fauxton/base.js
@@ -11,7 +11,7 @@
 // the License.
 
 define([
-  "app",
+       "app",
        // Libs
        "backbone"
 
@@ -75,15 +75,15 @@ function(app, Backbone) {
     },
 
     addLinkViews: function () {
-      var self = this;
+      var that = this;
 
       _.each(this.navLinks, function (link) {
         if (!link.view) { return; }
 
         //TODO check if establish is a function
         var establish = link.establish || [];
-        $.when.apply(null, establish).done( function () {
-          self.insertView('#nav-links', link.view).render();
+        $.when.apply(null, establish).then( function () {
+          that.insertView('#nav-links', link.view).render();
         });
       }, this);
     }

http://git-wip-us.apache.org/repos/asf/couchdb/blob/3ebf2992/src/fauxton/app/router.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/router.js b/src/fauxton/app/router.js
index 4a79ff1..4c413d1 100644
--- a/src/fauxton/app/router.js
+++ b/src/fauxton/app/router.js
@@ -51,7 +51,7 @@ function(req, app, Initialize, FauxtonAPI, Fauxton, Layout, Databases, Documents
     routes: {},
 
     addModuleRouteObject: function(RouteObject) {
-      var self = this;
+      var that = this; //change that to that
       var masterLayout = this.masterLayout,
           routeUrls = RouteObject.prototype.getRouteUrls();
 
@@ -59,21 +59,24 @@ function(req, app, Initialize, FauxtonAPI, Fauxton, Layout, Databases,
Documents
         this.route(route, route.toString(), function() {
           var args = Array.prototype.slice.call(arguments);
 
-          if (!self.activeRouteObject || !self.activeRouteObject.hasRoute(route)) {
-            self.activeRouteObject = new RouteObject(args);
+          if (!that.activeRouteObject || !that.activeRouteObject.hasRoute(route)) {
+            that.activeRouteObject = new RouteObject(args);
           }
 
-          var routeObject = self.activeRouteObject,
-              routeCallback = routeObject.routeCallback(route),
+          var routeObject = that.activeRouteObject,
               roles = routeObject.getRouteRoles(route);
 
-          var authPromise = app.auth.checkAccess(roles);
+          var authPromise = app.auth.checkAccess(roles); // TODO add a get session
 
-          authPromise.then(function () {
-            routeCallback.apply(routeObject, args);
-            routeObject.render(route, masterLayout, args);
+          authPromise.done(function () {
+            routeObject.routeCallback(route, args);
+            routeObject.renderWith(route, masterLayout, args);
           });
 
+          authPromise.fail(function () { 
+            FauxtonAPI.auth.authDeniedCb();
+         });
+
         });
       }, this);
     },
@@ -133,7 +136,6 @@ function(req, app, Initialize, FauxtonAPI, Fauxton, Layout, Databases,
Documents
     triggerRouteEvent: function(event, args) {
       if (this.activeRouteObject) {
         var eventArgs = [event].concat(args);
-        console.log("CALLING ROUTE EVENT ON", this.activeRouteObject, arguments);
         this.activeRouteObject.trigger.apply(this.activeRouteObject, eventArgs );
         this.activeRouteObject.renderWith(eventArgs, this.masterLayout, args);
       }


Mime
View raw message