Skip to content

Commit 21f481a

Browse files
Merge pull request #441 from topcoder-platform/develop
Prod release
2 parents 3d55210 + 5c6d279 commit 21f481a

16 files changed

+6642
-23450
lines changed

README.md

Lines changed: 66 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -81,50 +81,82 @@ You can find sample `.env` files inside the `/docs` directory.
8181
5. View table data in default environment: `npm run view-data <ModelName>`, ModelName can be `Challenge`, `ChallengeType`, `AuditLog`, `Phase`, `TimelineTemplate`or `Attachment`
8282
6. Create Elasticsearch index: `npm run init-es`, or to re-create index: `npm run init-es force`
8383
7. Synchronize ES data and DynamoDB data: `npm run sync-es`
84+
8. Start all the depending services for local deployment: `npm run services:up`
85+
9. Stop all the depending services for local deployment: `npm run services:down`
86+
10. Check the logs of all the depending services for local deployment: `npm run services:logs`
87+
11. Initialize the local environments: `npm run local:init`
88+
12. Reset the local environments: `npm run local:reset`
89+
8490

8591
### Notes
8692
- The seed data are located in `src/scripts/seed`
8793

8894
## Local Deployment
95+
0. Make sure to use Node v10+ by command `node -v`. We recommend using [NVM](https://github.com/nvm-sh/nvm) to quickly switch to the right version:
96+
97+
```bash
98+
nvm use
99+
```
100+
101+
1. 📦 Install npm dependencies
102+
103+
```bash
104+
npm install
105+
```
106+
107+
2. ⚙ Local config
108+
In the `challenge-api` root directory create `.env` file with the next environment variables. Values for **Auth0 config** should be shared with you on the forum.<br>
109+
```bash
110+
# Auth0 config
111+
AUTH0_URL=
112+
AUTH0_PROXY_SERVER_URL=
113+
AUTH0_AUDIENCE=
114+
AUTH0_CLIENT_ID=
115+
AUTH0_CLIENT_SECRET=
116+
117+
# Locally deployed services (via docker-compose)
118+
IS_LOCAL_DB=true
119+
DYNAMODB_URL=http://localhost:8000
120+
```
121+
122+
- Values from this file would be automatically used by many `npm` commands.
123+
- ⚠️ Never commit this file or its copy to the repository!
124+
125+
3. 🚢 Start docker-compose with services which are required to start Topcoder Challenges API locally
126+
127+
```bash
128+
npm run services:up
129+
```
130+
131+
4. ♻ Update following two parts:
132+
- https://github.com/topcoder-platform/challenge-api/blob/develop/src/models/Challenge.js#L116
133+
`throughput: 'ON_DEMAND',` should be updated to `throughput:{ read: 4, write: 2 },`
134+
- https://github.com/topcoder-platform/challenge-api/blob/develop/config/default.js#L27-L28
89135

90-
### AWS S3 Setup
91-
Go to https://console.aws.amazon.com/ and login. Choose S3 from Service folder and click `Create bucket`. Following the instruction to create S3 bucket.
136+
5. ♻ Create tables.
92137

93-
### Local services setup
94-
In the `local` folder, run `docker-compose up` to start Elasticsearch, DynamoDB, S3 compatible server and Mock API.
138+
```bash
139+
npm run create-tables
140+
# Use `npm run drop-tables` to drop tables.
141+
```
95142

96-
### Create Tables
97-
1. Make sure DynamoDB are running as per instructions above.
98-
2. Make sure you have configured all config parameters. Refer [Configuration](#configuration)
99-
3. Run `npm run create-tables` to create tables.
143+
6. ♻ Init DB, ES
100144

101-
### Mock API
102-
The provided mock API provides mock endpoint to fetch challenge resources and groups so you don't have to deploy the related services locally.
103-
You need to ensure DynamoDB configuration in `mock-api/config/default.js` is consistent with `config/default.js`
104-
Mock API starts after running `docker-compose up` and expose port 4000.
145+
```bash
146+
npm run local:init
147+
```
105148

106-
### Notes
107-
There are two parts need to be updated for local development
108-
- https://github.com/topcoder-platform/challenge-api/blob/develop/src/models/Challenge.js#L116
109-
`throughput: 'ON_DEMAND',` should be updated to `throughput:{ read: 4, write: 2 },`
110-
- https://github.com/topcoder-platform/challenge-api/blob/develop/config/default.js#L27-L28
111-
Two aws config should be uncommented
112-
113-
and AUTH0 related configuration must be set at config file or in env variables.
114-
115-
### Deploy the app
116-
117-
- Follow the Notes section above
118-
- Install dependencies `npm install`
119-
- Run lint `npm run lint`
120-
- Run lint fix `npm run lint:fix`
121-
- initialize Elasticsearch, create configured Elasticsearch index if not present: `npm run init-es`,
122-
or re-create the index: `npm run init-es force`
123-
- Create tables `npm run create-tables`
124-
- Clear and init db `npm run init-db`
125-
- Seed tables: `npm run seed-tables`
126-
- Start app `npm start`
127-
- App is running at `http://localhost:3000`
149+
This command will do 3 things:
150+
- create Elasticsearch indexes (drop if exists)
151+
- Initialize the database by cleaning all the records.
152+
- Import the data to the local database and index it to ElasticSearch
153+
154+
7. 🚀 Start Topcoder Challenge API
155+
156+
```bash
157+
npm start
158+
```
159+
The Topcoder Challenge API will be served on `http://localhost:3000`
128160

129161
## Production deployment
130162

Verification.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# TopCoder Challenge API Verification
22

3-
## Postman tests
4-
- clear the environment, run command `npm run init-db` and `npm run init-es force`
5-
- import Postman collection and environment in the docs folder to Postman
6-
- run tests from up to down in order
7-
- You need to run command `npm run sync-es` before you run `Challenges/get challenge` and `Challenges/search challenge` test case.
3+
## E2E Postman tests
4+
- Import Postman collection and environment in the docs folder to Postman
5+
- Set `token` variable in environment variables folder
6+
- Open Runner
7+
- Put E2E Test Folder inside Runner
8+
- Set `Delay` to 2000ms
9+
- Check `Save Responses`
10+
- Start Run
811

912
## DynamoDB Verification
1013
Run command `npm run view-data <ModelName>` to view table data, ModelName can be `Challenge`, `ChallengeType`, `AuditLog`, `Phase`, `TimelineTemplate`, `Attachment` or `ChallengeTimelineTemplate`

app-constants.js

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
const config = require('config')
2+
13
/**
24
* App constants
35
*/
46
const UserRoles = {
57
Admin: 'administrator',
68
Copilot: 'copilot',
79
Manager: 'Connect Manager',
8-
User: 'Topcoder User'
10+
User: 'Topcoder User',
11+
SelfServiceCustomer: 'Self-Service Customer'
912
}
1013

1114
const prizeSetTypes = {
@@ -18,6 +21,7 @@ const prizeSetTypes = {
1821
const challengeStatuses = {
1922
New: 'New',
2023
Draft: 'Draft',
24+
Approved: 'Approved',
2125
Cancelled: 'Cancelled',
2226
Active: 'Active',
2327
Completed: 'Completed',
@@ -28,7 +32,8 @@ const challengeStatuses = {
2832
CancelledWinnerUnresponsive: 'Cancelled - Winner Unresponsive',
2933
CancelledClientRequest: 'Cancelled - Client Request',
3034
CancelledRequirementsInfeasible: 'Cancelled - Requirements Infeasible',
31-
CancelledZeroRegistrations: 'Cancelled - Zero Registrations'
35+
CancelledZeroRegistrations: 'Cancelled - Zero Registrations',
36+
CancelledPaymentFailed: 'Cancelled - Payment Failed'
3237
}
3338

3439
const validChallengeParams = {
@@ -70,7 +75,9 @@ const Topics = {
7075
ChallengeTypeTimelineTemplateDeleted: 'test.new.bus.events', // 'challenge.action.type.timeline.template.deleted'
7176
ChallengeAttachmentCreated: 'test.new.bus.events', // 'challenge.action.attachment.created',
7277
ChallengeAttachmentUpdated: 'test.new.bus.events', // 'challenge.action.attachment.updated',
73-
ChallengeAttachmentDeleted: 'test.new.bus.events' // 'challenge.action.attachment.deleted',
78+
ChallengeAttachmentDeleted: 'test.new.bus.events', // 'challenge.action.attachment.deleted',
79+
// Self Service topics
80+
Notifications: 'notifications.action.create'
7481
}
7582

7683
const challengeTracks = {
@@ -90,6 +97,32 @@ const reviewTypes = {
9097
Internal: 'INTERNAL'
9198
}
9299

100+
const SelfServiceNotificationTypes = {
101+
WORK_REQUEST_SUBMITTED: 'self-service.notifications.work-request-submitted',
102+
WORK_REQUEST_STARTED: 'self-service.notifications.work-request-started',
103+
WORK_REQUEST_REDIRECTED: 'self-service.notifications.work-request-redirected',
104+
WORK_COMPLETED: 'self-service.notifications.work-completed'
105+
}
106+
107+
const SelfServiceNotificationSettings = {
108+
[SelfServiceNotificationTypes.WORK_REQUEST_SUBMITTED]: {
109+
sendgridTemplateId: config.SENDGRID_TEMPLATES.WORK_REQUEST_SUBMITTED,
110+
cc: []
111+
},
112+
[SelfServiceNotificationTypes.WORK_REQUEST_STARTED]: {
113+
sendgridTemplateId: config.SENDGRID_TEMPLATES.WORK_REQUEST_STARTED,
114+
cc: []
115+
},
116+
[SelfServiceNotificationTypes.WORK_REQUEST_REDIRECTED]: {
117+
sendgridTemplateId: config.SENDGRID_TEMPLATES.WORK_REQUEST_REDIRECTED,
118+
cc: [...config.SELF_SERVICE_EMAIL_CC_ACCOUNTS]
119+
},
120+
[SelfServiceNotificationTypes.WORK_COMPLETED]: {
121+
sendgridTemplateId: config.SENDGRID_TEMPLATES.WORK_COMPLETED,
122+
cc: []
123+
}
124+
}
125+
93126
module.exports = {
94127
UserRoles,
95128
prizeSetTypes,
@@ -101,5 +134,7 @@ module.exports = {
101134
challengeTracks,
102135
challengeTextSortField,
103136
DiscussionTypes,
104-
reviewTypes
137+
reviewTypes,
138+
SelfServiceNotificationTypes,
139+
SelfServiceNotificationSettings
105140
}

app-routes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ module.exports = (app) => {
5050
next(new errors.ForbiddenError('You are not allowed to perform this action!'))
5151
} else {
5252
req.authUser.handle = config.M2M_AUDIT_HANDLE
53+
req.userToken = req.headers.authorization.split(' ')[1]
5354
next()
5455
}
5556
} else {

config/default.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/**
22
* The configuration file.
33
*/
4-
4+
const _ = require('lodash')
5+
require('dotenv').config()
56
module.exports = {
67
READONLY: process.env.READONLY === 'true' || false,
78
LOG_LEVEL: process.env.LOG_LEVEL || 'debug',
@@ -57,13 +58,15 @@ module.exports = {
5758
GROUPS_API_URL: process.env.GROUPS_API_URL || 'http://localhost:4000/v5/groups',
5859
PROJECTS_API_URL: process.env.PROJECTS_API_URL || 'http://localhost:4000/v5/projects',
5960
TERMS_API_URL: process.env.TERMS_API_URL || 'http://localhost:4000/v5/terms',
61+
CUSTOMER_PAYMENTS_URL: process.env.CUSTOMER_PAYMENTS_URL || 'https://api.topcoder-dev.com/v5/customer-payments',
6062
// copilot resource role ids allowed to upload attachment
6163
COPILOT_RESOURCE_ROLE_IDS: process.env.COPILOT_RESOURCE_ROLE_IDS
6264
? process.env.COPILOT_RESOURCE_ROLE_IDS.split(',') : ['10ba038e-48da-487b-96e8-8d3b99b6d18b'],
6365
SUBMITTER_ROLE_ID: process.env.SUBMITTER_ROLE_ID || '732339e7-8e30-49d7-9198-cccf9451e221',
6466

6567
MANAGER_ROLE_ID: process.env.MANAGER_ROLE_ID || '0e9c6879-39e4-4eb6-b8df-92407890faf1',
6668
OBSERVER_ROLE_ID: process.env.OBSERVER_ROLE_ID || '2a4dc376-a31c-4d00-b173-13934d89e286',
69+
CLIENT_MANAGER_ROLE_ID: process.env.OBSERVER_ROLE_ID || '9b2f1905-8128-42da-85df-ed64410f4781',
6770

6871
// health check timeout in milliseconds
6972
HEALTH_CHECK_TIMEOUT: process.env.HEALTH_CHECK_TIMEOUT || 3000,
@@ -80,5 +83,24 @@ module.exports = {
8083

8184
M2M_AUDIT_HANDLE: process.env.M2M_AUDIT_HANDLE || 'tcwebservice',
8285

83-
FORUM_TITLE_LENGTH_LIMIT: process.env.FORUM_TITLE_LENGTH_LIMIT || 90
86+
FORUM_TITLE_LENGTH_LIMIT: process.env.FORUM_TITLE_LENGTH_LIMIT || 90,
87+
88+
NEW_SELF_SERVICE_PROJECT_TYPE: process.env.NEW_SELF_SERVICE_PROJECT_TYPE || 'self-service',
89+
90+
SENDGRID_TEMPLATES: {
91+
WORK_REQUEST_SUBMITTED: process.env.WORK_REQUEST_SUBMITTED || '',
92+
WORK_REQUEST_STARTED: process.env.WORK_REQUEST_STARTED || '',
93+
WORK_REQUEST_REDIRECTED: process.env.WORK_REQUEST_REDIRECTED || '',
94+
WORK_COMPLETED: process.env.WORK_COMPLETED || ''
95+
},
96+
97+
EMAIL_FROM: process.env.EMAIL_FROM || 'no-reply@topcoder.com',
98+
SELF_SERVICE_EMAIL_CC_ACCOUNTS: process.env.SELF_SERVICE_EMAIL_CC_ACCOUNTS ? _.map(process.env.SELF_SERVICE_EMAIL_CC_ACCOUNTS.split(','), email => ({ email })) : ['sathya.jayabal@gmail.com'],
99+
SELF_SERVICE_WHITELIST_HANDLES: process.env.SELF_SERVICE_WHITELIST_HANDLES ? process.env.SELF_SERVICE_WHITELIST_HANDLES.split(',') : ['TCConnCopilot', 'sstestcopilot'],
100+
SELF_SERVICE_APP_URL: process.env.SELF_SERVICE_APP_URL || 'https://platform.topcoder-dev.com/self-service',
101+
102+
ZENDESK_API_TOKEN: process.env.ZENDESK_API_TOKEN || '',
103+
ZENDESK_API_URL: process.env.ZENDESK_API_URL || '',
104+
ZENDESK_CUSTOM_FIELD_TAG_ID: process.env.ZENDESK_CUSTOM_FIELD_TAG_ID,
105+
ZENDESK_DEFAULT_PRIORITY: process.env.ZENDESK_DEFAULT_PRIORITY || 'high'
84106
}

0 commit comments

Comments
 (0)