mirror of https://github.com/rancher/ui.git
Refactor GH auth page
This commit is contained in:
parent
c753f75baa
commit
f99ed17f2b
|
|
@ -73,10 +73,11 @@ export default Mixin.create({
|
||||||
this.send('clearError');
|
this.send('clearError');
|
||||||
|
|
||||||
const model = get(this, 'authConfig');
|
const model = get(this, 'authConfig');
|
||||||
|
const accessMode = get(model, 'id') !== 'github' ? 'unrestricted' : 'restricted';
|
||||||
|
|
||||||
setProperties(model, {
|
setProperties(model, {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
accessMode: 'unrestricted',
|
accessMode: accessMode,
|
||||||
allowedPrincipalIds: []
|
allowedPrincipalIds: []
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,17 @@ import { alias } from '@ember/object/computed';
|
||||||
import { inject as service } from '@ember/service';
|
import { inject as service } from '@ember/service';
|
||||||
import Controller from '@ember/controller';
|
import Controller from '@ember/controller';
|
||||||
import C from 'ui/utils/constants';
|
import C from 'ui/utils/constants';
|
||||||
|
import AuthMixin from 'global-admin/mixins/authentication';
|
||||||
|
|
||||||
export default Controller.extend({
|
export default Controller.extend(AuthMixin,{
|
||||||
github: service(),
|
github: service(),
|
||||||
endpoint: service(),
|
endpoint: service(),
|
||||||
access: service(),
|
access: service(),
|
||||||
settings: service(),
|
settings: service(),
|
||||||
|
|
||||||
|
authConfig: alias('model.githubConfig'),
|
||||||
|
scheme: alias('authConfig.scheme'),
|
||||||
|
|
||||||
confirmDisable: false,
|
confirmDisable: false,
|
||||||
errors: null,
|
errors: null,
|
||||||
testing: false,
|
testing: false,
|
||||||
|
|
@ -106,105 +111,27 @@ export default Controller.extend({
|
||||||
this.send('clearError');
|
this.send('clearError');
|
||||||
set(this, 'saving', true);
|
set(this, 'saving', true);
|
||||||
|
|
||||||
const githubConfig = get(this, 'githubConfig');
|
const authConfig = get(this, 'authConfig');
|
||||||
const am = get(githubConfig, 'accessMode') || 'restricted';
|
const am = get(authConfig, 'accessMode') || 'restricted';
|
||||||
|
|
||||||
githubConfig.setProperties({
|
authConfig.setProperties({
|
||||||
'clientId': (githubConfig.get('clientId') || '').trim(),
|
'clientId': (authConfig.get('clientId') || '').trim(),
|
||||||
'clientSecret': (githubConfig.get('clientSecret') || '').trim(),
|
'clientSecret': (authConfig.get('clientSecret') || '').trim(),
|
||||||
'enabled': false, // It should already be, but just in case..
|
'enabled': false, // It should already be, but just in case..
|
||||||
'accessMode': am,
|
'accessMode': am,
|
||||||
'tls': true,
|
'tls': true,
|
||||||
'allowedPrincipalIds': [],
|
'allowedPrincipalIds': [],
|
||||||
});
|
});
|
||||||
|
|
||||||
get(this, 'github').setProperties({
|
get(this, 'github').setProperties({
|
||||||
hostname: githubConfig.get('hostname'),
|
hostname: authConfig.get('hostname'),
|
||||||
scheme: githubConfig.get('scheme'),
|
scheme: authConfig.get('scheme'),
|
||||||
clientId: githubConfig.get('clientId')
|
clientId: authConfig.get('clientId')
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
set(this, '_boundSucceed', this.authenticationApplied.bind(this));
|
set(this, '_boundSucceed', this.authenticationApplied.bind(this));
|
||||||
get(this, 'github').test(githubConfig, get(this, '_boundSucceed'));
|
get(this, 'github').test(authConfig, get(this, '_boundSucceed'));
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
waitAndRefresh(url) {
|
|
||||||
|
|
||||||
$('#loading-underlay, #loading-overlay').removeClass('hide').show(); // eslint-disable-line
|
|
||||||
setTimeout(() => {
|
|
||||||
|
|
||||||
window.location.href = url || window.location.href;
|
|
||||||
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
promptDisable() {
|
|
||||||
|
|
||||||
set(this, 'confirmDisable', true);
|
|
||||||
later(this, function() {
|
|
||||||
|
|
||||||
set(this, 'confirmDisable', false);
|
|
||||||
|
|
||||||
}, 10000);
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
gotError(err) {
|
|
||||||
|
|
||||||
if ( err.message ) {
|
|
||||||
|
|
||||||
this.send('showError', err.message + (err.detail ? `(${ err.detail })` : ''));
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
this.send('showError', `Error (${ err.status } - ${ err.code })`);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
set(this, 'testing', false);
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
showError(msg) {
|
|
||||||
|
|
||||||
set(this, 'errors', [msg]);
|
|
||||||
window.scrollY = 10000;
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
clearError() {
|
|
||||||
|
|
||||||
set(this, 'errors', null);
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
disable() {
|
|
||||||
|
|
||||||
this.send('clearError');
|
|
||||||
|
|
||||||
let model = get(this, 'githubConfig').clone();
|
|
||||||
|
|
||||||
model.setProperties({ 'enabled': false, });
|
|
||||||
|
|
||||||
model.doAction('disable').then(() => {
|
|
||||||
|
|
||||||
this.send('waitAndRefresh');
|
|
||||||
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
|
|
||||||
this.send('gotError', err);
|
|
||||||
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
|
|
||||||
set(this, 'confirmDisable', false);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,9 @@
|
||||||
</div>
|
</div>
|
||||||
<hr/>
|
<hr/>
|
||||||
{{#if isEnterprise }}
|
{{#if isEnterprise }}
|
||||||
<div><b>{{t 'authPage.github.authenticated.header.enterpriseHostName'}} </b> <span class="text-muted">{{githubConfig.hostname}}</span></div>
|
<div><b>{{t 'authPage.github.authenticated.header.enterpriseHostName'}} </b> <span class="text-muted">{{authConfig.hostname}}</span></div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
<div><b>{{t 'authPage.github.authenticated.header.clientId.text'}} </b> <span class="text-muted">{{githubConfig.clientId}}</span></div>
|
<div><b>{{t 'authPage.github.authenticated.header.clientId.text'}} </b> <span class="text-muted">{{authConfig.clientId}}</span></div>
|
||||||
</section>
|
</section>
|
||||||
{{/accordion-list-item}}
|
{{/accordion-list-item}}
|
||||||
|
|
||||||
|
|
@ -47,7 +47,7 @@
|
||||||
title=(t 'siteAccess.header')
|
title=(t 'siteAccess.header')
|
||||||
}}
|
}}
|
||||||
{{site-access
|
{{site-access
|
||||||
model=githubConfig
|
model=authConfig
|
||||||
principals=model.principals
|
principals=model.principals
|
||||||
collection='siteAccess.organizations'
|
collection='siteAccess.organizations'
|
||||||
}}
|
}}
|
||||||
|
|
@ -104,7 +104,7 @@
|
||||||
<div class="col span-6">
|
<div class="col span-6">
|
||||||
<div class="inline-form">
|
<div class="inline-form">
|
||||||
<label class="acc-label pb-5">{{t 'authPage.github.notAuthenticated.form.clientId.labelText'}}{{field-required}}</label>
|
<label class="acc-label pb-5">{{t 'authPage.github.notAuthenticated.form.clientId.labelText'}}{{field-required}}</label>
|
||||||
{{input type="text" name="username" value=githubConfig.clientId classNames="form-control"}}
|
{{input type="text" name="username" value=authConfig.clientId classNames="form-control"}}
|
||||||
<p class="help-block">{{t 'authPage.github.notAuthenticated.form.subtext'}}</p>
|
<p class="help-block">{{t 'authPage.github.notAuthenticated.form.subtext'}}</p>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -112,7 +112,7 @@
|
||||||
<div class="col span-6">
|
<div class="col span-6">
|
||||||
<div class="inline-form">
|
<div class="inline-form">
|
||||||
<label class="acc-label pb-5">{{t 'authPage.github.notAuthenticated.form.clientSecret.labelText'}}{{field-required}}</label>
|
<label class="acc-label pb-5">{{t 'authPage.github.notAuthenticated.form.clientSecret.labelText'}}{{field-required}}</label>
|
||||||
{{input type="password" name="password" value=githubConfig.clientSecret classNames="form-control"}}
|
{{input type="password" name="password" value=authConfig.clientSecret classNames="form-control"}}
|
||||||
</div>
|
</div>
|
||||||
<div class="checkbox pt-10">
|
<div class="checkbox pt-10">
|
||||||
<label class="acc-label pb-5">{{input type="checkbox" checked=isEnterprise}} {{t 'authPage.github.notAuthenticated.form.ghEnterprise.labelText'}} (disabled)</label>
|
<label class="acc-label pb-5">{{input type="checkbox" checked=isEnterprise}} {{t 'authPage.github.notAuthenticated.form.ghEnterprise.labelText'}} (disabled)</label>
|
||||||
|
|
@ -124,7 +124,7 @@
|
||||||
{{/liquid-if}}
|
{{/liquid-if}}
|
||||||
{{#liquid-if isEnterprise}}
|
{{#liquid-if isEnterprise}}
|
||||||
<label class="acc-label pb-5">{{t 'authPage.github.notAuthenticated.form.enterpriseHost.labelText'}}{{field-required}}</label>
|
<label class="acc-label pb-5">{{t 'authPage.github.notAuthenticated.form.enterpriseHost.labelText'}}{{field-required}}</label>
|
||||||
{{input type="text" value=githubConfig.hostname classNames="form-control" placeholder=(t 'authPage.github.notAuthenticated.form.enterpriseHost.placeholder')}}
|
{{input type="text" value=authConfig.hostname classNames="form-control" placeholder=(t 'authPage.github.notAuthenticated.form.enterpriseHost.placeholder')}}
|
||||||
{{/liquid-if}}
|
{{/liquid-if}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -140,8 +140,9 @@ export default Service.extend({
|
||||||
ttl: C.SESSION.TTL,
|
ttl: C.SESSION.TTL,
|
||||||
};
|
};
|
||||||
|
|
||||||
return this.saveConfig(config, out).then(() => {
|
const allowedPrincipalIds = get(config, 'allowedPrincipalIds') || [];
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
return get(this, 'globalStore').find('principal', null, {
|
return get(this, 'globalStore').find('principal', null, {
|
||||||
filter: {
|
filter: {
|
||||||
me: true,
|
me: true,
|
||||||
|
|
@ -173,5 +174,28 @@ export default Service.extend({
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
=======
|
||||||
|
return this.saveConfig(config, out).then(() => {
|
||||||
|
|
||||||
|
let found = false;
|
||||||
|
const myPIds = get(this, 'access.me.principalIds');
|
||||||
|
|
||||||
|
myPIds.forEach( id => {
|
||||||
|
if (allowedPrincipalIds.indexOf(id) >= 0) {
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if ( !found && !allowedPrincipalIds.length) {
|
||||||
|
allowedPrincipalIds.pushObject(get(this, 'access.principal.id'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ghConfig.save().then(() => {
|
||||||
|
window.location.href = window.location.href;
|
||||||
|
});
|
||||||
|
}).catch(err => {
|
||||||
|
cb(err);
|
||||||
|
});
|
||||||
|
>>>>>>> Refactor GH auth page
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue