mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
fix(deletion): user delete bugs
Correct lookup in GDPR script, and address a TypeError when deleting a user with no tasks
This commit is contained in:
@@ -27,12 +27,13 @@ async function _deleteAmplitudeData (userId, email) {
|
||||
if (response) console.log(`${response.status} ${response.statusText}`);
|
||||
}
|
||||
|
||||
async function _deleteHabiticaData (user) {
|
||||
async function _deleteHabiticaData (user, email) {
|
||||
await User.update(
|
||||
{_id: user._id},
|
||||
{$set: {
|
||||
'auth.local.passwordHashMethod': 'bcrypt',
|
||||
'auth.local.email': email,
|
||||
'auth.local.hashed_password': '$2a$10$QDnNh1j1yMPnTXDEOV38xOePEWFd4X8DSYwAM8XTmqmacG5X0DKjW',
|
||||
'auth.local.passwordHashMethod': 'bcrypt',
|
||||
}}
|
||||
);
|
||||
const response = await axios.delete(
|
||||
@@ -61,8 +62,8 @@ async function _processEmailAddress (email) {
|
||||
const users = await User.find({
|
||||
$or: [
|
||||
{'auth.local.email': emailRegex},
|
||||
{'auth.facebook.emails.value': emailRegex},
|
||||
{'auth.google.emails.value': emailRegex},
|
||||
{'auth.facebook.emails': emailRegex},
|
||||
{'auth.google.emails': emailRegex},
|
||||
]},
|
||||
{
|
||||
_id: 1,
|
||||
@@ -75,7 +76,7 @@ async function _processEmailAddress (email) {
|
||||
} else {
|
||||
for (const user of users) {
|
||||
await _deleteAmplitudeData(user._id, email); // eslint-disable-line no-await-in-loop
|
||||
await _deleteHabiticaData(user); // eslint-disable-line no-await-in-loop
|
||||
await _deleteHabiticaData(user, email); // eslint-disable-line no-await-in-loop
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1376,12 +1376,15 @@ schema.methods.unlinkTask = async function groupUnlinkTask (unlinkingTask, user,
|
||||
} else { // keep = 'remove-all'
|
||||
let task = await Tasks.Task.findOne(findQuery).select('_id type completed').exec();
|
||||
// Remove task from user.tasksOrder and delete them
|
||||
if (task.type !== 'todo' || !task.completed) {
|
||||
if (task && (task.type !== 'todo' || !task.completed)) {
|
||||
removeFromArray(user.tasksOrder[`${task.type}s`], task._id);
|
||||
user.markModified('tasksOrder');
|
||||
}
|
||||
|
||||
const promises = [task.remove(), unlinkingTask.save()];
|
||||
let promises = [unlinkingTask.save()];
|
||||
if (task) {
|
||||
promises.push(task.remove());
|
||||
}
|
||||
// When multiple tasks are being unlinked at the same time,
|
||||
// save the user once outside of this function
|
||||
if (saveUser) promises.push(user.save());
|
||||
|
||||
Reference in New Issue
Block a user