mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 22:02:11 +03:00
6a3cfc2ca8
requires https://github.com/TryGhost/Ghost/pull/9426 - fixed default token component display in {{gh-token-input}} - if no `tokenComponent` is passed to `{{gh-token-input}}` then it should default to the ember-drag-drop `draggable-object` component but instead it didn't output anything - put `draggable-object` in quotes because `{{component}}` needs a component name rather than an object - rename `option` attribute to `content` to match the default `{{draggable-object}}` interface - add embedded `authors` attr to the Post model - ensure authors is populated when starting new post - add validation for empty authors list - swap author dropdown for a token input in PSM - show all post authors in posts list - update tests for `authors` - always provide through an authors array - fix mirage serialisation for paginated responses (embedded records were not being serialised) - unify tags and author inputs design - remove highlight of primary tags - highlight internal tags - remove unnecessary/redundant title attributes on tags - use SVG icon for "remove option" button in token inputs
73 lines
2.4 KiB
JavaScript
73 lines
2.4 KiB
JavaScript
import {Response} from 'ember-cli-mirage';
|
|
import {paginateModelCollection} from '../utils';
|
|
|
|
export default function mockUsers(server) {
|
|
// /users/me = Always return the user with ID=1
|
|
server.get('/users/me/', function ({users}) {
|
|
let user = users.find(1);
|
|
|
|
if (user) {
|
|
return user;
|
|
} else {
|
|
return new Response(404, {}, {errors: [
|
|
{message: 'Not found', errorType: 'NotFoundError'}
|
|
]});
|
|
}
|
|
});
|
|
|
|
server.get('/users/', function ({users}, {queryParams}) {
|
|
let page = +queryParams.page || 1;
|
|
|
|
// NOTE: this is naive and only set up to work with queries that are
|
|
// actually used - if you use a different filter in the app, add it here!
|
|
let collection = users.where(function (user) {
|
|
let statusMatch = true;
|
|
|
|
if (queryParams.filter === 'status:-inactive') {
|
|
statusMatch = user.status !== 'inactive';
|
|
} else if (queryParams.filter === 'status:inactive') {
|
|
statusMatch = user.status === 'inactive';
|
|
} else if (queryParams.status && queryParams.status !== 'all') {
|
|
statusMatch = user.status === queryParams.status;
|
|
}
|
|
|
|
return statusMatch;
|
|
});
|
|
|
|
return paginateModelCollection('users', collection, page, queryParams.limit);
|
|
});
|
|
|
|
server.get('/users/slug/:slug/', function ({users}, {params, queryParams}) {
|
|
let user = users.findBy({slug: params.slug});
|
|
user.postCount = queryParams.include.match(/count\.posts/);
|
|
return user;
|
|
});
|
|
|
|
server.get('/users/:id', function ({users}, {params, queryParams}) {
|
|
let user = users.find(params.id);
|
|
user.postCount = queryParams.include.match(/count\.posts/);
|
|
return user;
|
|
});
|
|
|
|
server.put('/users/:id/', function ({users}, {params}) {
|
|
let {id} = params;
|
|
|
|
if (id === 'password') {
|
|
return {
|
|
password: [{message: 'Password changed successfully.'}]
|
|
};
|
|
} else {
|
|
let attrs = this.normalizedRequestAttrs();
|
|
|
|
// TODO: why is our custom serializer causing .update to throw
|
|
// children.update is not a function?
|
|
// https://github.com/samselikoff/ember-cli-mirage/issues/964
|
|
delete attrs.roles;
|
|
|
|
return users.find(id).update(attrs);
|
|
}
|
|
});
|
|
|
|
server.del('/users/:id/');
|
|
}
|