From 22d1c6fd064ccdcf18798f0014489f79caeea5a8 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Mon, 3 Jun 2019 09:40:54 +1000 Subject: [PATCH] API Admin client-side cleanups --- .../controllers/admin-wizards-api.js.es6 | 47 +++++++++++-------- .../discourse/templates/admin-wizards-api.hbs | 11 ++++- assets/stylesheets/wizard_custom_admin.scss | 7 +-- 3 files changed, 40 insertions(+), 25 deletions(-) diff --git a/assets/javascripts/discourse/controllers/admin-wizards-api.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards-api.js.es6 index 2457a917..0fae7419 100644 --- a/assets/javascripts/discourse/controllers/admin-wizards-api.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizards-api.js.es6 @@ -10,15 +10,20 @@ export default Ember.Controller.extend({ notAuthorized: Ember.computed.not('api.authorized'), authorizationTypes: ['oauth', 'basic'], isOauth: Ember.computed.equal('api.authType', 'oauth'), + isBasicAuth: Ember.computed.equal('api.authType', 'basic'), endpointMethods: ['GET', 'PUT', 'POST', 'PATCH', 'DELETE'], - saveDisabled: Ember.computed.empty('api.name'), showRemove: Ember.computed.not('isNew'), - @computed('saveDisabled', 'authType', 'authUrl') + @computed('saveDisabled', 'api.authType', 'api.authUrl') authDisabled(saveDisabled, authType, authUrl) { return saveDisabled || !authType || !authUrl; }, + @computed('api.name', 'api.authType') + saveDisabled(name, authType) { + return !name || !authType; + }, + @observes('api.title') titleWatcher() { const title = this.get('api.title'); @@ -48,18 +53,19 @@ export default Ember.Controller.extend({ authorize() { const api = this.get('api'); const { authType, authUrl, authParams } = api; + + if (authType !== 'oauth') return; + let query = '?'; - if (authType === 'oauth') { - query += `client_id=${api.clientId}&redirect_uri=${encodeURIComponent(api.redirectUri)}&response_type=code`; + query += `client_id=${api.clientId}`; + query += `&redirect_uri=${encodeURIComponent(api.redirectUri)}`; + query += `&response_type=code`; - if (authParams) { - authParams.forEach(p => { - query += `&${p.key}=${encodeURIComponent(p.value)}`; - }); - } - } else { - // basic auth - no need to authorize separately + if (authParams) { + authParams.forEach(p => { + query += `&${p.key}=${encodeURIComponent(p.value)}`; + }); } window.location.href = authUrl + query; @@ -68,15 +74,18 @@ export default Ember.Controller.extend({ save() { const api = this.get('api'); const name = api.name; + const authType = api.authType; let refreshList = false; - if (!name ) return; + if (!name || !authType) return; let data = { - title: api.title + auth_type: authType }; - if (this.get('isNew') || (api.title !== this.get('originalTitle'))) { + if (api.title) data['title'] = api.title; + + if (api.get('isNew') || (api.title !== this.get('originalTitle'))) { refreshList = true; } @@ -84,10 +93,8 @@ export default Ember.Controller.extend({ data['new'] = true; }; - if (api.authType) data['auth_type'] = api.authType; - if (api.authUrl) data['auth_url'] = api.authUrl; - - if (data.auth_type === 'oauth') { + if (authType === 'oauth') { + data['auth_url'] = api.authUrl; data['client_id'] = api.clientId; data['client_secret'] = api.clientSecret; @@ -98,13 +105,13 @@ export default Ember.Controller.extend({ } data['token_url'] = api.tokenUrl; - } else { + } else if (authType === 'basic') { data['username'] = api.username; data['password'] = api.password; } const endpoints = api.endpoints; - + if (endpoints.length) { data['endpoints'] = JSON.stringify(endpoints); } diff --git a/assets/javascripts/discourse/templates/admin-wizards-api.hbs b/assets/javascripts/discourse/templates/admin-wizards-api.hbs index 9d929985..8ab9cf7c 100644 --- a/assets/javascripts/discourse/templates/admin-wizards-api.hbs +++ b/assets/javascripts/discourse/templates/admin-wizards-api.hbs @@ -34,7 +34,12 @@
- {{d-button label="admin.wizard.api.auth.btn" action="authorize" disabled=authDisabled class="btn-primary"}} + {{#if isOauth}} + {{d-button label="admin.wizard.api.auth.btn" + action="authorize" + disabled=authDisabled + class="btn-primary"}} + {{/if}}
@@ -107,7 +112,9 @@ {{d-button label='admin.wizard.api.auth.params.new' icon='plus' action='addParam'}} - {{else}} + {{/if}} + + {{#if isBasicAuth}}
diff --git a/assets/stylesheets/wizard_custom_admin.scss b/assets/stylesheets/wizard_custom_admin.scss index 8026525c..68ecff6a 100644 --- a/assets/stylesheets/wizard_custom_admin.scss +++ b/assets/stylesheets/wizard_custom_admin.scss @@ -334,9 +334,6 @@ margin-bottom: 20px; .settings { - border-right: 1px solid #333; - margin-right: 20px; - padding-right: 20px; width: 50%; max-width: 50%; } @@ -352,6 +349,9 @@ } .status { + border-left: 1px solid $primary; + margin-left: 20px; + padding-left: 20px; width: 50%; max-width: 50%; @@ -384,6 +384,7 @@ .endpoint { display: flex; + margin-top: 20px; .combo-box { width: 200px;