mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 01:16:38 -06:00
Unify API keys and web hooks into a single admin nav header.
This commit is contained in:
parent
fa6b10cf3c
commit
547750e9dd
@ -0,0 +1,7 @@
|
||||
import RESTAdapter from 'discourse/adapters/rest';
|
||||
|
||||
export default RESTAdapter.extend({
|
||||
basePath() {
|
||||
return '/admin/api/';
|
||||
}
|
||||
});
|
7
app/assets/javascripts/admin/adapters/web-hook.js.es6
Normal file
7
app/assets/javascripts/admin/adapters/web-hook.js.es6
Normal file
@ -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'}}
|
||||
|
34
app/assets/javascripts/admin/templates/api-keys.hbs
Normal file
34
app/assets/javascripts/admin/templates/api-keys.hbs
Normal 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> </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 }}
|
||||
|
@ -1,33 +1,10 @@
|
||||
{{#if model}}
|
||||
<table class='api-keys'>
|
||||
<tr>
|
||||
<th>{{i18n 'admin.api.key'}}</th>
|
||||
<th>{{i18n 'admin.api.user'}}</th>
|
||||
<th> </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>
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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."
|
||||
|
@ -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 }
|
||||
|
Loading…
Reference in New Issue
Block a user