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');
|
||||
|
||||
const model = get(this, 'authConfig');
|
||||
const accessMode = get(model, 'id') !== 'github' ? 'unrestricted' : 'restricted';
|
||||
|
||||
setProperties(model, {
|
||||
enabled: false,
|
||||
accessMode: 'unrestricted',
|
||||
accessMode: accessMode,
|
||||
allowedPrincipalIds: []
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -7,12 +7,17 @@ import { alias } from '@ember/object/computed';
|
|||
import { inject as service } from '@ember/service';
|
||||
import Controller from '@ember/controller';
|
||||
import C from 'ui/utils/constants';
|
||||
import AuthMixin from 'global-admin/mixins/authentication';
|
||||
|
||||
export default Controller.extend({
|
||||
export default Controller.extend(AuthMixin,{
|
||||
github: service(),
|
||||
endpoint: service(),
|
||||
access: service(),
|
||||
settings: service(),
|
||||
|
||||
authConfig: alias('model.githubConfig'),
|
||||
scheme: alias('authConfig.scheme'),
|
||||
|
||||
confirmDisable: false,
|
||||
errors: null,
|
||||
testing: false,
|
||||
|
|
@ -106,105 +111,27 @@ export default Controller.extend({
|
|||
this.send('clearError');
|
||||
set(this, 'saving', true);
|
||||
|
||||
const githubConfig = get(this, 'githubConfig');
|
||||
const am = get(githubConfig, 'accessMode') || 'restricted';
|
||||
const authConfig = get(this, 'authConfig');
|
||||
const am = get(authConfig, 'accessMode') || 'restricted';
|
||||
|
||||
githubConfig.setProperties({
|
||||
'clientId': (githubConfig.get('clientId') || '').trim(),
|
||||
'clientSecret': (githubConfig.get('clientSecret') || '').trim(),
|
||||
authConfig.setProperties({
|
||||
'clientId': (authConfig.get('clientId') || '').trim(),
|
||||
'clientSecret': (authConfig.get('clientSecret') || '').trim(),
|
||||
'enabled': false, // It should already be, but just in case..
|
||||
'accessMode': am,
|
||||
'tls': true,
|
||||
'tls': true,
|
||||
'allowedPrincipalIds': [],
|
||||
});
|
||||
|
||||
get(this, 'github').setProperties({
|
||||
hostname: githubConfig.get('hostname'),
|
||||
scheme: githubConfig.get('scheme'),
|
||||
clientId: githubConfig.get('clientId')
|
||||
hostname: authConfig.get('hostname'),
|
||||
scheme: authConfig.get('scheme'),
|
||||
clientId: authConfig.get('clientId')
|
||||
});
|
||||
|
||||
|
||||
set(this, '_boundSucceed', this.authenticationApplied.bind(this));
|
||||
get(this, 'github').test(githubConfig, 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);
|
||||
|
||||
});
|
||||
get(this, 'github').test(authConfig, get(this, '_boundSucceed'));
|
||||
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -30,9 +30,9 @@
|
|||
</div>
|
||||
<hr/>
|
||||
{{#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}}
|
||||
<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>
|
||||
{{/accordion-list-item}}
|
||||
|
||||
|
|
@ -47,7 +47,7 @@
|
|||
title=(t 'siteAccess.header')
|
||||
}}
|
||||
{{site-access
|
||||
model=githubConfig
|
||||
model=authConfig
|
||||
principals=model.principals
|
||||
collection='siteAccess.organizations'
|
||||
}}
|
||||
|
|
@ -104,7 +104,7 @@
|
|||
<div class="col span-6">
|
||||
<div class="inline-form">
|
||||
<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>
|
||||
|
||||
</div>
|
||||
|
|
@ -112,7 +112,7 @@
|
|||
<div class="col span-6">
|
||||
<div class="inline-form">
|
||||
<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 class="checkbox pt-10">
|
||||
<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 isEnterprise}}
|
||||
<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}}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -140,8 +140,9 @@ export default Service.extend({
|
|||
ttl: C.SESSION.TTL,
|
||||
};
|
||||
|
||||
return this.saveConfig(config, out).then(() => {
|
||||
const allowedPrincipalIds = get(config, 'allowedPrincipalIds') || [];
|
||||
|
||||
<<<<<<< HEAD
|
||||
return get(this, 'globalStore').find('principal', null, {
|
||||
filter: {
|
||||
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