Merge pull request #3601 from FreeCodeCamp/fix/user-certs-edge-cases

Fix/user certs edge cases
This commit is contained in:
Quincy Larson
2015-10-05 22:43:39 -07:00
4 changed files with 65 additions and 19 deletions

View File

@ -103,7 +103,7 @@
"isLocked": {
"type": "boolean",
"default": false,
"description": "Campers profile does not show challenges to the public"
"description": "Campers profile does not show challenges/certificates to the public"
},
"currentChallenge": {
"type": {}

View File

@ -13,8 +13,11 @@ import {
observeQuery
} from '../utils/rx';
const frontEndChallangeId = '561add10cb82ac38a17513be';
const fullStackChallangeId = '660add10cb82ac38a17513be';
import {
frontEndChallangeId,
fullStackChallangeId
} from '../utils/constantStrings.json';
const debug = debugFactory('freecc:certification');
const sendMessageToNonUser = ifNoUserSend(
'must be logged in to complete.'
@ -36,10 +39,12 @@ export default function certificate(app) {
'findById',
frontEndChallangeId,
{
tests: true
id: true,
tests: true,
name: true,
challengeType: true
}
)
.map(({ tests = [] }) => tests)
.shareReplay();
const fullStackChallangeIds$ = observeQuery(
@ -47,10 +52,12 @@ export default function certificate(app) {
'findById',
fullStackChallangeId,
{
tests: true
id: true,
tests: true,
name: true,
challengeType: true
}
)
.map(({ tests = [] }) => tests)
.shareReplay();
router.post(
@ -82,8 +89,14 @@ export default function certificate(app) {
}
return fullStackChallangeIds$;
})
.flatMap((tests) => {
.flatMap(challenge => {
const { user } = req;
const {
id,
tests,
name,
challengeType
} = challenge;
if (
isFront && !user.isFrontEndCert && isCertified(tests, user) ||
!isFront && !user.isFullStackCert && isCertified(tests, user)
@ -91,17 +104,16 @@ export default function certificate(app) {
debug('certified');
if (isFront) {
user.isFrontEndCert = true;
user.completedChallenges.push({
completedDate: new Date(),
id: frontEndChallangeId
})
} else {
user.isFullStackCert = true;
user.completedChallenges.push({
completedDate: new Date(),
id: fullStackChallangeId
})
}
user.completedChallenges.push({
id,
name,
completedDate: new Date(),
challengeType
});
return saveUser(user);
}
return Observable.just(user);

View File

@ -4,6 +4,10 @@ import moment from 'moment';
import { Observable } from 'rx';
import debugFactory from 'debug';
import {
frontEndChallangeId,
fullStackChallangeId
} from '../utils/constantStrings.json';
import { ifNoUser401, ifNoUserRedirectTo } from '../utils/middleware';
import { observeQuery } from '../utils/rx';
@ -270,14 +274,42 @@ module.exports = function(app) {
});
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 (
showFront && user.isFrontEndCert ||
!showFront && user.isFullStackCert
) {
var { completedDate } = _.find(user.completedChallenges, {
id: showFront ?
'561add10cb82ac38a17513be' :
'660add10cb82ac38a17513be'
frontEndChallangeId :
fullStackChallangeId
});
return res.render(

View File

@ -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"
}