refactor sever-url set into its own route and always check on load

This commit is contained in:
Westly Wright 2018-03-23 15:20:06 -07:00
parent ccb3923993
commit 6d9cc84a33
No known key found for this signature in database
GPG Key ID: 4FAB3D8673DC54A3
10 changed files with 138 additions and 95 deletions

View File

@ -23,7 +23,8 @@ const App = Application.extend({
externalRoutes: { externalRoutes: {
index: 'index', index: 'index',
authenticated: 'authenticated', authenticated: 'authenticated',
'update-password': 'update-password' 'update-password': 'update-password',
'update-critical-settings': 'update-critical-settings'
} }
} }
}, },
@ -64,7 +65,7 @@ const App = Application.extend({
} }
} }
}, },
logging: { logging: {
dependencies: { dependencies: {
services: [ services: [
'app', 'app',

View File

@ -34,9 +34,17 @@ export default Route.extend(Preload, {
}, CHECK_AUTH_TIMER)); }, CHECK_AUTH_TIMER));
return this.testAuthToken().then(() => { return this.testAuthToken().then(() => {
if (get(this, 'access.mustChangePassword')) { if (get(this, 'access.mustChangePassword')) {
this.transitionTo('update-password'); this.transitionTo('update-password');
} }
return this.loadPublicSettings().then(() => {
if (get(this, 'settings.serverUrlIsEmpty')) {
get(this, 'router').transitionTo('update-critical-settings');
}
});
}); });
}, },
@ -58,7 +66,7 @@ export default Route.extend(Preload, {
this.loadClusters(), this.loadClusters(),
this.loadProjects(), this.loadProjects(),
this.loadPreferences(), this.loadPreferences(),
this.loadPublicSettings(), // this.loadPublicSettings(),
]; ];
const globalStore = get(this, 'globalStore'); const globalStore = get(this, 'globalStore');

View File

@ -33,6 +33,7 @@ Router.map(function() {
this.route('verify-auth'); this.route('verify-auth');
this.route('update-password', {path: '/update-password'}); this.route('update-password', {path: '/update-password'});
this.route('update-critical-settings', {path: '/update-setting'});
this.route('authenticated', {path: '/'}, function() { this.route('authenticated', {path: '/'}, function() {
// Global // Global

View File

@ -0,0 +1,7 @@
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { get } from '@ember/object';
import C from 'ui/utils/constants';
export default Controller.extend({
});

View File

@ -0,0 +1,29 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { get } from '@ember/object';
import C from 'ui/utils/constants';
export default Route.extend({
access: service(),
settings: service(),
globalStore: service(),
activate() {
$('BODY').addClass('container-farm');
},
deactivate() {
$('BODY').removeClass('container-farm');
},
model: function() {
let globalStore = get(this, 'globalStore');
return globalStore.find('setting', C.SETTING.SERVER_URL).then((serverUrl) => {
return {
serverUrl: get(serverUrl, 'value') || window.location.host,
serverUrlSetting: serverUrl,
};
});
},
});

View File

@ -0,0 +1,6 @@
<div class="login">
{{settings/server-url
serverUrlSetting=model.serverUrlSetting
serverUrl=model.serverUrl
}}
</div>

View File

@ -23,7 +23,8 @@ const Eng = Engine.extend({
externalRoutes: [ externalRoutes: [
'index', 'index',
'authenticated', 'authenticated',
'update-password' 'update-password',
'update-critical-settings',
] ]
} }
}); });

View File

@ -6,6 +6,7 @@ import { inject as service } from '@ember/service';
import Controller from '@ember/controller'; import Controller from '@ember/controller';
import { on } from '@ember/object/evented'; import { on } from '@ember/object/evented';
import C from 'ui/utils/constants'; import C from 'ui/utils/constants';
import { isEmpty } from '@ember/utils';
const USER_PASS_PROVIDERS = ['local','activedirectory']; const USER_PASS_PROVIDERS = ['local','activedirectory'];
@ -60,28 +61,17 @@ export default Controller.extend({
isCaas: computed('app.mode', function() { isCaas: computed('app.mode', function() {
return get(this, 'app.mode') === 'caas' ? true : false; return get(this, 'app.mode') === 'caas' ? true : false;
}), }),
setServerUrl: false,
serverUrlSetting: null,
shouldSetServerUrl() { shouldSetServerUrl() {
// setting isn't loaded yet
let globalStore = get(this, 'globalStore'); let globalStore = get(this, 'globalStore');
return globalStore.find('setting', C.SETTING.SERVER_URL).then((serverUrl) => { return globalStore.find('setting', C.SETTING.SERVER_URL).then((serverUrl) => {
if (serverUrl && get(serverUrl, 'value') === "" && get(serverUrl, 'links.update')) { if (serverUrl && isEmpty(get(serverUrl, 'value')) && get(serverUrl, 'links.update')) {
setProperties(this, {
user: null,
code: null,
serverUrl: window.location.host,
setServerUrl: true,
serverUrlSetting: serverUrl,
});
return false; return false;
} }
return true; return true;
}).catch((err)=> {
return err;
}); });
}, },
@ -99,8 +89,10 @@ export default Controller.extend({
this.shouldSetServerUrl().then((proceed) => { this.shouldSetServerUrl().then((proceed) => {
if (proceed) { if (proceed) {
this.send('finishComplete'); this.send('finishComplete');
} else {
get(this, 'router').transitionTo('update-critical-settings');
} }
}) });
} }
}, },
@ -114,7 +106,7 @@ export default Controller.extend({
later(() => { later(() => {
get(this, 'access').login(provider, code).then((user) => { get(this, 'access').login(provider, code).then((user) => {
if ( user.mustChangePassword && provider === 'local' ) { if ( get(user, 'mustChangePassword') && provider === 'local' ) {
get(this,'session').set(C.SESSION.BACK_TO, window.location.origin); get(this,'session').set(C.SESSION.BACK_TO, window.location.origin);
get(this, 'router').transitionTo('update-password'); get(this, 'router').transitionTo('update-password');
} else { } else {
@ -123,7 +115,6 @@ export default Controller.extend({
code: null, code: null,
}); });
this.send('complete', true); this.send('complete', true);
// this.send('finishLogin');
} }
}).catch((err) => { }).catch((err) => {
set(this, 'waiting', false); set(this, 'waiting', false);

View File

@ -1,68 +1,61 @@
<div class="login"> <div class="login">
{{#if setServerUrl}} <h1>
{{settings/server-url {{t 'loginPage.greeting' appName=settings.appName htmlSafe=true}}
serverUrlSetting=serverUrlSetting <div class="logo"></div>
serverUrl=serverUrl </h1>
}} <section class="pb-0">
{{else}} {{language-dropdown login=true class='mb-10'}}
<h1> <br/>
{{t 'loginPage.greeting' appName=settings.appName htmlSafe=true}} {{#unless promptPasswordReset}}
<div class="logo"></div> {{#if isGithub}}
</h1> {{login-github action="started"}}
<section class="pb-0"> {{/if}}
{{language-dropdown login=true class='mb-10'}}
<br/>
{{#unless promptPasswordReset}}
{{#if isGithub}}
{{login-github action="started"}}
{{/if}}
{{#if isShibboleth}} {{#if isShibboleth}}
<p>{{t 'loginPage.shibbolethMessage' appName=settings.appName}}</p> <p>{{t 'loginPage.shibbolethMessage' appName=settings.appName}}</p>
<br/> <br/>
{{login-shibboleth {{login-shibboleth
action="started" action="started"
waiting=waiting waiting=waiting
}} }}
{{/if}} {{/if}}
{{#if isCaas}} {{#if isCaas}}
{{caas-login promptReset=(mut promptPasswordReset)}} {{caas-login promptReset=(mut promptPasswordReset)}}
{{/if}} {{/if}}
{{#if isActiveDirectory}} {{#if isActiveDirectory}}
{{login-user-pass {{login-user-pass
classNames="row" classNames="row"
action="authenticate" action="authenticate"
waiting=waiting waiting=waiting
provider="activedirectory" provider="activedirectory"
}} }}
{{/if}} {{/if}}
{{#if isLocal}} {{#if isLocal}}
{{login-user-pass {{login-user-pass
classNames="row" classNames="row"
action="authenticate" action="authenticate"
waiting=waiting waiting=waiting
shown=onlyLocal shown=onlyLocal
provider="local" provider="local"
}} }}
{{/if}}
{{#if infoMsg}}
<div class="banner p-10 {{if errorMsg 'bg-error' 'bg-warning'}}" role="alert">
{{infoMsg}}
</div>
{{/if}}
{{/unless}}
{{#if app.initError}}
{{banner-message color='bg-error' icon='icon-alert' message=app.initError.message}}
<button class="btn bg-primary" {{action "reload"}}>
<i class="icon icon-refresh text-small"/> Reload
</button>
{{/if}} {{/if}}
</section>
{{/if}} {{#if infoMsg}}
<div class="banner p-10 {{if errorMsg 'bg-error' 'bg-warning'}}" role="alert">
{{infoMsg}}
</div>
{{/if}}
{{/unless}}
{{#if app.initError}}
{{banner-message color='bg-error' icon='icon-alert' message=app.initError.message}}
<button class="btn bg-primary" {{action "reload"}}>
<i class="icon icon-refresh text-small"/> Reload
</button>
{{/if}}
</section>
</div> </div>

View File

@ -5,6 +5,8 @@ import Evented from '@ember/object/evented';
import Service, { inject as service } from '@ember/service'; import Service, { inject as service } from '@ember/service';
import C from 'shared/utils/constants'; import C from 'shared/utils/constants';
import { minorVersion } from 'shared/utils/parse-version'; import { minorVersion } from 'shared/utils/parse-version';
import { get, set, computed } from '@ember/object';
import { isEmpty } from '@ember/utils';
export function normalizeName(str) { export function normalizeName(str) {
return str; //.replace(/\./g, C.SETTING.DOT_CHAR).toLowerCase(); return str; //.replace(/\./g, C.SETTING.DOT_CHAR).toLowerCase();
@ -27,7 +29,7 @@ export default Service.extend(Evented, {
init() { init() {
this._super(); this._super();
this.set('all', this.get('globalStore').all('setting')); set(this, 'all', get(this, 'globalStore').all('setting'));
}, },
unknownProperty(key) { unknownProperty(key) {
@ -64,7 +66,7 @@ export default Service.extend(Evented, {
if ( !obj ) if ( !obj )
{ {
obj = this.get('globalStore').createRecord({ obj = get(this, 'globalStore').createRecord({
type: 'setting', type: 'setting',
name: denormalizeName(key), name: denormalizeName(key),
}); });
@ -87,17 +89,17 @@ export default Service.extend(Evented, {
promiseCountObserver: function() { promiseCountObserver: function() {
if (this.get('promiseCount') <= 0) { if (get(this, 'promiseCount') <= 0) {
this.trigger('settingsPromisesResolved'); this.trigger('settingsPromisesResolved');
} }
}.observes('promiseCount'), }.observes('promiseCount'),
findByName(name) { findByName(name) {
return this.get('asMap')[normalizeName(name)]; return get(this, 'asMap')[normalizeName(name)];
}, },
loadAll() { loadAll() {
return this.get('globalStore').find('setting'); return get(this, 'globalStore').find('setting');
}, },
load(names) { load(names) {
@ -110,7 +112,7 @@ export default Service.extend(Evented, {
names = [names]; names = [names];
} }
var globalStore = this.get('globalStore'); var globalStore = get(this, 'globalStore');
var promise = new EmberPromise((resolve, reject) => { var promise = new EmberPromise((resolve, reject) => {
async.eachLimit(names, 3, function(name, cb) { async.eachLimit(names, 3, function(name, cb) {
@ -132,7 +134,7 @@ export default Service.extend(Evented, {
asMap: function() { asMap: function() {
var out = {}; var out = {};
(this.get('all')||[]).forEach((setting) => { (get(this, 'all')||[]).forEach((setting) => {
var name = normalizeName(setting.get('name')); var name = normalizeName(setting.get('name'));
out[name] = setting; out[name] = setting;
}); });
@ -141,25 +143,25 @@ export default Service.extend(Evented, {
}.property('all.@each.{name,value}'), }.property('all.@each.{name,value}'),
uiVersion: function() { uiVersion: function() {
return 'v' + this.get('app.version'); return 'v' + get(this, 'app.version');
}.property('app.version'), }.property('app.version'),
issueUrl: function() { issueUrl: function() {
var str = '*Describe your issue here*\n\n\n---\n| Useful | Info |\n| :-- | :-- |\n' + var str = '*Describe your issue here*\n\n\n---\n| Useful | Info |\n| :-- | :-- |\n' +
`|Versions|Rancher \`${this.get('rancherVersion')||'-'}\` ` + `|Versions|Rancher \`${get(this, 'rancherVersion')||'-'}\` ` +
`UI: \`${this.get('uiVersion')||'--'}\` |\n`; `UI: \`${get(this, 'uiVersion')||'--'}\` |\n`;
if ( this.get('access.enabled') ) if ( get(this, 'access.enabled') )
{ {
let provider = (this.get('access.provider')||'').replace(/config/,''); let provider = (get(this, 'access.provider')||'').replace(/config/,'');
str += `|Access|\`${provider}\` ${this.get('access.admin') ? '\`admin\`' : ''}|\n`; str += `|Access|\`${provider}\` ${get(this, 'access.admin') ? '\`admin\`' : ''}|\n`;
} }
else else
{ {
str += '|Access|`Disabled`|\n'; str += '|Access|`Disabled`|\n';
} }
str += `|Route|\`${this.get('app.currentRouteName')}\`|\n`; str += `|Route|\`${get(this, 'app.currentRouteName')}\`|\n`;
var url = C.EXT_REFERENCES.GITHUB + '/issues/new?body=' + encodeURIComponent(str); var url = C.EXT_REFERENCES.GITHUB + '/issues/new?body=' + encodeURIComponent(str);
return url; return url;
@ -170,36 +172,40 @@ export default Service.extend(Evented, {
cliVersion: alias(`asMap.${C.SETTING.VERSION_CLI}.value`), cliVersion: alias(`asMap.${C.SETTING.VERSION_CLI}.value`),
dockerMachineVersion: alias(`asMap.${C.SETTING.VERSION_MACHINE}.value`), dockerMachineVersion: alias(`asMap.${C.SETTING.VERSION_MACHINE}.value`),
helmVersion: alias(`asMap.${C.SETTING.VERSION_HELM}.value`), helmVersion: alias(`asMap.${C.SETTING.VERSION_HELM}.value`),
serverUrl: alias(`asMap.${C.SETTING.SERVER_URL}.value`),
serverUrlIsEmpty: computed('serverUrl', function() {
return isEmpty(get(this, 'serverUrl'));
}),
_plValue: function() { _plValue: function() {
let TRUE=true; // @TODO-2.0 let TRUE=true; // @TODO-2.0
if ( TRUE ) { if ( TRUE ) {
return 'rancher'; return 'rancher';
} }
return this.get(`cookies.${C.COOKIE.PL}`) || ''; return get(this, `cookies.${C.COOKIE.PL}`) || '';
}.property(`cookies.${C.COOKIE.PL}`), }.property(`cookies.${C.COOKIE.PL}`),
isRancher: function() { isRancher: function() {
return this.get('_plValue').toUpperCase() === C.COOKIE.PL_RANCHER_VALUE.toUpperCase(); return get(this, '_plValue').toUpperCase() === C.COOKIE.PL_RANCHER_VALUE.toUpperCase();
}.property('_plValue'), }.property('_plValue'),
isEnterprise: function() { isEnterprise: function() {
return this.get('rancherImage') === 'rancher/enterprise'; return get(this, 'rancherImage') === 'rancher/enterprise';
}.property('rancherImage'), }.property('rancherImage'),
appName: function() { appName: function() {
var isCaas = this.get('app.mode') === 'caas' ? true : false; var isCaas = get(this, 'app.mode') === 'caas' ? true : false;
if (isCaas) { if (isCaas) {
return 'Rancher Container Cloud'; return 'Rancher Container Cloud';
} else { } else {
if ( this.get('isRancher') ) if ( get(this, 'isRancher') )
{ {
return this.get('app.appName') || "Rancher"; // Rancher return get(this, 'app.appName') || "Rancher"; // Rancher
} }
else else
{ {
return this.get('_plValue'); return get(this, '_plValue');
} }
} }
}.property('isRancher','_plValue'), }.property('isRancher','_plValue'),
@ -207,7 +213,7 @@ export default Service.extend(Evented, {
minDockerVersion: alias(`asMap.${C.SETTING.MIN_DOCKER}.value`), minDockerVersion: alias(`asMap.${C.SETTING.MIN_DOCKER}.value`),
minorVersion: function() { minorVersion: function() {
let version = this.get('rancherVersion'); let version = get(this, 'rancherVersion');
if ( !version ) if ( !version )
{ {
return null; return null;
@ -217,15 +223,15 @@ export default Service.extend(Evented, {
}.property('rancherVersion'), }.property('rancherVersion'),
docsBase: function() { docsBase: function() {
let full = this.get('rancherVersion'); let full = get(this, 'rancherVersion');
let version; let version;
if ( full ) { if ( full ) {
version = minorVersion(full); version = minorVersion(full);
} else { } else {
version = minorVersion(this.get('uiVersion')); version = minorVersion(get(this, 'uiVersion'));
} }
let lang = ((this.get('intl.locale')||[])[0]||'').replace(/-.*$/,''); let lang = ((get(this, 'intl.locale')||[])[0]||'').replace(/-.*$/,'');
if ( !lang || lang === 'none' || C.LANGUAGE.DOCS.indexOf(lang) === -1 ) { if ( !lang || lang === 'none' || C.LANGUAGE.DOCS.indexOf(lang) === -1 ) {
lang = 'en'; lang = 'en';
} }