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

Commit

Permalink
Merge pull request #2882 from withspectrum/2.2.6
Browse files Browse the repository at this point in the history
2.2.6
  • Loading branch information
brianlovin authored Apr 16, 2018
2 parents 17b294f + bffba60 commit 1f14d80
Show file tree
Hide file tree
Showing 207 changed files with 4,947 additions and 2,756 deletions.
20 changes: 10 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ aliases:
name: Setup and build
command:
|
node -e "const setup = require('./shared/testing/setup.js')().then(() => process.exit())"
yarn run build:web
yarn run build:api

- &start-api
name: Start the API in the background
command: TEST_DB=true yarn run dev:api
command: yarn run start:api:test
background: true

- &start-web
Expand Down Expand Up @@ -90,28 +89,28 @@ jobs:
- image: circleci/node:8-browsers
- image: redis:3.2.7
- image: cypress/base:6
- image: rethinkdb:2.3.5
environment:
TERM: xterm
steps:
- attach_workspace:
at: ~/spectrum
- run: *install-rethinkdb
- run: *start-rethinkdb
- run: sleep 10
- run: node -e "const setup = require('./shared/testing/setup.js')().then(() => process.exit())"
- run: *setup-and-build-web
- run: *start-api
- run: *start-web
- run: sleep 60
# Wait for the API and webserver to start
- run: ./node_modules/.bin/wait-on http://localhost:3000 http://localhost:3001
- run:
name: Run Unit Tests
command: yarn run test:ci
- run:
name: Run E2E Tests
command: yarn run test:e2e
- run:
name: Danger
when: always
command: yarn run danger ci
command: test -z $DANGER_GITHUB_API_TOKEN && yarn run danger ci || echo "forks are not allowed to run danger"
- run:
name: Run E2E Tests
command: yarn run test:e2e

# Run eslint, flow etc.
test_static_js:
Expand Down Expand Up @@ -170,6 +169,7 @@ workflows:
- test_mobile_js:
requires:
- checkout_environment

# Disabled as Expo is fixing their critical issue with Detox
# - test_mobile_native:
# requires:
Expand Down
16 changes: 14 additions & 2 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
[ignore]
.*/node_modules/.*
.*/build.*
.*/*.test.js
.*/.expo
.*/node_modules/expo
.*/node_modules/react-native
.*/node_modules/cypress
.*/node_modules/draft-js
.*/node_modules/graphql
.*/node_modules/protobufjs-no-cli
.*/node_modules/react-navigation
.*/node_modules/reqwest
.*/node_modules/sentry-expo

.*/node_modules/react-apollo
.*/node_modules/dataloader


[include]

Expand All @@ -13,7 +25,7 @@ suppress_comment=.*\\$FlowFixMe
suppress_comment=.*\\$FlowIssue
esproposal.class_instance_fields=enable
module.system.node.resolve_dirname=node_modules
module.system.node.resolve_dirname=spectrum
module.system.node.resolve_dirname=.
module.file_ext=.ios.js
module.file_ext=.android.js
module.file_ext=.native.js
Expand Down
5 changes: 5 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ YES
**Release notes for users (delete if codebase-only change)**
-

<!--
If your pull request introduces changes to the user interface on Spectrum, please share before and after screenshots of the changes (gifs or videos are encouraged for interaction changes). Please include screenshots of desktop and mobile viewports to ensure that all responsive cases are reviewed.
-->
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ build
.DS_Store
src/config/FirebaseConfig.js
npm-debug.log
yarn-error.log
rethinkdb_data
debug
now-secrets.json
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ Spectrum has been under full-time development since March, 2017. See [the roadma
- [Running the app locally](#running-the-app-locally)
- [Roadmap](https://github.com/withspectrum/spectrum/projects/19)
- [Technical](docs/)
- [Testing](docs/testing.md)
- [Testing](docs/testing/intro.md)
- [Background Jobs](docs/backend/background-jobs.md)
- [Deployment](docs/backend/deployment.md)
- [Deployment](docs/deployments.md)
- [API](docs/backend/api/)
- [Fragments](docs/backend/api/fragments.md)
- [Pagination](docs/backend/api/pagination.md)
Expand Down Expand Up @@ -151,6 +151,11 @@ The first step to running Spectrum locally is downloading the code by cloning th

```sh
git clone [email protected]:withspectrum/spectrum.git
```
If you get `Permission denied` error using `ssh` refer [here](https://help.github.com/articles/error-permission-denied-publickey/)
or use `https` link as a fallback.
```sh
git clone https://github.com/withspectrum/spectrum.git
```

#### Installation
Expand Down
12 changes: 10 additions & 2 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
/**
* The entry point for the server, this is where everything starts
*/
console.log('Server starting...');
const compression = require('compression');
const debug = require('debug')('api');
debug('Server starting...');
debug('logging with debug enabled!');
import { createServer } from 'http';
import express from 'express';
Expand Down Expand Up @@ -62,6 +62,14 @@ app.use(
}
);

app.use('/', (req: express$Request, res: express$Response) => {
res.redirect(
process.env.NODE_ENV === 'production' && !process.env.FORCE_DEV
? 'https://spectrum.chat'
: 'http://localhost:3000'
);
});

import type { Loader } from './loaders/types';
export type GraphQLContext = {
user: DBUser,
Expand Down Expand Up @@ -96,7 +104,7 @@ const subscriptionsServer = createSubscriptionsServer(server, '/websocket');
// graphqlPaths: ['/api'],
// });
server.listen(PORT);
console.log(`GraphQL server running at http://localhost:${PORT}/api`);
debug(`GraphQL server running at http://localhost:${PORT}/api`);

process.on('unhandledRejection', async err => {
console.error('Unhandled rejection', err);
Expand Down
27 changes: 27 additions & 0 deletions api/migrations/20180411183454-lowercase-all-the-slugs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
exports.up = async (r, conn) => {
return Promise.all([
r
.table('users')
.update({
username: r.row('username').downcase(),
email: r.row('email').downcase(),
})
.run(conn),
r
.table('communities')
.update({
slug: r.row('slug').downcase(),
})
.run(conn),
r
.table('channels')
.update({
slug: r.row('slug').downcase(),
})
.run(conn),
]);
};

exports.down = function(r, conn) {
return Promise.resolve();
};
3 changes: 2 additions & 1 deletion api/migrations/seed/default/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const defaultDirectMessageThreads = require('./directMessageThreads');
const defaultUsersDirectMessageThreads = require('./usersDirectMessageThreads');
const defaultUsersCommunities = require('./usersCommunities');
const defaultUsersChannels = require('./usersChannels');
const defaultUsersSettings = require('./usersSettings')();
const defaultMessages = require('./messages');

module.exports = {
Expand All @@ -23,8 +24,8 @@ module.exports = {
defaultUsersCommunities,
defaultUsersChannels,
defaultMessages,
defaultUsersSettings,
defaultNotifications: [],
defaultCommunitySettings: [],
defaultChannelSettings: [],
defaultUsersSettings: [],
};
33 changes: 33 additions & 0 deletions api/migrations/seed/default/usersSettings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// @flow

module.exports = () => {
let settings = [];
for (let step = 0; step < 10; step++) {
settings.push({
userId: step.toString(),
notifications: {
types: {
newMessageInThreads: {
email: true,
},
newMention: {
email: true,
},
newDirectMessage: {
email: true,
},
newThreadCreated: {
email: true,
},
dailyDigest: {
email: true,
},
weeklyDigest: {
email: true,
},
},
},
});
}
return settings;
};
9 changes: 9 additions & 0 deletions api/models/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ const config = IS_PROD

var r = require('rethinkdbdash')(config);

// Exit the process on unhealthy db in test env
if (process.env.TEST_DB) {
r.getPoolMaster().on('healthy', healthy => {
if (!healthy) {
process.exit(1);
}
});
}

if (process.env.NODE_ENV === 'development') {
const fs = require('fs');
const inspect = require('rethinkdb-inspector');
Expand Down
27 changes: 14 additions & 13 deletions api/models/thread.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
// @flow
const { db } = require('./db');
import intersection from 'lodash.intersection';
import {
processReputationEventQueue,
sendThreadNotificationQueue,
_adminProcessToxicThreadQueue,
} from 'shared/bull/queues';
import { processReputationEventQueue } from 'shared/bull/queues';
const { NEW_DOCUMENTS, parseRange } = require('./utils');
import { createChangefeed } from 'shared/changefeed-utils';
import { deleteMessagesInThread } from '../models/message';
Expand Down Expand Up @@ -114,6 +110,19 @@ export const getThreadsInTimeframe = (
.run();
};

// We do not filter by deleted threads intentionally to prevent users from spam
// creating/deleting threads
export const getThreadsByUserAsSpamCheck = (
userId: string,
timeframe: number = 60 * 10
): Promise<Array<?DBThread>> => {
return db
.table('threads')
.getAll(userId, { index: 'creatorId' })
.filter(db.row('createdAt').during(db.now().sub(timeframe), db.now()))
.run();
};

/*
When viewing a user profile we have to take two arguments into account:
1. The user who is being viewed
Expand Down Expand Up @@ -313,14 +322,6 @@ export const publishThread = (
.run()
.then(result => {
const thread = result.changes[0].new_val;
sendThreadNotificationQueue.add({ thread });
processReputationEventQueue.add({
userId,
type: 'thread created',
entityId: thread.id,
});
_adminProcessToxicThreadQueue.add({ thread });

return thread;
});
};
Expand Down
42 changes: 28 additions & 14 deletions api/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,6 @@ const getUsers = (userIds: Array<string>): Promise<Array<DBUser>> => {
.run();
};

const getUsersBySearchString = (string: string): Promise<Array<DBUser>> => {
return (
db
.table('users')
// get users whose username or displayname matches a case insensitive string
.filter(user => user.coerceTo('string').match(`(?i)${string}`))
// only return the 10 users who match to avoid overloading the dom and sending
// down too much data at once
.limit(10)
.run()
);
};

const storeUser = (user: Object): Promise<DBUser> => {
return db
.table('users')
Expand Down Expand Up @@ -448,6 +435,33 @@ const updateUserEmail = (userId: string, email: string): Promise<Object> => {
.then(() => getUserById(userId));
};

const deleteUser = (userId: string) => {
return db
.table('users')
.get(userId)
.update({
username: null,
email: null,
deletedAt: new Date(),
providerId: null,
fbProviderId: null,
googleProviderId: null,
githubProviderId: null,
githubUsername: null,
profilePhoto: null,
description: null,
website: null,
timezone: null,
lastSeen: null,
modifiedAt: null,
firstName: null,
lastName: null,
pendingEmail: null,
name: 'Deleted',
})
.run();
};

module.exports = {
getUser,
getUserById,
Expand All @@ -456,7 +470,6 @@ module.exports = {
getUsersByUsername,
getUsersThreadCount,
getUsers,
getUsersBySearchString,
getUserByIndex,
saveUserProvider,
createOrFindUser,
Expand All @@ -466,4 +479,5 @@ module.exports = {
setUserOnline,
setUserPendingEmail,
updateUserEmail,
deleteUser,
};
Loading

0 comments on commit 1f14d80

Please sign in to comment.