Admin endpoints
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
exports[`presents a user 1`] = `
|
||||
Object {
|
||||
"avatarUrl": "http://example.com/avatar.png",
|
||||
"email": undefined,
|
||||
"id": "123",
|
||||
"name": "Test User",
|
||||
"username": "testuser",
|
||||
@@ -13,7 +12,6 @@ Object {
|
||||
exports[`presents a user without slack data 1`] = `
|
||||
Object {
|
||||
"avatarUrl": null,
|
||||
"email": undefined,
|
||||
"id": "123",
|
||||
"name": "Test User",
|
||||
"username": "testuser",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// @flow
|
||||
import _ from 'lodash';
|
||||
import { Op } from 'sequelize';
|
||||
import { User, Document } from '../models';
|
||||
import presentUser from './user';
|
||||
import presentCollection from './collection';
|
||||
@@ -57,7 +58,7 @@ async function present(ctx: Object, document: Document, options: ?Options) {
|
||||
// This could be further optimized by using ctx.cache
|
||||
data.collaborators = await User.findAll({
|
||||
where: {
|
||||
id: { $in: _.takeRight(document.collaboratorIds, 10) || [] },
|
||||
id: { [Op.in]: _.takeRight(document.collaboratorIds, 10) || [] },
|
||||
},
|
||||
}).map(user => presentUser(ctx, user));
|
||||
|
||||
|
||||
@@ -1,17 +1,37 @@
|
||||
// @flow
|
||||
import User from '../models/User';
|
||||
|
||||
function present(ctx: Object, user: User) {
|
||||
type Options = {
|
||||
includeDetails?: boolean,
|
||||
};
|
||||
|
||||
type UserPresentation = {
|
||||
id: string,
|
||||
username: string,
|
||||
name: string,
|
||||
avatarUrl: ?string,
|
||||
email?: string,
|
||||
isAdmin?: boolean,
|
||||
};
|
||||
|
||||
export default (
|
||||
ctx: Object,
|
||||
user: User,
|
||||
options: Options = {}
|
||||
): UserPresentation => {
|
||||
ctx.cache.set(user.id, user);
|
||||
|
||||
return {
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
name: user.name,
|
||||
email: user.email,
|
||||
avatarUrl:
|
||||
user.avatarUrl || (user.slackData ? user.slackData.image_192 : null),
|
||||
};
|
||||
}
|
||||
const userData = {};
|
||||
userData.id = user.id;
|
||||
userData.username = user.username;
|
||||
userData.name = user.name;
|
||||
userData.avatarUrl =
|
||||
user.avatarUrl || (user.slackData ? user.slackData.image_192 : null);
|
||||
|
||||
export default present;
|
||||
if (options.includeDetails) {
|
||||
userData.isAdmin = user.isAdmin;
|
||||
userData.email = user.email;
|
||||
}
|
||||
|
||||
return userData;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user