Skip to content
This repository was archived by the owner on Oct 11, 2022. It is now read-only.

Commit e84b676

Browse files
authored
Merge pull request #3792 from withspectrum/2.4.26
2.4.26
2 parents e5ca1d8 + 9a2bee4 commit e84b676

File tree

40 files changed

+683
-265
lines changed

40 files changed

+683
-265
lines changed

api/index.js

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,25 +94,33 @@ import createSubscriptionsServer from './routes/create-subscription-server';
9494
const subscriptionsServer = createSubscriptionsServer(server, '/websocket');
9595

9696
// Start API wrapped in Apollo Engine
97-
// const engine = new ApolloEngine({
98-
// logging: {
99-
// level: 'WARN',
100-
// },
101-
// apiKey: process.env.APOLLO_ENGINE_API_KEY,
102-
// // Only send perf data to the remote server in production
103-
// reporting: {
104-
// disabled: process.env.NODE_ENV !== 'production',
105-
// hostname: process.env.NOW_URL || undefined,
106-
// privateHeaders: ['authorization', 'Authorization', 'AUTHORIZATION'],
107-
// },
108-
// });
109-
110-
// engine.listen({
111-
// port: PORT,
112-
// httpServer: server,
113-
// graphqlPaths: ['/api'],
114-
// });
115-
server.listen(PORT);
97+
const engine = new ApolloEngine({
98+
logging: {
99+
level: 'WARN',
100+
},
101+
apiKey: process.env.APOLLO_ENGINE_API_KEY,
102+
// Only send perf data to the remote server in production
103+
reporting: {
104+
disabled: process.env.NODE_ENV !== 'production',
105+
hostname: process.env.NOW_URL || undefined,
106+
privateHeaders: ['authorization', 'Authorization', 'AUTHORIZATION'],
107+
},
108+
queryCache: {
109+
// Don't cache logged-in user responses
110+
privateFullQueryStore: 'disabled',
111+
},
112+
sessionAuth: {
113+
cookie: 'session',
114+
// TODO(@mxstbr): Ping Apollo to note that we need both of those
115+
// header: 'Authorization'
116+
},
117+
});
118+
119+
engine.listen({
120+
port: PORT,
121+
httpServer: server,
122+
graphqlPaths: ['/api'],
123+
});
116124
debug(`GraphQL server running at http://localhost:${PORT}/api`);
117125

118126
process.on('unhandledRejection', async err => {

api/mutations/user/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import unsubscribeWebPush from './unsubscribeWebPush';
1414
import updateUserEmail from './updateUserEmail';
1515
import deleteCurrentUser from './deleteCurrentUser';
1616
import subscribeExpoPush from './subscribeExpoPush';
17+
import reportUser from './reportUser';
1718

1819
module.exports = {
1920
Mutation: {
@@ -24,5 +25,6 @@ module.exports = {
2425
updateUserEmail,
2526
deleteCurrentUser,
2627
subscribeExpoPush,
28+
reportUser,
2729
},
2830
};

api/mutations/user/reportUser.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// @flow
2+
import { isAuthedResolver } from '../../utils/permissions';
3+
import UserError from '../../utils/UserError';
4+
import { _adminProcessUserReportedQueue } from 'shared/bull/queues';
5+
import type { GraphQLContext } from '../../';
6+
import { events } from 'shared/analytics';
7+
import { trackQueue } from 'shared/bull/queues';
8+
9+
type ReportUserInput = {
10+
input: {
11+
userId: string,
12+
reason: string,
13+
},
14+
};
15+
16+
export default isAuthedResolver(
17+
async (_: any, args: ReportUserInput, ctx: GraphQLContext) => {
18+
const {
19+
input: { userId, reason },
20+
} = args;
21+
const { loaders, user: currentUser } = ctx;
22+
23+
if (currentUser.id === userId) {
24+
return new UserError('You cannot report yourself.');
25+
}
26+
27+
const reportedUser = await loaders.user.load(userId);
28+
29+
if (!reportedUser) {
30+
return new UserError(`User with ID ${userId} does not exist.`);
31+
}
32+
33+
try {
34+
trackQueue.add({
35+
userId,
36+
event: events.USER_WAS_REPORTED,
37+
properties: {
38+
reason,
39+
reportedBy: currentUser.id,
40+
},
41+
});
42+
43+
trackQueue.add({
44+
userId: currentUser.id,
45+
event: events.USER_REPORTED_USER,
46+
properties: {
47+
reason,
48+
reportedUser: userId,
49+
},
50+
});
51+
52+
await _adminProcessUserReportedQueue.add({
53+
userId,
54+
reason,
55+
reportedBy: currentUser.id,
56+
reportedAt: new Date(),
57+
});
58+
} catch (err) {
59+
console.error(err);
60+
return false;
61+
}
62+
return true;
63+
}
64+
);

api/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"cors": "^2.8.3",
2323
"cryptr": "^3.0.0",
2424
"dataloader": "^1.4.0",
25-
"debounce": "^1.1.0",
25+
"debounce": "^1.2.0",
2626
"debug": "^2.6.8",
2727
"draft-js": "^0.10.5",
2828
"draft-js-code-editor-plugin": "0.2.1",
@@ -113,7 +113,7 @@
113113
"sanitize-filename": "^1.6.1",
114114
"serialize-javascript": "^1.5.0",
115115
"session-rethinkdb": "^2.0.0",
116-
"shortid": "^2.2.12",
116+
"shortid": "^2.2.13",
117117
"slate": "^0.20.1",
118118
"slate-markdown": "0.1.0",
119119
"slugg": "^1.1.0",

api/queries/community/metaData.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default async (root: DBCommunity, _: any, ctx: GraphQLContext) => {
1111
return {
1212
channels: 0,
1313
members: 0,
14+
onlineMembers: 0,
1415
};
1516
}
1617

api/routes/api/graphql.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export default graphqlExpress(req => {
1515
return {
1616
schema,
1717
formatError: createErrorFormatter(req),
18+
tracing: true,
19+
cacheControl: true,
20+
engine: false,
1821
context: {
1922
loaders,
2023
user: currentUser,

api/types/Community.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const Community = /* GraphQL */ `
4141
node: Thread!
4242
}
4343
44-
type CommunityMetaData {
44+
type CommunityMetaData @cacheControl(maxAge: 1800) {
4545
members: Int
4646
channels: Int
4747
onlineMembers: Int

0 commit comments

Comments
 (0)