mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-04 08:54:36 +03:00
5047b9f3d7
refs https://github.com/TryGhost/Ghost/issues/9865, https://github.com/TryGhost/Ghost/issues/9942 - `integration`, `api-key`, and `webhook` models and respective mirage mocks - moves integration routes around to match ember's concept of nested routes (nested routes reflect nested UI not nested URLs) - adds custom integrations list to integrations screen - adds custom integration screen - allow editing of integration details - show list of webhooks - webhook creation modal NB: the `enableDeveloperExperiments` flag needs to be enabled in the `config.development.json` file for the custom integrations UI to be displayed until it's out of development.
65 lines
2.2 KiB
JavaScript
65 lines
2.2 KiB
JavaScript
import moment from 'moment';
|
|
import {Response} from 'ember-cli-mirage';
|
|
import {paginatedResponse} from '../utils';
|
|
|
|
export default function mockIntegrations(server) {
|
|
server.get('/integrations/', paginatedResponse('integrations'));
|
|
|
|
server.post('/integrations/', function ({integrations}, {requestBody}) {
|
|
let body = JSON.parse(requestBody);
|
|
let [params] = body.integrations;
|
|
|
|
if (!params.name) {
|
|
return new Response(422, {}, {errors: [{
|
|
errorType: 'ValidationError',
|
|
message: 'Name is required',
|
|
property: 'name'
|
|
}]});
|
|
}
|
|
|
|
if (integrations.findBy({name: params.name}) || params.name.match(/Duplicate/i)) {
|
|
return new Response(422, {}, {errors: [{
|
|
errorType: 'ValidationError',
|
|
message: 'Name has already been used',
|
|
property: 'name'
|
|
}]});
|
|
}
|
|
|
|
// allow factory to create defaults
|
|
if (!params.slug) {
|
|
delete params.slug;
|
|
}
|
|
|
|
// use factory creation to auto-create api keys
|
|
return server.create('integration', params);
|
|
});
|
|
|
|
server.put('/integrations/:id/', function (schema, {params}) {
|
|
let {integrations, apiKeys, webhooks} = schema;
|
|
let attrs = this.normalizedRequestAttrs();
|
|
let integration = integrations.find(params.id);
|
|
let _apiKeys = [];
|
|
let _webhooks = [];
|
|
|
|
// this is required to work around an issue with ember-cli-mirage and
|
|
// embedded records. The `attrs` object will contain POJOs of the
|
|
// embedded apiKeys and webhooks but mirage expects schema model
|
|
// objects for relations so we need to fetch model records and replace
|
|
// the relationship keys
|
|
attrs.apiKeys.forEach((apiKey) => {
|
|
_apiKeys.push(apiKeys.find(apiKey.id));
|
|
});
|
|
attrs.webhooks.forEach((webhook) => {
|
|
_webhooks.push(webhooks.find(webhook.id));
|
|
});
|
|
attrs.apiKeys = _apiKeys;
|
|
attrs.webhooks = _webhooks;
|
|
|
|
attrs.updatedAt = moment.utc().format();
|
|
|
|
return integration.update(attrs);
|
|
});
|
|
|
|
server.del('/integrations/:id/');
|
|
}
|