From df55ffa92c34ce87f615a751a67e06e803ea4ce4 Mon Sep 17 00:00:00 2001 From: Vincent Fiduccia Date: Thu, 23 Apr 2015 12:16:58 -0700 Subject: [PATCH] Fix issues with no active projects --- app/authenticated/route.js | 61 +++++++++++++++---- app/authenticated/template.hbs | 4 +- app/components/page-header/template.hbs | 78 +++++++++++++------------ app/project/controller.js | 4 +- app/projects/index/controller.js | 1 + app/projects/index/template.hbs | 3 + 6 files changed, 102 insertions(+), 49 deletions(-) diff --git a/app/authenticated/route.js b/app/authenticated/route.js index da07579db..7eacb83bb 100644 --- a/app/authenticated/route.js +++ b/app/authenticated/route.js @@ -11,6 +11,7 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, { model: function(params, transition) { var store = this.get('store'); var session = this.get('session'); + var isAuthEnabled = this.get('app.authenticationEnabled'); // Load schemas var headers = {}; @@ -23,18 +24,21 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, { } var type = session.get(C.SESSION.USER_TYPE); - var isAdmin = (type === C.USER.TYPE_ADMIN) || (!this.get('app.authenticationEnabled')); + var isAdmin = (type === C.USER.TYPE_ADMIN) || !isAuthEnabled; this.set('app.isAuthenticationAdmin', isAdmin); return store.find('project', null, {forceReload: true}); }).catch((err) => { if ( err.status === 401 ) { - this.send('logout',transition,true); - } - else - { - this.send('error',err); + if ( isAuthEnabled ) + { + this.send('logout',transition,true); + } + else + { + this.send('error',err); + } } }); }, @@ -65,17 +69,54 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, { { select(project); } + else if ( this.get('app.isAuthenticationAdmin') ) + { + this.get('store').find('project', null, {filter: {all: 'true'}, forceReload: true}).then((all) => { + var firstActive = all.filterProperty('state','active')[0]; + if ( firstActive ) + { + select(firstActive); + } + else + { + fail(); + } + }).catch(() => { + fail(); + }); + } else { - // Then cry - this.send('logout'); + fail(); } }); }); function select(project) { - session.set(C.SESSION.PROJECT, project.get('id')); - controller.set('project', project); + if ( project ) + { + session.set(C.SESSION.PROJECT, project.get('id')); + controller.set('project', project); + } + else + { + session.set(C.SESSION.PROJECT, undefined); + controller.set('project', null); + } + } + + var self = this; + function fail() { + // Then cry + select(null); + if ( self.get('app.authenticationEnabled') && !self.get('app.isAuthenticationAdmin') ) + { + self.send('logout'); + } + else + { + self.transitionTo('projects'); + } } }, diff --git a/app/authenticated/template.hbs b/app/authenticated/template.hbs index 260ac867b..9851088c7 100644 --- a/app/authenticated/template.hbs +++ b/app/authenticated/template.hbs @@ -1,6 +1,8 @@
-{{page-nav activeTab=activeTab}} +{{#if project}} + {{page-nav activeTab=activeTab}} +{{/if}} {{page-header pageName=pageName projects=projects diff --git a/app/components/page-header/template.hbs b/app/components/page-header/template.hbs index 71912a302..aa65c756c 100644 --- a/app/components/page-header/template.hbs +++ b/app/components/page-header/template.hbs @@ -61,44 +61,48 @@
-
- - +
+ {{/if}}

diff --git a/app/project/controller.js b/app/project/controller.js index 2d5b002a0..d52280bf3 100644 --- a/app/project/controller.js +++ b/app/project/controller.js @@ -19,7 +19,9 @@ var ProjectController = Cattle.TransitioningResourceController.extend({ }, activate: function() { - return this.doAction('activate'); + return this.doAction('activate').then(() => { + this.send('refreshProjectDropdown'); + }); }, deactivate: function() { diff --git a/app/projects/index/controller.js b/app/projects/index/controller.js index f283cfbf4..7ec7334b5 100644 --- a/app/projects/index/controller.js +++ b/app/projects/index/controller.js @@ -2,4 +2,5 @@ import Cattle from "ui/utils/cattle"; export default Cattle.CollectionController.extend({ itemController: 'project', + needs: ['authenticated'], }); diff --git a/app/projects/index/template.hbs b/app/projects/index/template.hbs index abb5ad406..bc63a2a28 100644 --- a/app/projects/index/template.hbs +++ b/app/projects/index/template.hbs @@ -1,6 +1,9 @@

Rancher supports grouping resources into multiple projects. Each project gets its own set of hosts and other resources, and is owned by a single GitHub user, team or organization.

For example, you might create separate "dev", "test", and "production" projects to keep logical environments isolated from each other, and give "dev" access to your entire organization but restrict the "production" project to a small team.

+ {{#unless controllers.authenticated.project}} +
There are no active projects. You will need to create or activate one before you can do anything else.
+ {{/unless}}