Skip to content

Commit 27f04a5

Browse files
Merge pull request #106 from topcoder-platform/dev
Dry Release v0.2
2 parents b07b6aa + ef78279 commit 27f04a5

39 files changed

+4344
-551
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The following parameters can be set in config files or in env variables:
2222

2323
- `AUTH0_URL`: Auth0 URL, used to get TC M2M token
2424
- `AUTH0_AUDIENCE`: Auth0 audience, used to get TC M2M token
25-
- `AUTH0_AUDIENCE_FOR_BUS_API`: Auth0 audience, used to get TC M2M token to be used in bus api client
25+
- `AUTH0_AUDIENCE_UBAHN`: Auth0 audience for U-Bahn
2626
- `TOKEN_CACHE_TIME`: Auth0 token cache time, used to get TC M2M token
2727
- `AUTH0_CLIENT_ID`: Auth0 client id, used to get TC M2M token
2828
- `AUTH0_CLIENT_SECRET`: Auth0 client secret, used to get TC M2M token
@@ -36,6 +36,7 @@ The following parameters can be set in config files or in env variables:
3636
- `PROJECT_API_URL`: the project service url
3737
- `TC_API`: the Topcoder v5 url
3838
- `ORG_ID`: the organization id
39+
- `TOPCODER_SKILL_PROVIDER_ID`: the referenced skill provider id
3940

4041
- `esConfig.HOST`: the elasticsearch host
4142
- `esConfig.ES_INDEX_JOB`: the job index
@@ -66,6 +67,19 @@ The following parameters can be set in config files or in env variables:
6667
- Modify `DATABASE_URL` under `config/default.js` to meet your environment.
6768
- Run `npm run init-db` to create table(run `npm run init-db force` to force creating table)
6869

70+
## DB Migration
71+
- `npm run migrate`: run any migration files which haven't run yet.
72+
- `npm run migrate:undo`: revert most recent migration.
73+
74+
Configuration for migration is at `./config/config.json`.
75+
76+
The following parameters can be set in the config file or via env variables:
77+
78+
- `username`: set via env `DB_USERNAME`; datebase username
79+
- `password`: set via env `DB_PASSWORD`; datebase password
80+
- `database`: set via env `DB_NAME`; datebase name
81+
- `host`: set via env `DB_HOST`; datebase host name
82+
6983
## ElasticSearch Setup
7084
- Go to https://www.elastic.co/downloads/ download and install the elasticsearch.
7185
- Modify `esConfig` under `config/default.js` to meet your environment.

app-constants.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,16 @@
33
*/
44

55
const UserRoles = {
6-
BookingManager: 'bookingmanager'
6+
BookingManager: 'bookingmanager',
7+
Administrator: 'administrator',
8+
ConnectManager: 'Connect Manager'
79
}
810

11+
const FullManagePermissionRoles = [
12+
UserRoles.BookingManager,
13+
UserRoles.Administrator
14+
]
15+
916
const Scopes = {
1017
// job
1118
READ_JOB: 'read:taas-jobs',
@@ -31,5 +38,6 @@ const Scopes = {
3138

3239
module.exports = {
3340
UserRoles,
41+
FullManagePermissionRoles,
3442
Scopes
3543
}

app-routes.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,12 @@ module.exports = (app) => {
4949
}
5050
} else {
5151
req.authUser.jwtToken = req.headers.authorization
52-
if (_.includes(req.authUser.roles, constants.UserRoles.BookingManager)) {
53-
req.authUser.isBookingManager = true
52+
// check if user has full manage permission
53+
if (_.intersection(req.authUser.roles, constants.FullManagePermissionRoles).length) {
54+
req.authUser.hasManagePermission = true
55+
}
56+
if (_.includes(req.authUser.roles, constants.UserRoles.ConnectManager)) {
57+
req.authUser.isConnectManager = true
5458
}
5559
next()
5660
}

app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const cors = require('cors')
1010
const HttpStatus = require('http-status-codes')
1111
const interceptor = require('express-interceptor')
1212
const logger = require('./src/common/logger')
13+
const eventHandlers = require('./src/eventHandlers')
1314

1415
// setup express app
1516
const app = express()
@@ -91,6 +92,7 @@ app.use((err, req, res, next) => {
9192

9293
const server = app.listen(app.get('port'), () => {
9394
logger.info({ component: 'app', message: `Express server listening on port ${app.get('port')}` })
95+
eventHandlers.init()
9496
})
9597

9698
if (process.env.NODE_ENV === 'test') {

config/config.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Configuration for DB migration.
3+
*/
4+
5+
module.exports = {
6+
development: {
7+
username: process.env.DB_USERNAME || 'postgres',
8+
password: process.env.DB_PASSWORD || 'postgres',
9+
database: process.env.DB_NAME || 'postgres',
10+
host: process.env.DB_HOST || '127.0.0.1',
11+
dialect: 'postgres'
12+
},
13+
test: {
14+
username: process.env.DB_USERNAME || 'postgres',
15+
password: process.env.DB_PASSWORD || 'postgres',
16+
database: process.env.DB_NAME || 'postgres',
17+
host: process.env.DB_HOST || '127.0.0.1',
18+
dialect: 'postgres'
19+
},
20+
production: {
21+
username: process.env.DB_USERNAME,
22+
password: process.env.DB_PASSWORD,
23+
database: process.env.DB_NAME,
24+
host: process.env.DB_HOST,
25+
dialect: 'postgres'
26+
}
27+
}

config/config.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"development": {
3+
"username": "postgres",
4+
"password": "postgres",
5+
"database": "postgres",
6+
"host": "127.0.0.1",
7+
"dialect": "postgres"
8+
},
9+
"test": {
10+
"username": "root",
11+
"password": null,
12+
"database": "database_test",
13+
"host": "127.0.0.1",
14+
"dialect": "mysql"
15+
},
16+
"production": {
17+
"username": "root",
18+
"password": null,
19+
"database": "database_production",
20+
"host": "127.0.0.1",
21+
"dialect": "mysql"
22+
}
23+
}

config/default.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = {
88
VALID_ISSUERS: process.env.VALID_ISSUERS || '["https://api.topcoder-dev.com", "https://api.topcoder.com", "https://topcoder-dev.auth0.com/", "https://auth.topcoder-dev.com/"]',
99
AUTH0_URL: process.env.AUTH0_URL,
1010
AUTH0_AUDIENCE: process.env.AUTH0_AUDIENCE,
11-
AUTH0_AUDIENCE_FOR_BUS_API: process.env.AUTH0_AUDIENCE_FOR_BUS_API,
11+
AUTH0_AUDIENCE_UBAHN: process.env.AUTH0_AUDIENCE_UBAHN,
1212
TOKEN_CACHE_TIME: process.env.TOKEN_CACHE_TIME,
1313
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID,
1414
AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET,
@@ -21,6 +21,7 @@ module.exports = {
2121

2222
TC_API: process.env.TC_API || 'https://api.topcoder-dev.com/v5',
2323
ORG_ID: process.env.ORG_ID || '36ed815b-3da1-49f1-a043-aaed0a4e81ad',
24+
TOPCODER_SKILL_PROVIDER_ID: process.env.TOPCODER_SKILL_PROVIDER_ID || '9cc0795a-6e12-4c84-9744-15858dba1861',
2425

2526
TOPCODER_USERS_API: process.env.TOPCODER_USERS_API || 'https://api.topcoder-dev.com/v3/users',
2627

config/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module.exports = {
22
LOG_LEVEL: process.env.LOG_LEVEL || 'info',
33
AUTH0_URL: 'http://example.com',
44
AUTH0_AUDIENCE: 'http://example.com',
5-
AUTH0_AUDIENCE_FOR_BUS_API: 'http://example.com',
5+
AUTH0_AUDIENCE_UBAHN: 'http://example.com',
66
AUTH0_CLIENT_ID: 'fake_id',
77
AUTH0_CLIENT_SECRET: 'fake_secret'
88
}

docker/sample.api.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ ES_HOST=<ES Host Endpoint>
33

44
AUTH0_URL=<AUTH0 URL>
55
AUTH0_AUDIENCE=<AUTH0 Audience>
6-
AUTH0_AUDIENCE_FOR_BUS_API=<AUTH0 Audience For Bus Api>
6+
AUTH0_AUDIENCE_UBAHN=<AUTH0 Audience For Bus Api>
77
TOKEN_CACHE_TIME=500000
88
AUTH0_CLIENT_ID=<AUTH0 Client ID>
99
AUTH0_CLIENT_SECRET=<AUTH0 Client Secret>

0 commit comments

Comments
 (0)