mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 11:22:19 +03:00
d0d97d1aa2
requires https://github.com/TryGhost/Ghost/pull/8114 - adds "(Un-)Suspend User" options on user profile page with a modal confirmation screen - separates team index into "active" and "suspended" users - adds "suspended" badge to user profile when suspended
64 lines
2.1 KiB
JavaScript
64 lines
2.1 KiB
JavaScript
import {paginateModelArray} from '../utils';
|
|
|
|
export default function mockUsers(server) {
|
|
// /users/me = Always return the user with ID=1
|
|
server.get('/users/me/', function ({users}) {
|
|
return users.find(1);
|
|
});
|
|
|
|
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 {models} = 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 paginateModelArray('users', models, 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/');
|
|
}
|