Unify API keys and web hooks into a single admin nav header.

This commit is contained in:
Guo Xiang Tan
2016-09-20 05:22:03 +08:00
parent fa6b10cf3c
commit 547750e9dd
17 changed files with 86 additions and 53 deletions
@@ -0,0 +1,7 @@
import RESTAdapter from 'discourse/adapters/rest';
export default RESTAdapter.extend({
basePath() {
return '/admin/api/';
}
});
@@ -0,0 +1,7 @@
import RESTAdapter from 'discourse/adapters/rest';
export default RESTAdapter.extend({
basePath() {
return '/admin/api/';
}
});
@@ -33,7 +33,7 @@ export default Ember.Component.extend({
redeliver() {
return bootbox.confirm(I18n.t('admin.web_hooks.events.redeliver_confirm'), I18n.t('no_value'), I18n.t('yes_value'), result => {
if (result) {
ajax(`/admin/web_hooks/${this.get('model.web_hook_id')}/events/${this.get('model.id')}/redeliver`, { type: 'POST' }).then(json => {
ajax(`/admin/api/web_hooks/${this.get('model.web_hook_id')}/events/${this.get('model.id')}/redeliver`, { type: 'POST' }).then(json => {
this.set('model', json.web_hook_event);
}).catch(popupAjaxError);
}
@@ -41,7 +41,7 @@ export default Ember.Controller.extend({
ping() {
this.set('pingDisabled', true);
ajax(`/admin/web_hooks/${this.get('model.extras.web_hook_id')}/ping`, {
ajax(`/admin/api/web_hooks/${this.get('model.extras.web_hook_id')}/ping`, {
type: 'POST'
}).catch(error => {
this.set('pingDisabled', false);
@@ -52,7 +52,7 @@ export default Ember.Controller.extend({
showInserted() {
const webHookId = this.get('model.extras.web_hook_id');
ajax(`/admin/web_hooks/${webHookId}/events/bulk`, {
ajax(`/admin/api/web_hooks/${webHookId}/events/bulk`, {
type: 'GET',
data: { ids: this.get('incomingEventIds') }
}).then(data => {
@@ -52,7 +52,7 @@ ApiKey.reopenClass({
@returns {Promise} a promise that resolves to the array of `ApiKey` instances
**/
find: function() {
return ajax("/admin/api").then(function(keys) {
return ajax("/admin/api/keys").then(function(keys) {
return keys.map(function (key) {
return ApiKey.create(key);
});
@@ -0,0 +1,5 @@
export default Ember.Route.extend({
beforeModel() {
this.transitionTo('adminApiKeys');
}
});
@@ -35,10 +35,14 @@ export default {
this.route('edit', { path: '/:id' });
});
});
this.route('api');
this.resource('adminWebHooks', { path: '/web_hooks' }, function() {
this.route('show', { path: '/:web_hook_id' });
this.route('showEvents', { path: '/:web_hook_id/events' });
this.resource('adminApi', { path: '/api' }, function() {
this.resource('adminApiKeys', { path: '/keys' });
this.resource('adminWebHooks', { path: '/web_hooks' }, function() {
this.route('show', { path: '/:web_hook_id' });
this.route('showEvents', { path: '/:web_hook_id/events' });
});
});
this.resource('admin.backups', { path: '/backups' }, function() {
@@ -13,6 +13,6 @@ export default Discourse.Route.extend({
},
renderTemplate() {
this.render('admin/templates/web-hooks-show-events', { into: 'admin' });
this.render('admin/templates/web-hooks-show-events', { into: 'adminApi' });
}
});
@@ -21,6 +21,6 @@ export default Discourse.Route.extend({
},
renderTemplate() {
this.render('admin/templates/web-hooks-show', { into: 'admin' });
this.render('admin/templates/web-hooks-show', { into: 'adminApi' });
}
});
@@ -19,8 +19,7 @@
{{nav-item route='adminLogs' label='admin.logs.title'}}
{{#if currentUser.admin}}
{{nav-item route='adminCustomize' label='admin.customize.title'}}
{{nav-item route='admin.api' label='admin.api.title'}}
{{nav-item route='adminWebHooks' label='admin.web_hooks.title'}}
{{nav-item route='adminApi' label='admin.api.title'}}
{{nav-item route='admin.backups' label='admin.backups.title'}}
{{/if}}
{{nav-item route='adminPlugins' label='admin.plugins.title'}}
@@ -0,0 +1,34 @@
{{#if model}}
<table class='api-keys'>
<tr>
<th>{{i18n 'admin.api.key'}}</th>
<th>{{i18n 'admin.api.user'}}</th>
<th>&nbsp;</th>
</tr>
{{#each model as |k|}}
<tr>
<td class='key'>{{k.key}}</td>
<td>
{{#if k.user}}
{{#link-to 'adminUser' k.user}}
{{avatar k.user imageSize="small"}}
{{/link-to}}
{{else}}
{{i18n 'admin.api.all_users'}}
{{/if}}
</td>
<td>
{{d-button action="regenerateKey" actionParam=k icon="undo" label='admin.api.regenerate'}}
{{d-button action="revokeKey" actionParam=k icon="times" label='admin.api.revoke'}}
</td>
</tr>
{{/each}}
</table>
{{else}}
<p>{{i18n 'admin.api.none'}}</p>
{{/if}}
{{#unless hasMasterKey}}
<button class='btn' {{action "generateMasterKey"}}><i class="fa fa-key"></i>{{i18n 'admin.api.generate_master'}}</button>
{{/unless }}
+9 -32
View File
@@ -1,33 +1,10 @@
{{#if model}}
<table class='api-keys'>
<tr>
<th>{{i18n 'admin.api.key'}}</th>
<th>{{i18n 'admin.api.user'}}</th>
<th>&nbsp;</th>
</tr>
{{#each model as |k|}}
<tr>
<td class='key'>{{k.key}}</td>
<td>
{{#if k.user}}
{{#link-to 'adminUser' k.user}}
{{avatar k.user imageSize="small"}}
{{/link-to}}
{{else}}
{{i18n 'admin.api.all_users'}}
{{/if}}
</td>
<td>
<button class='btn' {{action "regenerateKey" k}}><i class="fa fa-undo"></i>{{i18n 'admin.api.regenerate'}}</button>
<button class='btn' {{action "revokeKey" k}}><i class="fa fa-times"></i>{{i18n 'admin.api.revoke'}}</button>
</td>
</tr>
{{/each}}
</table>
{{else}}
<p>{{i18n 'admin.api.none'}}</p>
{{/if}}
<div class="api">
{{#admin-nav}}
{{nav-item route='adminApiKeys' label='admin.api.title'}}
{{nav-item route='adminWebHooks' label='admin.web_hooks.title'}}
{{/admin-nav}}
{{#unless hasMasterKey}}
<button class='btn' {{action "generateMasterKey"}}><i class="fa fa-key"></i>{{i18n 'admin.api.generate_master'}}</button>
{{/unless }}
<div class="admin-container">
{{outlet}}
</div>
</div>