diff --git a/lib/global-admin/addon/mixins/authentication.js b/lib/global-admin/addon/mixins/authentication.js index 5ce65d28c..4cb7654ab 100644 --- a/lib/global-admin/addon/mixins/authentication.js +++ b/lib/global-admin/addon/mixins/authentication.js @@ -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: [] }); diff --git a/lib/global-admin/addon/security/authentication/github/controller.js b/lib/global-admin/addon/security/authentication/github/controller.js index 4d25cfb63..65e24378c 100644 --- a/lib/global-admin/addon/security/authentication/github/controller.js +++ b/lib/global-admin/addon/security/authentication/github/controller.js @@ -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')); }, }, diff --git a/lib/global-admin/addon/security/authentication/github/template.hbs b/lib/global-admin/addon/security/authentication/github/template.hbs index e8e2da075..3a2891ffd 100644 --- a/lib/global-admin/addon/security/authentication/github/template.hbs +++ b/lib/global-admin/addon/security/authentication/github/template.hbs @@ -30,9 +30,9 @@
{{#if isEnterprise }} -
{{t 'authPage.github.authenticated.header.enterpriseHostName'}} {{githubConfig.hostname}}
+
{{t 'authPage.github.authenticated.header.enterpriseHostName'}} {{authConfig.hostname}}
{{/if}} -
{{t 'authPage.github.authenticated.header.clientId.text'}} {{githubConfig.clientId}}
+
{{t 'authPage.github.authenticated.header.clientId.text'}} {{authConfig.clientId}}
{{/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 @@
- {{input type="text" name="username" value=githubConfig.clientId classNames="form-control"}} + {{input type="text" name="username" value=authConfig.clientId classNames="form-control"}}

{{t 'authPage.github.notAuthenticated.form.subtext'}}

@@ -112,7 +112,7 @@
- {{input type="password" name="password" value=githubConfig.clientSecret classNames="form-control"}} + {{input type="password" name="password" value=authConfig.clientSecret classNames="form-control"}}
@@ -124,7 +124,7 @@ {{/liquid-if}} {{#liquid-if isEnterprise}} - {{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}}
diff --git a/lib/shared/addon/github/service.js b/lib/shared/addon/github/service.js index 82f5b9691..c5b1bc11b 100644 --- a/lib/shared/addon/github/service.js +++ b/lib/shared/addon/github/service.js @@ -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 }, });