Skip to content

Issue #4380 - Fix challenge register/unregister #4512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};
65 changes: 64 additions & 1 deletion src/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -145,6 +145,69 @@ 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/challenges/:challengeId/registrants',
async (req, res, next) => {
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,
};
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}`),
Expand Down
2 changes: 1 addition & 1 deletion src/shared/containers/SubmissionManagement/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <AccessDenied redirectLink={`${challengesUrl}/${challenge.id}`} cause={ACCESS_DENIED_REASON.HAVE_NOT_SUBMITTED_TO_THE_CHALLENGE} />;

const isEmpty = _.isEmpty(challenge);
Expand Down
2 changes: 1 addition & 1 deletion src/shared/containers/SubmissionPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<React.Fragment>
Expand Down
8 changes: 2 additions & 6 deletions src/shared/containers/challenge-detail/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
);
Expand Down