mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-29 13:52:10 +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.
49 lines
1.6 KiB
JavaScript
49 lines
1.6 KiB
JavaScript
import {Collection, RestSerializer} from 'ember-cli-mirage';
|
|
import {pluralize} from 'ember-cli-mirage/utils/inflector';
|
|
import {underscore} from '@ember/string';
|
|
|
|
export default RestSerializer.extend({
|
|
keyForCollection(collection) {
|
|
return underscore(pluralize(collection));
|
|
},
|
|
|
|
keyForAttribute(attr) {
|
|
return underscore(attr);
|
|
},
|
|
|
|
keyForRelationship(relationship) {
|
|
return underscore(relationship);
|
|
},
|
|
|
|
keyForEmbeddedRelationship(relationship) {
|
|
return underscore(relationship);
|
|
},
|
|
|
|
serialize(object, request) {
|
|
// Ember expects pluralized responses for the post, user, and invite models,
|
|
// and this shortcut will ensure that those models are pluralized
|
|
if (this.isModel(object) && ['post', 'user', 'invite'].includes(object.modelName)) {
|
|
object = new Collection(object.modelName, [object]);
|
|
}
|
|
|
|
let json = RestSerializer.prototype.serialize.call(this, object, request);
|
|
|
|
if (this.isCollection(object) && object.meta) {
|
|
json.meta = object.meta;
|
|
}
|
|
|
|
return json;
|
|
},
|
|
|
|
// POST and PUT request send data in pluralized attributes for all models,
|
|
// so we extract it here - this allows #normalizedRequestAttrs to work
|
|
// in route functions
|
|
normalize(body, modelName) {
|
|
// sometimes mirage doesn't include a modelName, so we extrapolate it from
|
|
// the first element of Object.keys
|
|
modelName = pluralize(modelName) || Object.keys(body)[0];
|
|
let [attributes] = body[modelName] || [{}];
|
|
return {data: {attributes}};
|
|
}
|
|
});
|