Skip to content

Commit

Permalink
feat: add userswithaccounts obfuscation (#1218)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevbarns authored May 3, 2024
1 parent 9448b26 commit 7a6511d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions server/src/jobs/database/obfuscateCollections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,21 @@ const obfuscateUser = async () => {
logger.info(`obfuscating users done`)
}

const obfuscateUsersWithAccounts = async () => {
logger.info(`obfuscating userswithaccounts`)
const users: AsyncIterable<IUser> = await db.collection("userswithaccounts").find({})
for await (const user of users) {
const email = getFakeEmail()
const replacement = {
$set: { email, phone: "0601010106", last_name: "nom_famille", first_name: "prenom" },
$push: { status: { granted_by: "server", date: new Date(), reason: "ofuscation", status: "DESACTIVE", validation_type: "AUTOMATIQUE" } },
}
await db.collection("userswithaccounts").findOneAndUpdate({ _id: user._id }, replacement)
}

logger.info(`obfuscating users done`)
}

export async function obfuscateCollections(): Promise<void> {
if (config.env === "production") {
// prévention :)
Expand All @@ -254,5 +269,6 @@ export async function obfuscateCollections(): Promise<void> {
await obfuscateFormations()
await obfuscateRecruiter()
await obfuscateUser()
await obfuscateUsersWithAccounts()
await Optout.deleteMany({})
}

0 comments on commit 7a6511d

Please sign in to comment.