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

Commit c623fb3

Browse files
authored
Merge pull request #4732 from withspectrum/2.7.4
2.7.4
2 parents 59902e2 + ad2c530 commit c623fb3

File tree

72 files changed

+1459
-1450
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1459
-1450
lines changed

analytics/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
{
2-
"name": "analytics",
32
"version": "1.0.0",
43
"scripts": {
54
"start": "NODE_ENV=production node main.js"
65
},
76
"dependencies": {
87
"amplitude": "^3.5.0",
9-
"aws-sdk": "^2.395.0",
8+
"aws-sdk": "^2.409.0",
109
"bull": "3.3.10",
1110
"datadog-metrics": "^0.8.1",
1211
"debug": "^4.1.1",

analytics/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ asynckit@^0.4.0:
1414
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
1515
integrity sha1-x57Zf380y48robyXkLzDZkdLS3k=
1616

17-
aws-sdk@^2.395.0:
18-
version "2.395.0"
19-
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.395.0.tgz#637e5fa06d69bfb923b17bde24a8bd2a74dedab3"
20-
integrity sha512-ldTTjctniZT4E2lq2z3D8Y2u+vpkp+laoEnDkXgjKXTKbiJ0QEtfWsUdx/IQ7awCt8stoxyqZK47DJOxIbRNoA==
17+
aws-sdk@^2.409.0:
18+
version "2.409.0"
19+
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.409.0.tgz#d017060ba9e005487c68dc34a592af74d916f295"
20+
integrity sha512-QV6j9zBQq/Kz8BqVOrJ03ABjMKtErXdUT1YdYEljoLQZimpzt0ZdQwJAsoZIsxxriOJgrqeZsQUklv9AFQaldQ==
2121
dependencies:
2222
buffer "4.9.1"
2323
events "1.1.1"

api/authentication.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,11 @@ const init = () => {
294294
const githubUsername =
295295
profile.username || profile._json.login || fallbackUsername;
296296

297+
const existingUserWithProviderId = await getUserByIndex(
298+
'githubProviderId',
299+
profile.id
300+
);
301+
297302
if (req.user) {
298303
// if a user exists in the request body, it means the user is already
299304
// authed and is trying to connect a github account. Before we do so
@@ -302,7 +307,6 @@ const init = () => {
302307
// 2. The providerId returned from GitHub isnt' being used by another user
303308

304309
// 1
305-
// if the user already has a githubProviderId, don't override it
306310
if (req.user.githubProviderId) {
307311
/*
308312
Update the cached content of the github profile that we store
@@ -333,11 +337,6 @@ const init = () => {
333337
return done(null, req.user);
334338
}
335339

336-
const existingUserWithProviderId = await getUserByIndex(
337-
'githubProviderId',
338-
profile.id
339-
);
340-
341340
// 2
342341
// if no user exists with this provider id, it's safe to save on the req.user's object
343342
if (!existingUserWithProviderId) {
@@ -359,7 +358,10 @@ const init = () => {
359358

360359
// if a user exists with this provider id, don't do anything and return
361360
if (existingUserWithProviderId) {
362-
return done(null, req.user);
361+
return done(null, req.user, {
362+
message:
363+
'Your GitHub account is already linked to another Spectrum profile.',
364+
});
363365
}
364366
}
365367

api/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { init as initPassport } from './authentication.js';
1717
import apolloServer from './apollo-server';
1818
import { corsOptions } from 'shared/middlewares/cors';
1919
import errorHandler from 'shared/middlewares/error-handler';
20+
import rateLimiter from 'shared/middlewares/rate-limiter';
2021
import middlewares from './routes/middlewares';
2122
import authRoutes from './routes/auth';
2223
import apiRoutes from './routes/api';
@@ -43,6 +44,13 @@ app.use(statsd);
4344
// Trust the now proxy
4445
app.set('trust proxy', true);
4546
app.use(toobusy);
47+
// Allow bursts of up to 40 req for initial page loads, but block more than 40 / 10s
48+
app.use(
49+
rateLimiter({
50+
max: 40,
51+
duration: '10s',
52+
})
53+
);
4654

4755
// Security middleware.
4856
addSecurityMiddleware(app, { enableNonce: false, enableCSP: false });

api/mutations/thread/editThread.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @flow
2+
const debug = require('debug')('api:mutations:edit-thread');
23
import type { GraphQLContext } from '../../';
34
import type { EditThreadInput } from '../../models/thread';
45
import UserError from '../../utils/UserError';
@@ -7,6 +8,7 @@ import { getThreads, editThread } from '../../models/thread';
78
import { getUserPermissionsInCommunity } from '../../models/usersCommunities';
89
import { getUserPermissionsInChannel } from '../../models/usersChannels';
910
import { isAuthedResolver as requireAuth } from '../../utils/permissions';
11+
import processThreadContent from 'shared/draft-utils/process-thread-content';
1012
import { events } from 'shared/analytics';
1113
import { trackQueue } from 'shared/bull/queues';
1214
import {
@@ -83,6 +85,8 @@ export default requireAuth(async (_: any, args: Input, ctx: GraphQLContext) => {
8385
);
8486
}
8587

88+
input.content.body = processThreadContent('TEXT', input.content.body || '');
89+
8690
/*
8791
When threads are sent to the client, all image urls are signed and proxied
8892
via imgix. If a user edits the thread, we have to restore all image upload
@@ -130,6 +134,7 @@ export default requireAuth(async (_: any, args: Input, ctx: GraphQLContext) => {
130134
});
131135
}
132136

137+
debug('store new body to database:', initialBody);
133138
const newInput = Object.assign({}, input, {
134139
...input,
135140
content: {

api/mutations/thread/publishThread.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ export default requireAuth(
197197

198198
const checkForSpam = usersPreviousPublishedThreads.map(t => {
199199
if (!t) return false;
200+
if (
201+
usersPreviousPublishedThreads.length === 1 &&
202+
usersPreviousPublishedThreads[0] &&
203+
usersPreviousPublishedThreads[0].deletedAt
204+
)
205+
return false;
200206

201207
const incomingTitle = thread.content.title;
202208
const thisTitle = t.content.title;

api/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"dependencies": {
66
"algoliasearch": "^3.32.0",
77
"apollo-local-query": "^0.3.1",
8-
"apollo-server-express": "^2.4.2",
8+
"apollo-server-express": "^2.4.6",
99
"apollo-upload-client": "^9.1.0",
1010
"aws-sdk": "2.200.0",
1111
"axios": "^0.16.2",
@@ -71,7 +71,7 @@
7171
"iterall": "^1.2.2",
7272
"jest": "^21.2.1",
7373
"json-stringify-pretty-compact": "^1.2.0",
74-
"jsonwebtoken": "^8.4.0",
74+
"jsonwebtoken": "^8.5.0",
7575
"keygrip": "^1.0.3",
7676
"linkify-it": "^2.1.0",
7777
"localstorage-memory": "^1.0.3",
@@ -92,6 +92,7 @@
9292
"pre-commit": "^1.2.2",
9393
"prismjs": "^1.15.0",
9494
"query-string": "5.1.1",
95+
"ratelimiter": "^3.2.0",
9596
"raven": "^2.6.4",
9697
"react": "^15.4.1",
9798
"react-app-rewire-styled-components": "^3.0.2",

0 commit comments

Comments
 (0)