Merge pull request #3601 from FreeCodeCamp/fix/user-certs-edge-cases
Fix/user certs edge cases
This commit is contained in:
@ -103,7 +103,7 @@
|
|||||||
"isLocked": {
|
"isLocked": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false,
|
"default": false,
|
||||||
"description": "Campers profile does not show challenges to the public"
|
"description": "Campers profile does not show challenges/certificates to the public"
|
||||||
},
|
},
|
||||||
"currentChallenge": {
|
"currentChallenge": {
|
||||||
"type": {}
|
"type": {}
|
||||||
|
@ -13,8 +13,11 @@ import {
|
|||||||
observeQuery
|
observeQuery
|
||||||
} from '../utils/rx';
|
} from '../utils/rx';
|
||||||
|
|
||||||
const frontEndChallangeId = '561add10cb82ac38a17513be';
|
import {
|
||||||
const fullStackChallangeId = '660add10cb82ac38a17513be';
|
frontEndChallangeId,
|
||||||
|
fullStackChallangeId
|
||||||
|
} from '../utils/constantStrings.json';
|
||||||
|
|
||||||
const debug = debugFactory('freecc:certification');
|
const debug = debugFactory('freecc:certification');
|
||||||
const sendMessageToNonUser = ifNoUserSend(
|
const sendMessageToNonUser = ifNoUserSend(
|
||||||
'must be logged in to complete.'
|
'must be logged in to complete.'
|
||||||
@ -36,10 +39,12 @@ export default function certificate(app) {
|
|||||||
'findById',
|
'findById',
|
||||||
frontEndChallangeId,
|
frontEndChallangeId,
|
||||||
{
|
{
|
||||||
tests: true
|
id: true,
|
||||||
|
tests: true,
|
||||||
|
name: true,
|
||||||
|
challengeType: true
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.map(({ tests = [] }) => tests)
|
|
||||||
.shareReplay();
|
.shareReplay();
|
||||||
|
|
||||||
const fullStackChallangeIds$ = observeQuery(
|
const fullStackChallangeIds$ = observeQuery(
|
||||||
@ -47,10 +52,12 @@ export default function certificate(app) {
|
|||||||
'findById',
|
'findById',
|
||||||
fullStackChallangeId,
|
fullStackChallangeId,
|
||||||
{
|
{
|
||||||
tests: true
|
id: true,
|
||||||
|
tests: true,
|
||||||
|
name: true,
|
||||||
|
challengeType: true
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.map(({ tests = [] }) => tests)
|
|
||||||
.shareReplay();
|
.shareReplay();
|
||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
@ -82,8 +89,14 @@ export default function certificate(app) {
|
|||||||
}
|
}
|
||||||
return fullStackChallangeIds$;
|
return fullStackChallangeIds$;
|
||||||
})
|
})
|
||||||
.flatMap((tests) => {
|
.flatMap(challenge => {
|
||||||
const { user } = req;
|
const { user } = req;
|
||||||
|
const {
|
||||||
|
id,
|
||||||
|
tests,
|
||||||
|
name,
|
||||||
|
challengeType
|
||||||
|
} = challenge;
|
||||||
if (
|
if (
|
||||||
isFront && !user.isFrontEndCert && isCertified(tests, user) ||
|
isFront && !user.isFrontEndCert && isCertified(tests, user) ||
|
||||||
!isFront && !user.isFullStackCert && isCertified(tests, user)
|
!isFront && !user.isFullStackCert && isCertified(tests, user)
|
||||||
@ -91,17 +104,16 @@ export default function certificate(app) {
|
|||||||
debug('certified');
|
debug('certified');
|
||||||
if (isFront) {
|
if (isFront) {
|
||||||
user.isFrontEndCert = true;
|
user.isFrontEndCert = true;
|
||||||
user.completedChallenges.push({
|
|
||||||
completedDate: new Date(),
|
|
||||||
id: frontEndChallangeId
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
user.isFullStackCert = true;
|
user.isFullStackCert = true;
|
||||||
user.completedChallenges.push({
|
|
||||||
completedDate: new Date(),
|
|
||||||
id: fullStackChallangeId
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
user.completedChallenges.push({
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
completedDate: new Date(),
|
||||||
|
challengeType
|
||||||
|
});
|
||||||
return saveUser(user);
|
return saveUser(user);
|
||||||
}
|
}
|
||||||
return Observable.just(user);
|
return Observable.just(user);
|
||||||
|
@ -4,6 +4,10 @@ import moment from 'moment';
|
|||||||
import { Observable } from 'rx';
|
import { Observable } from 'rx';
|
||||||
import debugFactory from 'debug';
|
import debugFactory from 'debug';
|
||||||
|
|
||||||
|
import {
|
||||||
|
frontEndChallangeId,
|
||||||
|
fullStackChallangeId
|
||||||
|
} from '../utils/constantStrings.json';
|
||||||
import { ifNoUser401, ifNoUserRedirectTo } from '../utils/middleware';
|
import { ifNoUser401, ifNoUserRedirectTo } from '../utils/middleware';
|
||||||
import { observeQuery } from '../utils/rx';
|
import { observeQuery } from '../utils/rx';
|
||||||
|
|
||||||
@ -270,14 +274,42 @@ module.exports = function(app) {
|
|||||||
});
|
});
|
||||||
return res.redirect('/');
|
return res.redirect('/');
|
||||||
}
|
}
|
||||||
|
if (!user.isGithubCool) {
|
||||||
|
req.flash('errors', {
|
||||||
|
msg: dedent`
|
||||||
|
This user needs to link GitHub with their account
|
||||||
|
in order to display this certificate to the public.
|
||||||
|
`
|
||||||
|
});
|
||||||
|
return res.redirect('back');
|
||||||
|
}
|
||||||
|
if (user.isLocked) {
|
||||||
|
req.flash('errors', {
|
||||||
|
msg: dedent`
|
||||||
|
${username} has chosen to hide their work from the public.
|
||||||
|
They need to unhide their work in order for this certificate to
|
||||||
|
be verifiable.
|
||||||
|
`
|
||||||
|
});
|
||||||
|
return res.redirect('back');
|
||||||
|
}
|
||||||
|
if (!user.isHonest) {
|
||||||
|
req.flash('errors', {
|
||||||
|
msg: dedent`
|
||||||
|
${username} has not agreed to our Academic Honesty Pledge yet.
|
||||||
|
`
|
||||||
|
});
|
||||||
|
return res.redirect('back');
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
showFront && user.isFrontEndCert ||
|
showFront && user.isFrontEndCert ||
|
||||||
!showFront && user.isFullStackCert
|
!showFront && user.isFullStackCert
|
||||||
) {
|
) {
|
||||||
var { completedDate } = _.find(user.completedChallenges, {
|
var { completedDate } = _.find(user.completedChallenges, {
|
||||||
id: showFront ?
|
id: showFront ?
|
||||||
'561add10cb82ac38a17513be' :
|
frontEndChallangeId :
|
||||||
'660add10cb82ac38a17513be'
|
fullStackChallangeId
|
||||||
});
|
});
|
||||||
|
|
||||||
return res.render(
|
return res.render(
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
{
|
{
|
||||||
"gitHubUserAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1521.3 Safari/537.36"
|
"gitHubUserAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1521.3 Safari/537.36",
|
||||||
|
"frontEndChallangeId": "561add10cb82ac38a17513be",
|
||||||
|
"fullStackChallangeId": "660add10cb82ac38a17513be"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user