From 202d0fa0683e1351ceace18fe8bb129ede23026b Mon Sep 17 00:00:00 2001 From: Berkeley Martinez Date: Mon, 5 Oct 2015 19:58:44 -0700 Subject: [PATCH 1/3] Fix add to completed challenges on cert verify --- server/boot/certificate.js | 42 ++++++++++++++++++++----------- server/utils/constantStrings.json | 4 ++- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/server/boot/certificate.js b/server/boot/certificate.js index ba28cb8a16..b084d9f4b8 100644 --- a/server/boot/certificate.js +++ b/server/boot/certificate.js @@ -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); diff --git a/server/utils/constantStrings.json b/server/utils/constantStrings.json index 70f5d9766c..a2f5b29df8 100644 --- a/server/utils/constantStrings.json +++ b/server/utils/constantStrings.json @@ -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" } From 188da02ffcbf5a5709810495590888ed8f676325 Mon Sep 17 00:00:00 2001 From: Berkeley Martinez Date: Mon, 5 Oct 2015 20:00:25 -0700 Subject: [PATCH 2/3] Fix disable cert Disable certificate when user is locked to the public or when they haven't signed academic honesty --- common/models/user.json | 2 +- server/boot/user.js | 27 +++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/common/models/user.json b/common/models/user.json index cb34389b80..776c2c500e 100644 --- a/common/models/user.json +++ b/common/models/user.json @@ -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": {} diff --git a/server/boot/user.js b/server/boot/user.js index a7c6fe2978..9ecbe288dd 100644 --- a/server/boot/user.js +++ b/server/boot/user.js @@ -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,33 @@ module.exports = function(app) { }); return res.redirect('/'); } + if (user.isLocked) { + req.flash('errors', { + msg: dedent` + Looks like user '${username}'s account is locked + down to the public. + ` + }); + return res.redirect('/'); + } + if (!user.isHonest) { + req.flash('errors', { + msg: dedent` + Looks like the user '${username}'s has not signed + the academic honesty pledge. + ` + }); + return res.redirect('/'); + } + if ( showFront && user.isFrontEndCert || !showFront && user.isFullStackCert ) { var { completedDate } = _.find(user.completedChallenges, { id: showFront ? - '561add10cb82ac38a17513be' : - '660add10cb82ac38a17513be' + frontEndChallangeId : + fullStackChallangeId }); return res.render( From 9a0505f782dee6675b9f820593c10ca0eb3d63dd Mon Sep 17 00:00:00 2001 From: Quincy Larson Date: Mon, 5 Oct 2015 22:42:42 -0700 Subject: [PATCH 3/3] add github linking enforcement --- server/boot/user.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/server/boot/user.js b/server/boot/user.js index 9ecbe288dd..fa529cdd62 100644 --- a/server/boot/user.js +++ b/server/boot/user.js @@ -274,23 +274,32 @@ 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` - Looks like user '${username}'s account is locked - down to the public. + ${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('/'); + return res.redirect('back'); } if (!user.isHonest) { req.flash('errors', { msg: dedent` - Looks like the user '${username}'s has not signed - the academic honesty pledge. + ${username} has not agreed to our Academic Honesty Pledge yet. ` }); - return res.redirect('/'); + return res.redirect('back'); } if (