chore: remove verify-can-claim-cert logic (#44574)

* chore: remove verify-can-claim-cert logic

* remove extraneous

* remove console log before Nich wakes up

* add api route back with flash

* remove unnecessary logic in completion-epic

* change tests for new layout

* dynamically use api location

* rename file

* fix Cypress api location

* fix(test): anchor does not have disabled class

* fix(tests): change js test to claim from /settings

* chore: change status to 410 (gone)

* update testing again

* oliver is nitpicky

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>

* make oliver happy

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
Shaun Hamilton
2022-01-18 16:52:49 +02:00
committed by GitHub
parent 9672c92a19
commit 9cb87d0257
12 changed files with 72 additions and 491 deletions

View File

@ -12,15 +12,13 @@ import {
certTypeTitleMap,
certTypeIdMap,
certIds,
oldDataVizId,
superBlockCertTypeMap
oldDataVizId
} from '../../../../config/certification-settings';
import { reportError } from '../middlewares/sentry-error-handler.js';
import { getChallenges } from '../utils/get-curriculum';
import { ifNoUser401 } from '../utils/middleware';
import { observeQuery } from '../utils/rx';
import { ensureLowerCaseString } from '../../common/models/user';
const {
legacyFrontEndChallengeId,
@ -50,7 +48,6 @@ export default function bootCertificate(app) {
const certTypeIds = createCertTypeIds(getChallenges());
const showCert = createShowCert(app);
const verifyCert = createVerifyCert(certTypeIds, app);
const verifyCanClaimCert = createVerifyCanClaim(certTypeIds, app);
api.put('/certificate/verify', ifNoUser401, ifNoSuperBlock404, verifyCert);
api.get('/certificate/showCert/:username/:certSlug', showCert);
@ -59,6 +56,15 @@ export default function bootCertificate(app) {
app.use(api);
}
function verifyCanClaimCert(_req, res) {
return res.status(410).json({
message: {
type: 'info',
message: 'Please reload the app, this feature is no longer available.'
}
});
}
export function getFallbackFullStackDate(completedChallenges, completedDate) {
var chalIds = [
certTypeIdMap[certTypes.respWebDesign],
@ -508,97 +514,3 @@ function createShowCert(app) {
}, next);
};
}
function createVerifyCanClaim(certTypeIds, app) {
const { User } = app.models;
function findUserByUsername$(username, fields) {
return observeQuery(User, 'findOne', {
where: { username },
fields
});
}
return function verifyCert(req, res, next) {
const { superBlock, username } = req.query;
log(superBlock);
let certType = superBlockCertTypeMap[superBlock];
log(certType);
return findUserByUsername$(ensureLowerCaseString(username), {
isFrontEndCert: true,
isBackEndCert: true,
isFullStackCert: true,
isRespWebDesignCert: true,
isFrontEndLibsCert: true,
isJsAlgoDataStructCert: true,
isDataVisCert: true,
is2018DataVisCert: true,
isApisMicroservicesCert: true,
isInfosecQaCert: true,
isQaCertV7: true,
isInfosecCertV7: true,
isSciCompPyCertV7: true,
isDataAnalysisPyCertV7: true,
isMachineLearningPyCertV7: true,
username: true,
name: true,
isHonest: true,
completedChallenges: true
}).subscribe(user => {
if (!user) {
return res.status(404).json({
message: {
type: 'info',
message: 'flash.username-not-found',
variables: { username }
}
});
}
if (!certTypeIds[certType]) {
return res.status(404).json({
message: {
type: 'info',
// TODO: create a specific 'flash.cert-not-found' message
message: 'flash.could-not-find'
}
});
}
return Observable.of(certTypeIds[certType])
.flatMap(challenge => {
const certName = certTypeTitleMap[certType];
const { tests = [] } = challenge;
let result = 'incomplete-requirements';
let status = false;
const { isHonest, completedChallenges } = user;
const isProjectsCompleted = canClaim(tests, completedChallenges);
if (isHonest && isProjectsCompleted) {
status = true;
result = 'requirements-met';
} else if (isProjectsCompleted) {
result = 'projects-completed';
} else if (isHonest) {
result = 'is-honest';
}
return Observable.just({
type: 'success',
message: { status, result },
variables: { name: certName }
});
})
.subscribe(message => {
return res.status(200).json({
response: message,
isCertMap: getUserIsCertMap(user),
// send back the completed challenges
// NOTE: we could just send back the latest challenge, but this
// ensures the challenges are synced.
completedChallenges: user.completedChallenges
});
}, next);
});
};
}