Skip to content

Fix getChallengeRegistrants filter to not logged user #223

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

Open
wants to merge 6 commits into
base: integration-v5-challenge-api
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion src/reducers/challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 5 additions & 3 deletions src/services/challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || [];
}
Expand Down Expand Up @@ -636,7 +638,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
Expand All @@ -654,7 +656,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
Expand Down
8 changes: 5 additions & 3 deletions src/services/members.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 {
Expand All @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/challenge/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down