fix(api): reset all claimed certs during reset (#54883)

This commit is contained in:
Oliver Eyton-Williams
2024-05-28 18:03:43 +02:00
committed by GitHub
parent 52baa10c59
commit dae7701b1a
4 changed files with 41 additions and 55 deletions
+1 -1
View File
@@ -94,7 +94,7 @@ describe('dev login', () => {
showPortfolio: false,
showTimeLine: false
},
progressTimestamps: [],
progressTimestamps: [expect.any(Number)],
sendQuincyEmail: false,
theme: 'default',
username: expect.stringMatching(fccUuidRe),
+2
View File
@@ -402,6 +402,8 @@ describe('userRoutes', () => {
expect(userTokens).toHaveLength(1);
expect(userTokens[0]?.userId).toBe(otherUserId);
});
test.todo('POST resets the user to the default state');
});
describe('/user/user-token', () => {
+2 -27
View File
@@ -22,6 +22,7 @@ import {
import { encodeUserToken } from '../utils/tokens';
import { trimTags } from '../utils/validation';
import { generateReportEmail } from '../utils/email-templates';
import { createResetProperties } from '../utils/create-user';
// user flags that the api-server returns as false if they're missing in the
// user document. Since Prisma returns null for missing fields, we need to
@@ -148,33 +149,7 @@ export const userRoutes: FastifyPluginCallbackTypebox = (
});
await fastify.prisma.user.update({
where: { id: req.user!.id },
data: {
progressTimestamps: [Date.now()],
currentChallengeId: '',
isRespWebDesignCert: false,
is2018DataVisCert: false,
isFrontEndLibsCert: false,
isJsAlgoDataStructCert: false,
isApisMicroservicesCert: false,
isInfosecQaCert: false,
isQaCertV7: false,
isInfosecCertV7: false,
is2018FullStackCert: false,
isFrontEndCert: false,
isBackEndCert: false,
isDataVisCert: false,
isFullStackCert: false,
isSciCompPyCertV7: false,
isDataAnalysisPyCertV7: false,
isMachineLearningPyCertV7: false,
isRelationalDatabaseCertV8: false,
isCollegeAlgebraPyCertV8: false,
completedChallenges: [],
completedExams: [],
savedChallenges: [],
partiallyCompletedChallenges: [],
needsModeration: false
}
data: createResetProperties()
});
return {};
+36 -27
View File
@@ -7,6 +7,40 @@ export const nanoidCharSet =
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
const nanoid = customAlphabet(nanoidCharSet, 21);
/**
* Creates the necessary data to reset a user's properties.
* @returns Default data for resetting a user's properties.
*/
export const createResetProperties = () => ({
completedChallenges: [], // TODO(Post-MVP): Omit this from the document? (prisma will always return [])
completedExams: [], // TODO(Post-MVP): Omit this from the document? (prisma will always return [])
currentChallengeId: '',
is2018DataVisCert: false,
is2018FullStackCert: false,
isApisMicroservicesCert: false,
isBackEndCert: false,
isCollegeAlgebraPyCertV8: false,
isDataAnalysisPyCertV7: false,
isDataVisCert: false,
isFoundationalCSharpCertV8: false,
isFrontEndCert: false,
isFrontEndLibsCert: false,
isFullStackCert: false,
isInfosecCertV7: false,
isInfosecQaCert: false,
isJsAlgoDataStructCert: false,
isJsAlgoDataStructCertV8: false,
isMachineLearningPyCertV7: false,
isQaCertV7: false,
isRelationalDatabaseCertV8: false,
isRespWebDesignCert: false,
isSciCompPyCertV7: false,
needsModeration: false,
partiallyCompletedChallenges: [], // TODO(Post-MVP): Omit this from the document? (prisma will always return [])
progressTimestamps: [Date.now()], // TODO(Post-MVP): This may need normalising before we can omit it. Also, does it need to start with a timestamp?
savedChallenges: [] // TODO(Post-MVP): Omit this from the document? (prisma will always return [])
});
/**
* Creates the necessary data to create a new user.
* @param email The email address of the new user.
@@ -22,43 +56,19 @@ export function createUserInput(email: string): Prisma.userCreateInput {
return {
about: '',
acceptedPrivacyTerms: false,
completedChallenges: [], // TODO(Post-MVP): Omit this from the document? (prisma will always return [])
completedExams: [], // TODO(Post-MVP): Omit this from the document? (prisma will always return [])
currentChallengeId: '',
donationEmails: [], // TODO(Post-MVP): Omit this from the document? (prisma will always return [])
email,
emailVerified: true, // this should be true until a user changes their email address
// TODO(Post-MVP): remove externalId?
externalId,
is2018DataVisCert: false,
is2018FullStackCert: false,
isApisMicroservicesCert: false,
isBackEndCert: false,
isBanned: false,
isCheater: false,
isDataAnalysisPyCertV7: false,
isDataVisCert: false,
isDonating: false,
isFoundationalCSharpCertV8: false,
isFrontEndCert: false,
isFrontEndLibsCert: false,
isFullStackCert: false,
isHonest: false,
isInfosecCertV7: false,
isInfosecQaCert: false,
isJsAlgoDataStructCert: false,
isJsAlgoDataStructCertV8: false,
isMachineLearningPyCertV7: false,
isQaCertV7: false,
isRelationalDatabaseCertV8: false,
isCollegeAlgebraPyCertV8: false,
isRespWebDesignCert: false,
isSciCompPyCertV7: false,
keyboardShortcuts: false,
location: '',
name: '',
unsubscribeId: nanoid(),
partiallyCompletedChallenges: [], // TODO(Post-MVP): Omit this from the document? (prisma will always return [])
picture: '',
portfolio: [], // TODO(Post-MVP): Omit this from the document? (prisma will always return [])
profileUI: {
@@ -73,12 +83,11 @@ export function createUserInput(email: string): Prisma.userCreateInput {
showPortfolio: false,
showTimeLine: false
},
progressTimestamps: [], // TODO(Post-MVP): This may need normalising before we can omit it.
savedChallenges: [], // TODO(Post-MVP): Omit this from the document? (prisma will always return [])
sendQuincyEmail: false,
theme: 'default',
username,
usernameDisplay: username,
yearsTopContributor: [] // TODO: Omit this from the document? (prisma will always return [])
yearsTopContributor: [], // TODO: Omit this from the document? (prisma will always return []),
...createResetProperties()
};
}