Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: topcoder-platform/submissions-api
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.1.0
Choose a base ref
...
head repository: topcoder-platform/submissions-api
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: develop
Choose a head ref

Commits on Mar 2, 2021

  1. logic change for phaseId

    Sachin Maheshwari committed Mar 2, 2021
    Copy the full SHA
    4fc65df View commit details
  2. typo

    Sachin Maheshwari committed Mar 2, 2021
    Copy the full SHA
    b1e2faf View commit details
  3. typo

    Sachin Maheshwari committed Mar 2, 2021
    Copy the full SHA
    b34e69c View commit details
  4. correcting phaseid mapping

    Sachin Maheshwari committed Mar 2, 2021
    Copy the full SHA
    a225915 View commit details

Commits on Mar 3, 2021

  1. Merge pull request #227 from topcoder-platform/develop

    Hotfix 03 March2021 : shapeup pure v5 task
    sachin-maheshwari authored Mar 3, 2021
    Copy the full SHA
    70860cc View commit details

Commits on Mar 11, 2021

  1. Copy the full SHA
    6b78e92 View commit details
  2. DBtoES migration: to avoid community-app UI broken in case of empty a…

    …rray
    Sachin Maheshwari committed Mar 11, 2021
    Copy the full SHA
    d2627b6 View commit details

Commits on Mar 15, 2021

  1. Merge pull request #230 from topcoder-platform/develop

    Hotfix: Shapeup-pure-v5-task, migration DB to ES
    sachin-maheshwari authored Mar 15, 2021
    Copy the full SHA
    86a9fb0 View commit details

Commits on Mar 17, 2021

  1. Token commit to trigger redeploy

    to update aws creds
    rootelement authored Mar 17, 2021
    Copy the full SHA
    6a138fe View commit details

Commits on Mar 22, 2021

  1. Copy the full SHA
    e864a47 View commit details
  2. deploying on dev..

    Sachin Maheshwari committed Mar 22, 2021
    Copy the full SHA
    a82aef5 View commit details
  3. typo

    Sachin Maheshwari committed Mar 22, 2021
    Copy the full SHA
    72c98a0 View commit details

Commits on Mar 23, 2021

  1. fixing json error

    Sachin Maheshwari committed Mar 23, 2021
    Copy the full SHA
    daaaf21 View commit details
  2. cleanup

    Sachin Maheshwari committed Mar 23, 2021
    Copy the full SHA
    9346f74 View commit details
  3. Merge pull request #232 from topcoder-platform/feature/migrate-small-…

    …chunks
    
    migrate small chunks of challenges (submissions) for v5 ids
    sachin-maheshwari authored Mar 23, 2021
    Copy the full SHA
    1e15f23 View commit details
  4. Merge pull request #233 from topcoder-platform/develop

    migrate small chunks for v5 challenges (submissions) in the DB and change in ES accordingly.
    sachin-maheshwari authored Mar 23, 2021
    Copy the full SHA
    3a1512a View commit details

Commits on Mar 26, 2021

  1. Copy the full SHA
    b14e368 View commit details
  2. Fix lint errors

    callmekatootie committed Mar 26, 2021
    Copy the full SHA
    0992675 View commit details
  3. Copy the full SHA
    e3ad673 View commit details

Commits on Mar 31, 2021

  1. Merge pull request #234 from topcoder-platform/develop

    Sync master with prod
    rootelement authored Mar 31, 2021
    Copy the full SHA
    65c3004 View commit details

Commits on Jun 12, 2021

  1. documentation updates

    ThomasKranitsas committed Jun 12, 2021
    Copy the full SHA
    3accea7 View commit details

Commits on Jun 21, 2021

  1. Copy the full SHA
    6ac2cb4 View commit details
  2. Merge pull request #240 from topcoder-platform/allow-pure-v5

    allow pure v5 challenges
    rootelement authored Jun 21, 2021
    Copy the full SHA
    eeacbb8 View commit details

Commits on Jun 25, 2021

  1. Copy the full SHA
    fb6fcb0 View commit details
  2. Copy the full SHA
    4ff7f8a View commit details

Commits on Jun 29, 2021

  1. Copy the full SHA
    b1ed898 View commit details

Commits on Jul 26, 2021

  1. Copy the full SHA
    f3c92d2 View commit details

Commits on Jul 28, 2021

  1. Copy the full SHA
    b62c123 View commit details

Commits on Aug 19, 2021

  1. Copy the full SHA
    6d13d2c View commit details

Commits on Aug 20, 2021

  1. Copy the full SHA
    0fda5ed View commit details
  2. change debug to info

    callmekatootie committed Aug 20, 2021
    Copy the full SHA
    339b583 View commit details

Commits on Aug 21, 2021

  1. Copy the full SHA
    ecf373c View commit details

Commits on Aug 22, 2021

  1. Merge pull request #247 from topcoder-platform/Issue_246

    Issue 246 - support v5 scorecard id
    rootelement authored Aug 22, 2021
    Copy the full SHA
    a8fd596 View commit details

Commits on Sep 1, 2021

  1. Copy the full SHA
    659da47 View commit details

Commits on Oct 29, 2021

  1. Copy the full SHA
    89c3730 View commit details
  2. Copy the full SHA
    08ca508 View commit details
  3. Merge pull request #254 from topcoder-platform/Issue_253

    HOTFIX - do not store legacy challenge id if there isnt one
    ThomasKranitsas authored Oct 29, 2021
    Copy the full SHA
    793100b View commit details

Commits on Jan 28, 2022

  1. Copy the full SHA
    b8e692a View commit details
  2. Merge pull request #261 from topcoder-platform/Issue_260

    ignore appeals response phase for design track
    ThomasKranitsas authored Jan 28, 2022
    Copy the full SHA
    0f5c242 View commit details

Commits on Feb 8, 2022

  1. Copy the full SHA
    5926981 View commit details

Commits on Feb 9, 2022

  1. Merge pull request #267 from topcoder-platform/Issue_266

    allow client managers to download submissions
    ThomasKranitsas authored Feb 9, 2022
    Copy the full SHA
    fd8d005 View commit details
  2. Copy the full SHA
    0f41a8a View commit details

Commits on Mar 17, 2022

  1. Copy the full SHA
    b3e2480 View commit details

Commits on Mar 21, 2022

  1. Copy the full SHA
    1980a1b View commit details
  2. ci:reset

    LieutenantRoger committed Mar 21, 2022
    Copy the full SHA
    7a8fb4a View commit details
  3. Merge pull request #274 from topcoder-platform/issue_reviewer_role

    reviewer role restriction
    LieutenantRoger authored Mar 21, 2022
    Copy the full SHA
    3d40d40 View commit details
  4. redeploying branch

    LieutenantRoger committed Mar 21, 2022
    Copy the full SHA
    88f8096 View commit details
  5. resource role check

    LieutenantRoger committed Mar 21, 2022
    Copy the full SHA
    741361a View commit details

Commits on Mar 22, 2022

  1. adjust naming

    LieutenantRoger committed Mar 22, 2022
    Copy the full SHA
    15973ae View commit details
  2. adjust name

    LieutenantRoger committed Mar 22, 2022
    Copy the full SHA
    4c26cd1 View commit details
Showing with 17,981 additions and 9,917 deletions.
  1. +24 −20 .circleci/config.yml
  2. +8 −0 .eslintrc.yml
  3. +102 −5 README.md
  4. +21 −21 app.js
  5. +16 −1 build.sh
  6. +37 −9 config/default.js
  7. +5 −4 config/test.js
  8. +5 −3 docker/Dockerfile
  9. +2 −1 docker/sample.api.env
  10. +1,745 −1,617 docs/swagger.yaml
  11. +8 −0 local/docker-compose.yml
  12. +14,091 −7,183 package-lock.json
  13. +37 −27 package.json
  14. +37 −42 scripts/ESloadHelper.js
  15. +10 −9 scripts/createIndex.js
  16. +7 −7 scripts/createTables.js
  17. +10 −9 scripts/deleteIndex.js
  18. +5 −4 scripts/importData.js
  19. +5 −4 scripts/loadES.js
  20. +38 −20 scripts/migrateFromDBToES.js
  21. +12 −11 scripts/updateToV5ChallengeId.js
  22. +112 −0 scripts/updateToV5ChallengeIdSmallChunk.js
  23. +12 −11 scripts/updateToV5ChallengeIdV2.js
  24. +1 −1 src/bootstrap.js
  25. +1 −1 src/common/ErrorMiddleware.js
  26. +33 −0 src/common/axiosInstance.js
  27. +16 −16 src/common/dbhelper.js
  28. +461 −253 src/common/helper.js
  29. +124 −0 src/common/informixHelper.js
  30. +34 −48 src/common/logger.js
  31. +16 −0 src/common/m2mHelper.js
  32. +18 −0 src/constants/index.js
  33. +8 −8 src/controllers/ArtifactController.js
  34. +2 −2 src/controllers/HealthCheckController.js
  35. +12 −12 src/controllers/ReviewController.js
  36. +12 −12 src/controllers/ReviewSummationController.js
  37. +12 −12 src/controllers/ReviewTypeController.js
  38. +26 −16 src/controllers/SubmissionController.js
  39. +13 −7 src/routes/ReviewRoutes.js
  40. +12 −6 src/routes/ReviewSummationRoutes.js
  41. +35 −14 src/routes/SubmissionRoutes.js
  42. +52 −33 src/services/ArtifactService.js
  43. +5 −7 src/services/HealthCheckService.js
  44. +29 −6 src/services/HelperService.js
  45. +116 −66 src/services/ReviewService.js
  46. +51 −51 src/services/ReviewSummationService.js
  47. +43 −43 src/services/ReviewTypeService.js
  48. +313 −117 src/services/SubmissionService.js
  49. +156 −156 test/common/testData.js
  50. +3 −3 test/e2e/ReviewService.test.js
  51. +2 −2 test/e2e/ReviewSummationService.test.js
  52. +3 −3 test/e2e/prepare.js
  53. +13 −4 test/unit/SubmissionService.test.js
  54. +10 −10 test/unit/prepare.js
44 changes: 24 additions & 20 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
version: 2
version: 2.1
defaults: &defaults
docker:
- image: circleci/python:stretch-browsers
docker:
- image: cimg/python:3.13.2-browsers
install_dependency: &install_dependency
name: Installation of build and deployment dependencies.
command: |
sudo apt install jq
sudo pip3 install awscli --upgrade
sudo pip3 install docker-compose
sudo apt update
sudo apt install python3-pip
sudo pip3 install awscli --upgrade
# sudo pip3 install docker==6.1.3
# sudo pip3 install docker-compose
install_deploysuite: &install_deploysuite
name: Installation of install_deploysuite.
command: |
git clone --branch v1.4.1 https://github.com/topcoder-platform/tc-deploy-scripts ../buildscript
cp ./../buildscript/master_deploy.sh .
cp ./../buildscript/buildenv.sh .
cp ./../buildscript/awsconfiguration.sh .
name: Installation of install_deploysuite.
command: |
git clone --branch v1.4.17 https://github.com/topcoder-platform/tc-deploy-scripts ../buildscript
cp ./../buildscript/master_deploy.sh .
cp ./../buildscript/buildenv.sh .
cp ./../buildscript/awsconfiguration.sh .
run_build: &run_build
name: Installation of build dependencies.
command: ./build.sh
name: Installation of build dependencies.
command: ./build.sh

jobs:
# Build & Deploy against development backend
@@ -38,7 +40,7 @@ jobs:
source awsenvconf
./buildenv.sh -e DEV -b dev-submissions-api-deployvar
source buildenvvar
./master_deploy.sh -d ECS -e DEV -t latest -s dev-global-appvar,dev-submissions-api-appvar -i submissions-api
./master_deploy.sh -d ECS -e DEV -t latest -s dev-global-appvar,dev-submissions-api-appvar -i submissions-api -p FARGATE
"build-prod":
<<: *defaults
@@ -56,20 +58,22 @@ jobs:
source awsenvconf
./buildenv.sh -e PROD -b prod-submissions-api-deployvar
source buildenvvar
./master_deploy.sh -d ECS -e PROD -t latest -s prod-global-appvar,prod-submissions-api-appvar -i submissions-api
./master_deploy.sh -d ECS -e PROD -t latest -s prod-global-appvar,prod-submissions-api-appvar -i submissions-api -p FARGATE
workflows:
version: 2
build:
jobs:
# Development builds are executed on "develop" branch only.
- "build-dev":
context : org-global
context: org-global
filters:
branches:
only: ['develop']
only: ["develop", "PM-809_artifact-endpoint-update"]
- "build-prod":
context : org-global
context: org-global
filters:
branches:
only: master
only:
- master
- hotfix/inc-15
8 changes: 8 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
env:
browser: true
commonjs: true
es2021: true
extends: standard
parserOptions:
ecmaVersion: latest
rules: {}
107 changes: 102 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# Topcoder Submission API

Topcoder's API that deals with submissions, reviews, review summations and review types on the Topcoder platform

## Devlopment status

[![Total alerts](https://img.shields.io/lgtm/alerts/g/topcoder-platform/submissions-api.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/topcoder-platform/submissions-api/alerts/)[![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/topcoder-platform/submissions-api.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/topcoder-platform/submissions-api/context:javascript)

### Deployment status

Dev: [![CircleCI](https://circleci.com/gh/topcoder-platform/submissions-api/tree/develop.svg?style=svg)](https://circleci.com/gh/topcoder-platform/submissions-api/tree/develop) Prod: [![CircleCI](https://circleci.com/gh/topcoder-platform/submissions-api/tree/master.svg?style=svg)](https://circleci.com/gh/topcoder-platform/submissions-api/tree/master)

## Swagger definition

- [Swagger](https://api.topcoder.com/v5/submissions/docs)

## Intended use

- Production API

## Related repos

- [ES Processor](https://github.com/topcoder-platform/submission-processor-es) - Updates data in Opensearch

## Pre-requisites

@@ -50,7 +71,7 @@ e.g.

```
export AWS_REGION="<AWS Region>"
export S3_BUCKET="<S3 Bucket Name>"
export DMZ_BUCKET="<S3 Bucket Name>"
export ARTIFACT_BUCKET="<Artifact S3 Bucket Name>"
export ES_HOST="<ES Endpoint>"
export AUTH0_URL="<Auth0 URL>"
@@ -94,6 +115,84 @@ This script will load the data from `scripts/data` directory into ES
npm run start
```

### Local Deployment
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:

```bash
nvm use
```

1. 📦 Install npm dependencies

```bash
npm install
```

2. ⚙ Local config
In the `submissions-api` root directory create `.env` file with the next environment variables. Values for **Auth0 config** should be shared with you on the forum.<br>
```bash
# AWS related config
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_REGION=
DMZ_BUCKET=
ARTIFACT_BUCKET=

# Auth0 config
AUTH0_URL=
AUTH0_PROXY_SERVER_URL=
TOKEN_CACHE_TIME=
AUTH0_AUDIENCE=
AUTH0_CLIENT_ID=
AUTH0_CLIENT_SECRET=

# Locally deployed services (via docker-compose)
ES_HOST=localhost:9200
```

- Values from this file would be automatically used by many `npm` commands.
- ⚠️ Never commit this file or its copy to the repository!

3. 🚢 Start docker-compose with services which are required to start Topcoder Submissions API locally

```bash
npm run services:up
```
- `npm run services:down` can be used to shutdown the docker services
- `npm run services:logs` can be used to view the logs from the docker services

4. ♻ Create tables.

```bash
npm run create-tables
```
5. ♻ Create ES index.

```bash
npm run create-index
```

6. ♻ Init DB, ES

```bash
npm run local:init
```

This command will do 2 things:
- Import the data to the database and index it to OpenSearch
- Note, to migrate the existing data from DynamoDB to OS, run the following script
```
npm run db-to-es
```

7. 🚀 Start Topcoder Submissions API

```bash
npm run start
```
The Topcoder Submissions API will be served on `http://localhost:3000`


#### Linting JS files

```
@@ -191,10 +290,6 @@ and then run the following script
npm run update-to-v5-challengeId
```

#### Swagger UI

Swagger UI will be served at `http://localhost:3000/docs`

## Postman verification

1. Open Postman
@@ -220,3 +315,5 @@ Swagger UI will be served at `http://localhost:3000/docs`
2. There are 3 tokens provided in the environment collection representing each role - Topcoder User, Copilot, Administrator

3. DynamoDB performance seems to be slower in my testing

Token Commit.
42 changes: 21 additions & 21 deletions app.js
Original file line number Diff line number Diff line change
@@ -10,15 +10,14 @@ const cors = require('cors')
const bodyParser = require('body-parser')
const httpStatus = require('http-status')
const _ = require('lodash')
const winston = require('winston')
const logger = require('./src/common/logger')
const helper = require('./src/common/helper')
const errorMiddleware = require('./src/common/ErrorMiddleware')
const routes = require('./src/routes')
const swaggerUi = require('swagger-ui-express')
const YAML = require('yamljs')
const authenticator = require('tc-core-library-js').middleware.jwtAuthenticator
const fileUpload = require('express-fileupload')
const memwatch = require('memwatch-next')

const swaggerDocument = YAML.load('./docs/swagger.yaml')
const app = express()
@@ -29,20 +28,9 @@ app.set('port', config.WEB_SERVER_PORT)
app.use(bodyParser.json({ limit: '50mb' }))
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }))
app.use(cors())
app.use(fileUpload())

memwatch.on('leak', function (info) {
winston.info(`Memory leak detected, details: ${info}`)
const reqBody = {
topic: 'common.error.reporting',
originator: 'submission-api',
timestamp: (new Date()).toISOString(), // time when submission was created
'mime-type': 'application/json',
payload: info
}

helper.postToBusApi(reqBody)
})
app.use(fileUpload({
limits: { fileSize: 150 * 1024 * 1024 }
}))

const apiRouter = express.Router()

@@ -77,7 +65,6 @@ function checkIfExists (source, term) {
return false
}

/* eslint-disable no-param-reassign */
_.each(routes, (verbs, url) => {
_.each(verbs, (def, verb) => {
let actions = [
@@ -86,7 +73,7 @@ _.each(routes, (verbs, url) => {
next()
}
]
const method = require(`./src/controllers/${def.controller}`)[ def.method ]; // eslint-disable-line
const method = require(`./src/controllers/${def.controller}`)[def.method]

if (!method) {
throw new Error(`${def.method} is undefined, for controller ${def.controller}`)
@@ -127,19 +114,32 @@ _.each(routes, (verbs, url) => {
})
}

if (def.blockByIp) {
actions.push((req, res, next) => {
req.authUser.blockIP = _.find(req.authUser, (value, key) => {
return (key.indexOf('blockIP') !== -1)
})
if (req.authUser.blockIP) {
throw new errors.HttpStatusError(403, 'Access denied')
} else {
next()
}
})
}

actions.push(method)
winston.info(`API : ${verb.toLocaleUpperCase()} ${config.API_VERSION}${url}`)
logger.info(`API : ${verb.toLocaleUpperCase()} ${config.API_VERSION}${url}`)
apiRouter[verb](`${config.API_VERSION}${url}`, helper.autoWrapExpress(actions))
})
})
/* eslint-enable no-param-reassign */

app.use('/v5/submissions/docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument))
app.use('/', apiRouter)
app.use(errorMiddleware())
// Serve Swagger Docs after setting host and base path
swaggerDocument.host = config.HOST
swaggerDocument.basePath = config.API_VERSION
app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument))

// Check if the route is not found or HTTP method is not supported
app.use('*', (req, res) => {
@@ -153,7 +153,7 @@ app.use('*', (req, res) => {
})

http.listen(app.get('port'), () => {
winston.info(`Express server listening on port ${app.get('port')}`)
logger.info(`Express server listening on port ${app.get('port')}`)
})

module.exports = app
17 changes: 16 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -10,5 +10,20 @@ set -eo pipefail
#sed -i='' "s|submissions-api:latest|$TAG|" docker/docker-compose.yml
echo "" > docker/api.env
docker-compose -f docker/docker-compose.yml build submissions-api
docker images
#docker images
docker create --name app submissions-api:latest
if [ -d node_modules ]
then
mv package-lock.json old-package-lock.json
docker cp app:/submissions-api/package-lock.json package-lock.json
set +eo pipefail
UPDATE_CACHE=$(cmp package-lock.json old-package-lock.json)
set -eo pipefail
else
UPDATE_CACHE=1
fi

if [ "$UPDATE_CACHE" == 1 ]
then
docker cp app:/submissions-api/node_modules .
fi
Loading