mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-15 05:37:22 +01:00
Use new indexes in GDPR script (#11567)
* fix(script): use new indexes * fix(lint): linting errors * fix(lint): moar lint
This commit is contained in:
@@ -24,7 +24,13 @@ async function deleteAmplitudeData (userId, email) {
|
|||||||
console.log(err.response.data);
|
console.log(err.response.data);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response) console.log(`${response.status} ${response.statusText}`);
|
if (response) {
|
||||||
|
if (response.status === 200) {
|
||||||
|
console.log(`${userId} (${email}) Amplitude deletion request OK.`);
|
||||||
|
} else {
|
||||||
|
console.log(`${userId} (${email}) Amplitude response: ${response.status} ${response.statusText}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteHabiticaData (user, email) {
|
async function deleteHabiticaData (user, email) {
|
||||||
@@ -54,39 +60,46 @@ async function deleteHabiticaData (user, email) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (response) {
|
if (response) {
|
||||||
console.log(`${response.status} ${response.statusText}`);
|
if (response.status === 200) {
|
||||||
if (response.status === 200) console.log(`${user._id} (${email}) removed. Last login: ${user.auth.timestamps.loggedin}`);
|
console.log(`${user._id} (${email}) removed from Habitica. Last login: ${user.auth.timestamps.loggedin}`);
|
||||||
|
} else {
|
||||||
|
console.log(`${user._id} (${email}) Habitica response: ${response.status} ${response.statusText}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function processEmailAddress (email) {
|
async function processEmailAddress (email) {
|
||||||
const emailRegex = new RegExp(`^${email}$`, 'i');
|
const emailRegex = new RegExp(`^${email}$`, 'i');
|
||||||
const users = await User.find({
|
const localUsers = await User.find(
|
||||||
$or: [
|
{ 'auth.local.email': emailRegex },
|
||||||
{ 'auth.local.email': emailRegex },
|
{ _id: 1, apiToken: 1, auth: 1 },
|
||||||
{ 'auth.facebook.emails.value': emailRegex },
|
).exec();
|
||||||
{ 'auth.google.emails.value': emailRegex },
|
|
||||||
],
|
const socialUsers = await User.find(
|
||||||
},
|
{
|
||||||
{
|
$or: [
|
||||||
_id: 1,
|
{ 'auth.facebook.emails.value': email },
|
||||||
apiToken: 1,
|
{ 'auth.google.emails.value': email },
|
||||||
auth: 1,
|
],
|
||||||
}).exec();
|
},
|
||||||
|
{ _id: 1, apiToken: 1, auth: 1 },
|
||||||
|
).collation(
|
||||||
|
{ locale: 'en', strength: 1 },
|
||||||
|
).exec();
|
||||||
|
|
||||||
|
const users = localUsers.concat(socialUsers);
|
||||||
|
|
||||||
if (users.length < 1) {
|
if (users.length < 1) {
|
||||||
console.log(`No users found with email address ${email}`);
|
return console.log(`No users found with email address ${email}`);
|
||||||
} else {
|
|
||||||
Promise.all(users.map(user => (async () => {
|
|
||||||
await deleteAmplitudeData(user._id, email); // eslint-disable-line no-await-in-loop
|
|
||||||
await deleteHabiticaData(user, email); // eslint-disable-line no-await-in-loop
|
|
||||||
})()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Promise.all(users.map(user => (async () => {
|
||||||
|
await deleteAmplitudeData(user._id, email); // eslint-disable-line no-await-in-loop
|
||||||
|
await deleteHabiticaData(user, email); // eslint-disable-line no-await-in-loop
|
||||||
|
})()));
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteUserData (emails) {
|
export default function deleteUserData (emails) {
|
||||||
const emailPromises = emails.map(processEmailAddress);
|
const emailPromises = emails.map(processEmailAddress);
|
||||||
return Promise.all(emailPromises);
|
return Promise.all(emailPromises);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = deleteUserData;
|
|
||||||
|
|||||||
Reference in New Issue
Block a user