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) {
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');
}
}
},

View File

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

View File

@ -61,44 +61,48 @@
</div>
<div class="right" style="padding-right: 0;">
<div class="btn-group project-btn">
<button type="button" class="btn btn-link dropdown-toggle text-left clip" data-toggle="dropdown" aria-expanded="false">
<div class="text-muted">Project:</div>
{{#if project}}
{{#with project as p controller="project"}}
<i {{bind-attr class=":fa-fw p.icon"}}></i>&nbsp;{{p.displayName}}
{{/with}}
{{/if}}
<span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right" role="menu">
<li role="presentation" class="dropdown-header">Your Projects:</li>
{{#each p in projectChoices itemController="project"}}
<li {{bind-attr class="p.active:disabled p.active:selected"}}>
<a {{action "switchProject" p.id}} class="clip">
<i {{bind-attr class=":fa-fw p.icon"}}></i>
&nbsp;
{{p.displayName}}
</a>
</li>
{{/each}}
<li role="presentation" class="divider"></li>
{{#if projectIsMissing}}
<li role="presentation" class="dropdown-header">Not Your Project:</li>
{{#with project as p controller="project"}}
<li {{bind-attr class="p.active:disabled p.active:selected"}}>
<a {{action "switchProject" p.id}} class="clip">
<i {{bind-attr class=":fa-fw p.icon"}}></i>
&nbsp;
{{p.displayName}}
</a>
</li>
{{/with}}
{{#if project}}
<div class="btn-group project-btn">
<button type="button" class="btn btn-link dropdown-toggle text-left clip" data-toggle="dropdown" aria-expanded="false">
<div class="text-muted">Project:</div>
{{#if project}}
{{#with project as p controller="project"}}
<i {{bind-attr class=":fa-fw p.icon"}}></i>&nbsp;{{p.displayName}}
{{/with}}
{{/if}}
<span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right" role="menu">
{{#if projectChoices.length}}
<li role="presentation" class="dropdown-header">Your Projects:</li>
{{#each p in projectChoices itemController="project"}}
<li {{bind-attr class="p.active:disabled p.active:selected"}}>
<a {{action "switchProject" p.id}} class="clip">
<i {{bind-attr class=":fa-fw p.icon"}}></i>
&nbsp;
{{p.displayName}}
</a>
</li>
{{/each}}
{{/if}}
<li role="presentation" class="divider"></li>
{{/if}}
<li>{{#link-to "projects"}}Manage Projects{{/link-to}}</li>
</ul>
</div>
{{#if projectIsMissing}}
<li role="presentation" class="dropdown-header">Not Your Project:</li>
{{#with project as p controller="project"}}
<li {{bind-attr class="p.active:disabled p.active:selected"}}>
<a {{action "switchProject" p.id}} class="clip">
<i {{bind-attr class=":fa-fw p.icon"}}></i>
&nbsp;
{{p.displayName}}
</a>
</li>
{{/with}}
<li role="presentation" class="divider"></li>
{{/if}}
<li>{{#link-to "projects"}}Manage Projects{{/link-to}}</li>
</ul>
</div>
{{/if}}
</div>
<h3>

View File

@ -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() {

View File

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

View File

@ -1,6 +1,9 @@
<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>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 class="grid-header">