From 3eb060ad496b892bc2aa6e09da8d87018b6f7801 Mon Sep 17 00:00:00 2001 From: "Luiz R. Rodrigues" Date: Tue, 9 Jun 2020 21:12:08 -0300 Subject: [PATCH 1/4] Added apiProxy to get registrants from challenge --- src/server/index.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/server/index.js b/src/server/index.js index 062cb1449c..dbb5fb47ad 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -9,7 +9,7 @@ import Application from 'shared'; import config from 'config'; import express from 'express'; import fetch from 'isomorphic-fetch'; -import { logger } from 'topcoder-react-lib'; +import { logger, services } from 'topcoder-react-lib'; import fs from 'fs'; import moment from 'moment'; import path from 'path'; @@ -145,6 +145,28 @@ async function onExpressJsSetup(server) { tcCommunitiesDemoApi, ); + // Get registrants from challenge + server.use( + '/community-app-assets/api/registrants/:challengeId', + async (req, res, next) => { + const tokenM2M = await services.api.getTcM2mToken(); + const params = { + challengeId: req.params.challengeId, + roleId: req.query.roleId, + }; + const url = `${config.API.V5}/resources?${qs.stringify(params)}`; + try { + let data = await fetch(url, { + headers: { Authorization: `Bearer ${tokenM2M}` }, + }); + data = await data.text(); + res.send(data); + } catch (err) { + next(err); + } + }, + ); + server.use( '/community-app-assets/api/edit-contentful-entry/:id', (req, res) => res.redirect(`${CMS_BASE_URL}/entries/${req.params.id}`), From e7f5286fb537202b9decbe847a5ce482092c84a8 Mon Sep 17 00:00:00 2001 From: "Luiz R. Rodrigues" Date: Tue, 9 Jun 2020 21:14:43 -0300 Subject: [PATCH 2/4] Challenge Details : Fix isRegistered functions --- src/shared/containers/SubmissionManagement/index.jsx | 2 +- src/shared/containers/SubmissionPage.jsx | 2 +- src/shared/containers/challenge-detail/index.jsx | 8 ++------ 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/shared/containers/SubmissionManagement/index.jsx b/src/shared/containers/SubmissionManagement/index.jsx index 0062cba9c3..b849323beb 100644 --- a/src/shared/containers/SubmissionManagement/index.jsx +++ b/src/shared/containers/SubmissionManagement/index.jsx @@ -65,7 +65,7 @@ class SubmissionManagementPageContainer extends React.Component { showModal, toBeDeletedId, } = this.props; - const isRegistered = registrants.find(r => _.toString(r.handle) === _.toString(handle)); + const isRegistered = registrants.find(r => _.toString(r.memberHandle) === _.toString(handle)); if (!isRegistered) return ; const isEmpty = _.isEmpty(challenge); diff --git a/src/shared/containers/SubmissionPage.jsx b/src/shared/containers/SubmissionPage.jsx index 592e89937a..4505291471 100644 --- a/src/shared/containers/SubmissionPage.jsx +++ b/src/shared/containers/SubmissionPage.jsx @@ -53,7 +53,7 @@ class SubmissionsPageContainer extends React.Component { render() { const { registrants, handle, challengeId } = this.props; - const isRegistered = registrants.find(r => _.toString(r.handle) === _.toString(handle)); + const isRegistered = registrants.find(r => _.toString(r.memberHandle) === _.toString(handle)); if (!isRegistered) { return ( diff --git a/src/shared/containers/challenge-detail/index.jsx b/src/shared/containers/challenge-detail/index.jsx index 63013b6476..b494f53ade 100644 --- a/src/shared/containers/challenge-detail/index.jsx +++ b/src/shared/containers/challenge-detail/index.jsx @@ -112,11 +112,8 @@ function getOgImage(challenge, challengeTypes) { } } -function isRegistered(details, registrants, handle) { - if (details && details.roles && details.roles.includes('Submitter')) { - return true; - } - if (_.find(registrants, r => _.toString(r.handle) === _.toString(handle))) { +function isRegistered(registrants, handle) { + if (_.find(registrants, r => _.toString(r.memberHandle) === _.toString(handle))) { return true; } return false; @@ -398,7 +395,6 @@ class ChallengeDetailPageContainer extends React.Component { const isLegacyMM = isMM(challenge) && Boolean(challenge.roundId); const hasRegistered = isRegistered( - challenge.userDetails, challenge.registrants, (auth.user || {}).handle, ); From 5e57c54311063b398baa03e1bc08287cac21581f Mon Sep 17 00:00:00 2001 From: "Luiz R. Rodrigues" Date: Wed, 10 Jun 2020 04:35:03 -0300 Subject: [PATCH 3/4] added proxyApi to get challenge rolesId --- src/server/index.js | 47 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/src/server/index.js b/src/server/index.js index dbb5fb47ad..c8da5ea563 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -145,14 +145,55 @@ async function onExpressJsSetup(server) { tcCommunitiesDemoApi, ); + // Get roleId by name + server.use( + '/community-app-assets/api/challenges/roleId', + async (req, res, next) => { + let tokenM2M = ''; + try { + tokenM2M = await services.api.getTcM2mToken(); + } catch (err) { + logger.error('proxyApi-roleId-getTcM2mToken : ', err); + } + + const params = { + name: req.query.name, + isActive: true, + }; + const url = `${config.API.V5}/resource-roles?${qs.stringify(params)}`; + try { + let data = await fetch(url, { + headers: { Authorization: `Bearer ${tokenM2M}` }, + }); + data = await data.text(); + res.send(data); + } catch (err) { + next(err); + } + }, + ); + // Get registrants from challenge server.use( - '/community-app-assets/api/registrants/:challengeId', + '/community-app-assets/api/challenges/:challengeId/registrants', async (req, res, next) => { - const tokenM2M = await services.api.getTcM2mToken(); + let tokenM2M = ''; + let roleId = ''; + try { + tokenM2M = await services.api.getTcM2mToken(); + } catch (err) { + logger.error('proxyApi-registrants-getTcM2mToken : ', err); + } + + try { + roleId = await services.challenge.getService().getRoleId('Submitter'); + } catch (err) { + logger.error('proxyApi-registrants-getRoleId : ', err); + } + const params = { challengeId: req.params.challengeId, - roleId: req.query.roleId, + roleId, }; const url = `${config.API.V5}/resources?${qs.stringify(params)}`; try { From fd48f941b1c256e076728e350e3b07390a9e3ccf Mon Sep 17 00:00:00 2001 From: "Luiz R. Rodrigues" Date: Wed, 10 Jun 2020 04:35:24 -0300 Subject: [PATCH 4/4] Addedd process.env.HOST and process.env.PORT to config file --- config/default.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/config/default.js b/config/default.js index 7de679aec0..0db54cbc36 100644 --- a/config/default.js +++ b/config/default.js @@ -401,4 +401,9 @@ module.exports = { TC_EDU_ARTICLES_PATH: '/articles', TC_EDU_SEARCH_PATH: '/search', TC_EDU_SEARCH_BAR_MAX_RESULTS_EACH_GROUP: 3, + + ENV: { + HOST: process.env.HOST, + PORT: process.env.PORT, + }, };