Fix issues with no active projects

This commit is contained in:
Vincent Fiduccia 2015-04-23 12:16:58 -07:00
parent 7300aa3aac
commit df55ffa92c
6 changed files with 102 additions and 49 deletions

View File

@ -11,6 +11,7 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {
model: function(params, transition) { model: function(params, transition) {
var store = this.get('store'); var store = this.get('store');
var session = this.get('session'); var session = this.get('session');
var isAuthEnabled = this.get('app.authenticationEnabled');
// Load schemas // Load schemas
var headers = {}; var headers = {};
@ -23,12 +24,14 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {
} }
var type = session.get(C.SESSION.USER_TYPE); 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); this.set('app.isAuthenticationAdmin', isAdmin);
return store.find('project', null, {forceReload: true}); return store.find('project', null, {forceReload: true});
}).catch((err) => { }).catch((err) => {
if ( err.status === 401 ) if ( err.status === 401 )
{
if ( isAuthEnabled )
{ {
this.send('logout',transition,true); this.send('logout',transition,true);
} }
@ -36,6 +39,7 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {
{ {
this.send('error',err); this.send('error',err);
} }
}
}); });
}, },
@ -65,18 +69,55 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {
{ {
select(project); 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 else
{ {
// Then cry fail();
this.send('logout'); }
}).catch(() => {
fail();
});
}
else
{
fail();
} }
}); });
}); });
function select(project) { function select(project) {
if ( project )
{
session.set(C.SESSION.PROJECT, project.get('id')); session.set(C.SESSION.PROJECT, project.get('id'));
controller.set('project', project); 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');
}
}
}, },
activeProjectFromId: function(projectId) { activeProjectFromId: function(projectId) {

View File

@ -1,6 +1,8 @@
<div class="nav-background"></div> <div class="nav-background"></div>
<div {{bind-attr class=":aside-background asideColor hasAside::hide"}}></div> <div {{bind-attr class=":aside-background asideColor hasAside::hide"}}></div>
{{page-nav activeTab=activeTab}} {{#if project}}
{{page-nav activeTab=activeTab}}
{{/if}}
{{page-header {{page-header
pageName=pageName pageName=pageName
projects=projects projects=projects

View File

@ -61,6 +61,7 @@
</div> </div>
<div class="right" style="padding-right: 0;"> <div class="right" style="padding-right: 0;">
{{#if project}}
<div class="btn-group project-btn"> <div class="btn-group project-btn">
<button type="button" class="btn btn-link dropdown-toggle text-left clip" data-toggle="dropdown" aria-expanded="false"> <button type="button" class="btn btn-link dropdown-toggle text-left clip" data-toggle="dropdown" aria-expanded="false">
<div class="text-muted">Project:</div> <div class="text-muted">Project:</div>
@ -72,6 +73,7 @@
<span class="caret"></span> <span class="caret"></span>
</button> </button>
<ul class="dropdown-menu dropdown-menu-right" role="menu"> <ul class="dropdown-menu dropdown-menu-right" role="menu">
{{#if projectChoices.length}}
<li role="presentation" class="dropdown-header">Your Projects:</li> <li role="presentation" class="dropdown-header">Your Projects:</li>
{{#each p in projectChoices itemController="project"}} {{#each p in projectChoices itemController="project"}}
<li {{bind-attr class="p.active:disabled p.active:selected"}}> <li {{bind-attr class="p.active:disabled p.active:selected"}}>
@ -82,6 +84,7 @@
</a> </a>
</li> </li>
{{/each}} {{/each}}
{{/if}}
<li role="presentation" class="divider"></li> <li role="presentation" class="divider"></li>
{{#if projectIsMissing}} {{#if projectIsMissing}}
<li role="presentation" class="dropdown-header">Not Your Project:</li> <li role="presentation" class="dropdown-header">Not Your Project:</li>
@ -99,6 +102,7 @@
<li>{{#link-to "projects"}}Manage Projects{{/link-to}}</li> <li>{{#link-to "projects"}}Manage Projects{{/link-to}}</li>
</ul> </ul>
</div> </div>
{{/if}}
</div> </div>
<h3> <h3>

View File

@ -19,7 +19,9 @@ var ProjectController = Cattle.TransitioningResourceController.extend({
}, },
activate: function() { activate: function() {
return this.doAction('activate'); return this.doAction('activate').then(() => {
this.send('refreshProjectDropdown');
});
}, },
deactivate: function() { deactivate: function() {

View File

@ -2,4 +2,5 @@ import Cattle from "ui/utils/cattle";
export default Cattle.CollectionController.extend({ export default Cattle.CollectionController.extend({
itemController: 'project', itemController: 'project',
needs: ['authenticated'],
}); });

View File

@ -1,6 +1,9 @@
<section> <section>
<p>Rancher supports grouping resources into multiple <b>projects</b>. Each project gets its own set of hosts and other resources, and is owned by a single GitHub user, team or organization.</p> <p>Rancher supports grouping resources into multiple <b>projects</b>. Each project gets its own set of hosts and other resources, and is owned by a single GitHub user, team or organization.</p>
<p>For example, you might create separate &quot;dev&quot;, &quot;test&quot;, and &quot;production&quot; projects to keep logical environments isolated from each other, and give &quot;dev&quot; access to your entire organization but restrict the &quot;production&quot; project to a small team.</p> <p>For example, you might create separate &quot;dev&quot;, &quot;test&quot;, and &quot;production&quot; projects to keep logical environments isolated from each other, and give &quot;dev&quot; access to your entire organization but restrict the &quot;production&quot; project to a small team.</p>
{{#unless controllers.authenticated.project}}
<div class="alert alert-danger"><i class="ss-alert"></i> There are no active projects. You will need to create or activate one before you can do anything else.</div>
{{/unless}}
</section> </section>
<section class="grid-header"> <section class="grid-header">