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

Commit e3b4fec

Browse files
authored
Merge pull request #3001 from withspectrum/2.2.9
2.2.9
2 parents 4286a58 + 1acefa3 commit e3b4fec

File tree

162 files changed

+4592
-2907
lines changed

Some content is hidden

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

162 files changed

+4592
-2907
lines changed

.circleci/config.yml

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,15 @@ aliases:
3636
background: true
3737

3838
- &setup-and-build-web
39-
name: Setup and build
39+
name: Setup and build web
4040
command:
4141
|
4242
cp now-secrets.example.json now-secrets.json
4343
yarn run build:web
44-
yarn run build:api
44+
45+
- &build-api
46+
name: Build API
47+
command: yarn run build:api
4548

4649
- &start-api
4750
name: Start the API in the background
@@ -98,21 +101,37 @@ jobs:
98101
at: ~/spectrum
99102
- run: node -e "const setup = require('./shared/testing/setup.js')().then(() => process.exit())"
100103
- run: *setup-and-build-web
104+
- run: *build-api
101105
- run: *start-api
102106
- run: *start-web
103107
# Wait for the API and webserver to start
104108
- run: ./node_modules/.bin/wait-on http://localhost:3000 http://localhost:3001
105109
- run:
106110
name: Run Unit Tests
107111
command: yarn run test:ci
108-
- run:
109-
name: Danger
110-
when: always
111-
command: test $DANGER_GITHUB_API_TOKEN && yarn run danger ci || echo "forks are not allowed to run danger"
112112
- run:
113113
name: Run E2E Tests
114114
command: test $CYPRESS_RECORD_KEY && yarn run test:e2e -- --record || yarn run test:e2e
115115

116+
deploy_alpha:
117+
<<: *js_defaults
118+
docker:
119+
- image: circleci/node:8-browsers
120+
steps:
121+
- attach_workspace:
122+
at: ~/spectrum
123+
- run: *build-api
124+
- run:
125+
name: Deploy and alias API
126+
command: |
127+
cd build-api
128+
npx now-cd --alias "alpha=api.alpha.spectrum.chat" --team spaceprogram
129+
cd ..
130+
- run:
131+
name: Deploy and alias Hyperion
132+
command: npx now-cd --alias "alpha=hyperion.alpha.spectrum.chat" --team spaceprogram
133+
134+
116135
# Run eslint, flow etc.
117136
test_static_js:
118137
<<: *js_defaults
@@ -181,3 +200,10 @@ workflows:
181200
- test_static_js:
182201
requires:
183202
- checkout_environment
203+
- deploy_alpha:
204+
requires:
205+
- test_static_js
206+
- test_web
207+
filters:
208+
branches:
209+
only: alpha

admin/README.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ To configure the syntax highlighting in your favorite text editor, head to the [
213213

214214
## Displaying Lint Output in the Editor
215215

216-
>Note: this feature is available with `[email protected]` and higher.<br>
217-
>It also only works with npm 3 or higher.
216+
> Note: this feature is available with `[email protected]` and higher.<br>
217+
> It also only works with npm 3 or higher.
218218
219219
Some editors, including Sublime Text, Atom, and Visual Studio Code, provide plugins for ESLint.
220220

@@ -464,7 +464,7 @@ Then in `package.json`, add the following lines to `scripts`:
464464
"test": "react-scripts test --env=jsdom",
465465
```
466466

467-
>Note: To use a different preprocessor, replace `build-css` and `watch-css` commands according to your preprocessor’s documentation.
467+
> Note: To use a different preprocessor, replace `build-css` and `watch-css` commands according to your preprocessor’s documentation.
468468
469469
Now you can rename `src/App.css` to `src/App.scss` and run `npm run watch-css`. The watcher will find every Sass file in `src` subdirectories, and create a corresponding CSS file next to it, in our case overwriting `src/App.css`. Since `src/App.js` still imports `src/App.css`, the styles become a part of your application. You can now edit `src/App.scss`, and `src/App.css` will be regenerated.
470470

@@ -565,7 +565,7 @@ An alternative way of handling static assets is described in the next section.
565565

566566
## Using the `public` Folder
567567

568-
>Note: this feature is available with `[email protected]` and higher.
568+
> Note: this feature is available with `[email protected]` and higher.
569569
570570
### Changing the HTML
571571

@@ -586,7 +586,7 @@ This mechanism provides a number of benefits:
586586

587587
However there is an **escape hatch** that you can use to add an asset outside of the module system.
588588

589-
If you put a file into the `public` folder, it will **not** be processed by Webpack. Instead it will be copied into the build folder untouched. To reference assets in the `public` folder, you need to use a special variable called `PUBLIC_URL`.
589+
If you put a file into the `public` folder, it will **not** be processed by Webpack. Instead it will be copied into the build folder untouched. To reference assets in the `public` folder, you need to use a special variable called `PUBLIC_URL`.
590590

591591
Inside `index.html`, you can use it like this:
592592

@@ -701,15 +701,15 @@ To learn more about Flow, check out [its documentation](https://flowtype.org/).
701701

702702
## Adding Custom Environment Variables
703703

704-
>Note: this feature is available with `[email protected]` and higher.
704+
> Note: this feature is available with `[email protected]` and higher.
705705
706706
Your project can consume variables declared in your environment as if they were declared locally in your JS files. By
707707
default you will have `NODE_ENV` defined for you, and any other environment variables starting with
708708
`REACT_APP_`.
709709

710710
**The environment variables are embedded during the build time**. Since Create React App produces a static HTML/CSS/JS bundle, it can’t possibly read them at runtime. To read them at runtime, you would need to load HTML into memory on the server and replace placeholders in runtime, just like [described here](#injecting-data-from-the-server-into-the-page). Alternatively you can rebuild the app on the server anytime you change them.
711711

712-
>Note: You must create custom environment variables beginning with `REACT_APP_`. Any other variables except `NODE_ENV` will be ignored to avoid accidentally [exposing a private key on the machine that could have the same name](https://github.com/facebookincubator/create-react-app/issues/865#issuecomment-252199527). Changing any environment variables will require you to restart the development server if it is running.
712+
> Note: You must create custom environment variables beginning with `REACT_APP_`. Any other variables except `NODE_ENV` will be ignored to avoid accidentally [exposing a private key on the machine that could have the same name](https://github.com/facebookincubator/create-react-app/issues/865#issuecomment-252199527). Changing any environment variables will require you to restart the development server if it is running.
713713
714714
These environment variables will be defined for you on `process.env`. For example, having an environment
715715
variable named `REACT_APP_SECRET_CODE` will be exposed in your JS as `process.env.REACT_APP_SECRET_CODE`.
@@ -764,7 +764,7 @@ When you compile the app with `npm run build`, the minification step will strip
764764

765765
### Referencing Environment Variables in the HTML
766766

767-
>Note: this feature is available with `[email protected]` and higher.
767+
> Note: this feature is available with `[email protected]` and higher.
768768
769769
You can also access the environment variables starting with `REACT_APP_` in the `public/index.html`. For example:
770770

@@ -798,7 +798,7 @@ REACT_APP_SECRET_CODE=abcdef npm start
798798

799799
### Adding Development Environment Variables In `.env`
800800

801-
>Note: this feature is available with `[email protected]` and higher.
801+
> Note: this feature is available with `[email protected]` and higher.
802802
803803
To define permanent environment variables, create a file called `.env` in the root of your project:
804804

@@ -810,7 +810,7 @@ REACT_APP_SECRET_CODE=abcdef
810810

811811
#### What other `.env` files are can be used?
812812

813-
>Note: this feature is **available with `[email protected]` and higher**.
813+
> Note: this feature is **available with `[email protected]` and higher**.
814814
815815
* `.env`: Default.
816816
* `.env.local`: Local overrides. **This file is loaded for all environments except test.**
@@ -826,7 +826,7 @@ Files on the left have more priority than files on the right:
826826
These variables will act as the defaults if the machine does not explicitly set them.<br>
827827
Please refer to the [dotenv documentation](https://github.com/motdotla/dotenv) for more details.
828828

829-
>Note: If you are defining environment variables for development, your CI and/or hosting platform will most likely need
829+
> Note: If you are defining environment variables for development, your CI and/or hosting platform will most likely need
830830
these defined as well. Consult their documentation how to do this. For example, see the documentation for [Travis CI](https://docs.travis-ci.com/user/environment-variables/) or [Heroku](https://devcenter.heroku.com/articles/config-vars).
831831

832832
## Can I Use Decorators?
@@ -862,7 +862,7 @@ You can find the companion GitHub repository [here](https://github.com/fullstack
862862

863863
## Proxying API Requests in Development
864864

865-
>Note: this feature is available with `[email protected]` and higher.
865+
> Note: this feature is available with `[email protected]` and higher.
866866
867867
People often serve the front-end React app from the same host and port as their backend implementation.<br>
868868
For example, a production setup might look like this after the app is deployed:
@@ -904,7 +904,7 @@ When you enable the `proxy` option, you opt into a more strict set of host check
904904

905905
This shouldn’t affect you when developing on `localhost`, but if you develop remotely like [described here](https://github.com/facebookincubator/create-react-app/issues/2271), you will see this error in the browser after enabling the `proxy` option:
906906

907-
>Invalid Host header
907+
> Invalid Host header
908908
909909
To work around it, you can specify your public development host in a file called `.env.development` in the root of your project:
910910

@@ -926,7 +926,7 @@ We don’t recommend this approach.
926926

927927
### Configuring the Proxy Manually
928928

929-
>Note: this feature is available with `[email protected]` and higher.
929+
> Note: this feature is available with `[email protected]` and higher.
930930
931931
If the `proxy` option is **not** flexible enough for you, you can specify an object in the following form (in `package.json`).<br>
932932
You may also specify any configuration value [`http-proxy-middleware`](https://github.com/chimurai/http-proxy-middleware#options) or [`http-proxy`](https://github.com/nodejitsu/node-http-proxy#options) supports.
@@ -984,7 +984,7 @@ You may also narrow down matches using `*` and/or `**`, to match the path exactl
984984

985985
## Using HTTPS in Development
986986

987-
>Note: this feature is available with `[email protected]` and higher.
987+
> Note: this feature is available with `[email protected]` and higher.
988988
989989
You may require the dev server to serve pages over HTTPS. One particular case where this could be useful is when using [the "proxy" feature](#proxying-api-requests-in-development) to proxy requests to an API server when that API server is itself serving HTTPS.
990990

@@ -1049,7 +1049,7 @@ Then, on the server, you can replace `__SERVER_DATA__` with a JSON of real data
10491049

10501050
## Running Tests
10511051

1052-
>Note: this feature is available with `[email protected]` and higher.<br>
1052+
> Note: this feature is available with `[email protected]` and higher.<br>
10531053
>[Read the migration guide to learn how to enable it in older projects!](https://github.com/facebookincubator/create-react-app/blob/master/CHANGELOG.md#migrating-from-023-to-030)
10541054
10551055
Create React App uses [Jest](https://facebook.github.io/jest/) as its test runner. To prepare for this integration, we did a [major revamp](https://facebook.github.io/jest/blog/2016/09/01/jest-15.html) of Jest so if you heard bad things about it years ago, give it another try.
@@ -1198,7 +1198,7 @@ and then use them in your tests like you normally do.
11981198

11991199
### Initializing Test Environment
12001200

1201-
>Note: this feature is available with `[email protected]` and higher.
1201+
> Note: this feature is available with `[email protected]` and higher.
12021202
12031203
If your app uses a browser API that you need to mock in your tests or if you just need a global setup before running your tests, add a `src/setupTests.js` to your project. It will be automatically executed before running your tests.
12041204

@@ -1281,7 +1281,7 @@ CI=true npm run build
12811281

12821282
The test command will force Jest to run tests once instead of launching the watcher.
12831283

1284-
> If you find yourself doing this often in development, please [file an issue](https://github.com/facebookincubator/create-react-app/issues/new) to tell us about your use case because we want to make watcher the best experience and are open to changing how it works to accommodate more workflows.
1284+
> If you find yourself doing this often in development, please [file an issue](https://github.com/facebookincubator/create-react-app/issues/new) to tell us about your use case because we want to make watcher the best experience and are open to changing how it works to accommodate more workflows.
12851285
12861286
The build command will check for linter warnings and fail if any are found.
12871287

@@ -1561,7 +1561,7 @@ This will let Create React App correctly infer the root path to use in the gener
15611561

15621562
#### Serving the Same Build from Different Paths
15631563

1564-
>Note: this feature is available with `[email protected]` and higher.
1564+
> Note: this feature is available with `[email protected]` and higher.
15651565
15661566
If you are not using the HTML5 `pushState` history API or not using client-side routing at all, it is unnecessary to specify the URL from which your app will be served. Instead, you can put this in your `package.json`:
15671567

@@ -1638,7 +1638,7 @@ For more information see [Add Firebase to your JavaScript Project](https://fireb
16381638
16391639
### GitHub Pages
16401640
1641-
>Note: this feature is available with `[email protected]` and higher.
1641+
> Note: this feature is available with `[email protected]` and higher.
16421642
16431643
#### Step 1: Add `homepage` to `package.json`
16441644
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
exports.up = function(r, conn) {
2+
return Promise.all([
3+
r
4+
.table('slackImports')
5+
.update({
6+
members: r.literal(),
7+
})
8+
.run(conn),
9+
]).catch(err => console.error(err));
10+
};
11+
12+
exports.down = function(r, conn) {
13+
return Promise.resolve();
14+
};

api/models/channelSettings.js

Lines changed: 71 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @flow
22
const { db } = require('./db');
3-
import type { DBChannelSettings } from 'shared/types';
3+
import type { DBChannelSettings, DBChannel } from 'shared/types';
44
import { getChannelById } from './channel';
55
import shortid from 'shortid';
66

@@ -9,24 +9,39 @@ const defaultSettings = {
99
tokenJoinEnabled: false,
1010
message: null,
1111
},
12+
slackSettings: {
13+
botLinks: {
14+
threadCreated: null,
15+
},
16+
},
1217
};
1318

14-
export const getChannelSettings = (id: string) => {
15-
return db
19+
// prettier-ignore
20+
export const getOrCreateChannelSettings = async (channelId: string): Promise<DBChannelSettings> => {
21+
const settings = await db
1622
.table('channelSettings')
17-
.getAll(id, { index: 'channelId' })
18-
.run()
19-
.then(data => {
20-
if (!data || data.length === 0) {
21-
return defaultSettings;
22-
}
23-
return data[0];
24-
});
23+
.getAll(channelId, { index: 'channelId' })
24+
.run();
25+
26+
if (!settings || settings.length === 0) {
27+
return await db
28+
.table('channelSettings')
29+
.insert(
30+
{
31+
...defaultSettings,
32+
channelId,
33+
},
34+
{ returnChanges: true }
35+
)
36+
.run()
37+
.then(results => results.changes[0].new_val);
38+
}
39+
40+
return settings[0];
2541
};
2642

27-
export const getChannelsSettings = (
28-
channelIds: Array<string>
29-
): Promise<?DBChannelSettings> => {
43+
// prettier-ignore
44+
export const getChannelsSettings = (channelIds: Array<string>): Promise<?DBChannelSettings> => {
3045
return db
3146
.table('channelSettings')
3247
.getAll(...channelIds, { index: 'channelId' })
@@ -50,20 +65,6 @@ export const getChannelsSettings = (
5065
});
5166
};
5267

53-
export const createChannelSettings = (id: string) => {
54-
return db
55-
.table('channelSettings')
56-
.insert({
57-
channelId: id,
58-
joinSettings: {
59-
token: null,
60-
tokenJoinEnabled: false,
61-
},
62-
})
63-
.run()
64-
.then(async () => await getChannelById(id));
65-
};
66-
6768
export const enableChannelTokenJoin = (id: string) => {
6869
return db
6970
.table('channelSettings')
@@ -104,3 +105,45 @@ export const resetChannelJoinToken = (id: string) => {
104105
.run()
105106
.then(async () => await getChannelById(id));
106107
};
108+
109+
type UpdateInput = {
110+
channelId: string,
111+
slackChannelId: ?string,
112+
eventType: 'threadCreated',
113+
};
114+
115+
// prettier-ignore
116+
export const updateChannelSlackBotLinks = async ({ channelId, slackChannelId, eventType }: UpdateInput): Promise<DBChannel> => {
117+
const settings: DBChannelSettings = await getOrCreateChannelSettings(
118+
channelId
119+
);
120+
121+
let newSettings;
122+
if (!settings.slackSettings) {
123+
settings.slackSettings = {
124+
botLinks: {
125+
[eventType]:
126+
slackChannelId && slackChannelId.length > 0 ? slackChannelId : null,
127+
},
128+
};
129+
newSettings = Object.assign({}, settings);
130+
} else {
131+
newSettings = Object.assign({}, settings, {
132+
slackSettings: {
133+
botLinks: {
134+
[eventType]:
135+
slackChannelId && slackChannelId.length > 0 ? slackChannelId : null,
136+
},
137+
},
138+
});
139+
}
140+
141+
return db
142+
.table('channelSettings')
143+
.getAll(channelId, { index: 'channelId' })
144+
.update({
145+
...newSettings,
146+
})
147+
.run()
148+
.then(() => getChannelById(channelId));
149+
};

0 commit comments

Comments
 (0)