Merge pull request #4446 from tgxworld/unify_api_keys_web_hooks_admin_headers

Unify API keys and web hooks into a single admin nav header.
This commit is contained in:
Guo Xiang Tan 2016-09-20 05:24:44 +08:00 committed by GitHub
commit 91dac006ac
17 changed files with 86 additions and 53 deletions

View File

@ -0,0 +1,7 @@
import RESTAdapter from 'discourse/adapters/rest';
export default RESTAdapter.extend({
basePath() {
return '/admin/api/';
}
});

View File

@ -0,0 +1,7 @@
import RESTAdapter from 'discourse/adapters/rest';
export default RESTAdapter.extend({
basePath() {
return '/admin/api/';
}
});

View File

@ -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);
}

View File

@ -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 => {

View File

@ -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);
});

View File

@ -0,0 +1,5 @@
export default Ember.Route.extend({
beforeModel() {
this.transitionTo('adminApiKeys');
}
});

View File

@ -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() {

View File

@ -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' });
}
});

View File

@ -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' });
}
});

View File

@ -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'}}

View File

@ -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 }}

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>

View File

@ -63,7 +63,7 @@ class Admin::WebHooksController < Admin::AdminController
json = {
web_hook_events: serialize_data(@web_hook.web_hook_events.limit(limit).offset(offset), AdminWebHookEventSerializer),
total_rows_web_hook_events: @web_hook.web_hook_events.count,
load_more_web_hook_events: admin_web_hook_events_path(limit: limit, offset: offset + limit, format: :json),
load_more_web_hook_events: web_hook_events_admin_api_index_path(limit: limit, offset: offset + limit, format: :json),
extras: {
web_hook_id: @web_hook.id
}

View File

@ -2413,7 +2413,6 @@ en:
flair_preview: "Preview"
flair_note: "Note: Flair will only show for a user's primary group."
api:
generate_master: "Generate Master API Key"
none: "There are no active API keys right now."

View File

@ -200,19 +200,20 @@ Discourse::Application.routes.draw do
resources :api, only: [:index], constraints: AdminConstraint.new do
collection do
get "keys" => "api#index"
post "key" => "api#create_master_key"
put "key" => "api#regenerate_key"
delete "key" => "api#revoke_key"
resources :web_hooks
get 'web_hook_events/:id' => 'web_hooks#list_events', as: :web_hook_events
get 'web_hooks/:id/events' => 'web_hooks#list_events'
get 'web_hooks/:id/events/bulk' => 'web_hooks#bulk_events'
post 'web_hooks/:web_hook_id/events/:event_id/redeliver' => 'web_hooks#redeliver_event'
post 'web_hooks/:id/ping' => 'web_hooks#ping'
end
end
resources :web_hooks, constraints: AdminConstraint.new
get 'web_hook_events/:id' => 'web_hooks#list_events', constraints: AdminConstraint.new, as: :web_hook_events
get 'web_hooks/:id/events' => 'web_hooks#list_events', constraints: AdminConstraint.new
get 'web_hooks/:id/events/bulk' => 'web_hooks#bulk_events', constraints: AdminConstraint.new
post 'web_hooks/:web_hook_id/events/:event_id/redeliver' => 'web_hooks#redeliver_event', constraints: AdminConstraint.new
post 'web_hooks/:id/ping' => 'web_hooks#ping', constraints: AdminConstraint.new
resources :backups, only: [:index, :create], constraints: AdminConstraint.new do
member do
get "" => "backups#show", constraints: { id: BACKUP_ROUTE_FORMAT }