From b07363e003fd059c2a6af3d188439ae5c2e8aee0 Mon Sep 17 00:00:00 2001 From: Cagdas U Date: Wed, 12 Aug 2020 08:09:32 +0300 Subject: [PATCH 1/4] fix(members-service): fetch only active challenges At the `getUserResources` function, it will fetch only Active challenges. Reference topcoder-platform/community-app#4714 --- src/services/members.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/services/members.js b/src/services/members.js index 7716c91d..a5b32a51 100644 --- a/src/services/members.js +++ b/src/services/members.js @@ -7,6 +7,7 @@ /* global XMLHttpRequest */ import _ from 'lodash'; import qs from 'qs'; +import { decodeToken } from 'tc-accounts'; import logger from '../utils/logger'; import { getApiResponsePayload } from '../utils/tc'; import { getApi } from './api'; @@ -329,7 +330,8 @@ class MembersService { * @param {Array} challengeId the challenge id */ async getChallengeResources(challengeId) { - const url = `/resources?challengeId=${challengeId}`; + const user = decodeToken(this.private.tokenV3); + const url = `/resources?challengeId=${challengeId}&memberId=${user.userId}`; let res = null; try { @@ -346,14 +348,14 @@ class MembersService { * @param {Array} memberId the member id */ async getUserResources(memberId) { - const url = `/resources/${memberId}/challenges`; + const url = `/challenges?status=Active&memberId=${memberId}`; const res = await this.private.apiV5.get(url); const challenges = await res.json(); const roles = await this.getResourceRoles(); const calls = []; challenges.forEach(async (ch) => { - calls.push(this.getChallengeResources(ch)); + calls.push(this.getChallengeResources(ch.id)); }); return Promise.all(calls).then((resources) => { From 1f69bae40442df8a6b7b564d6de403c523241151 Mon Sep 17 00:00:00 2001 From: Sushil Shinde Date: Thu, 13 Aug 2020 15:17:50 +0530 Subject: [PATCH 2/4] fix: for #4714 https://github.com/topcoder-platform/community-app/issues/4714 cagdas001 https://github.com/topcoder-platform/topcoder-react-lib/pull/220 1000.19.45 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6559a5cf..16989194 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "lint:js": "./node_modules/.bin/eslint --ext .js,.jsx .", "test": "npm run lint && npm run jest" }, - "version": "1000.19.44", + "version": "1000.19.45", "dependencies": { "auth0-js": "^6.8.4", "config": "^3.2.0", From 7cca2afb54e725f0b1f7f29afdb138aa8cdccc1c Mon Sep 17 00:00:00 2001 From: "Luiz R. Rodrigues" Date: Thu, 13 Aug 2020 21:44:51 -0300 Subject: [PATCH 3/4] Fix challenge.track validation --- src/reducers/challenge.js | 4 +++- src/services/challenges.js | 4 ++-- src/utils/challenge/filter.js | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/reducers/challenge.js b/src/reducers/challenge.js index 05bb9bc9..e91c4f53 100644 --- a/src/reducers/challenge.js +++ b/src/reducers/challenge.js @@ -18,6 +18,8 @@ import { fireErrorMessage } from '../utils/errors'; import mySubmissionsManagement from './my-submissions-management'; +import { COMPETITION_TRACKS } from '../utils/tc'; + /** * Handles CHALLENGE/GET_DETAILS_INIT action. * @param {Object} state @@ -469,7 +471,7 @@ export function factory(options = {}) { const challengeDetails = _.get(res, 'payload', {}); const track = _.get(challengeDetails, 'legacy.track', ''); let checkpointsPromise = null; - if (track === 'DESIGN') { + if (track === COMPETITION_TRACKS.DESIGN) { const p = _.get(challengeDetails, 'phases', []) .filter(x => x.name === 'Checkpoint Review'); if (p.length && !p[0].isOpen) { diff --git a/src/services/challenges.js b/src/services/challenges.js index f24bdf5e..d5fb3bc2 100644 --- a/src/services/challenges.js +++ b/src/services/challenges.js @@ -636,7 +636,7 @@ class ChallengesService { let contentType; let url; - if (track === 'DESIGN') { + if (track === COMPETITION_TRACKS.DESIGN) { ({ api } = this.private); contentType = 'application/json'; url = '/submissions/'; // The submission info is contained entirely in the JSON body @@ -654,7 +654,7 @@ class ChallengesService { }, onProgress).then((res) => { const jres = JSON.parse(res); // Return result for Develop submission - if (track === 'DEVELOP') { + if (track === COMPETITION_TRACKS.DEVELOP) { return jres; } // Design Submission requires an extra "Processing" POST diff --git a/src/utils/challenge/filter.js b/src/utils/challenge/filter.js index 36e91e6f..263c3132 100644 --- a/src/utils/challenge/filter.js +++ b/src/utils/challenge/filter.js @@ -89,7 +89,7 @@ function filterByRegistrationOpen(challenge, state) { if (!registrationPhase || !registrationPhase.isOpen) { return false; } - if (challenge.track === 'DESIGN') { + if (challenge.track === COMPETITION_TRACKS.DESIGN) { const checkpointPhase = challengePhases.find(item => item.name === 'Checkpoint Submission')[0]; return !checkpointPhase || !checkpointPhase.isOpen; } From 12cf31e5940095dc688aadb2f78c39525917e19a Mon Sep 17 00:00:00 2001 From: "Luiz R. Rodrigues" Date: Fri, 14 Aug 2020 02:05:02 -0300 Subject: [PATCH 4/4] Fix getChallengeRegistrants filter to not logged user --- src/services/challenges.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/services/challenges.js b/src/services/challenges.js index d5fb3bc2..d0a298ae 100644 --- a/src/services/challenges.js +++ b/src/services/challenges.js @@ -407,7 +407,9 @@ class ChallengesService { .then(checkErrorV5).then(res => res.result); /* API will return all roles to currentUser, so need to filter in FE */ - registrants = _.filter(registrants, r => r.roleId === roleId); + if (roleId) { + registrants = _.filter(registrants, r => r.roleId === roleId); + } return registrants || []; }