diff options
author | Sheogorath | 2020-03-21 16:07:14 +0100 |
---|---|---|
committer | Sheogorath | 2020-03-21 16:14:43 +0100 |
commit | a9d98d4b529e6dd4a4f978dd8facd4bf5a20861e (patch) | |
tree | 47abe564a0c2623a9e37fbb6466532c1eec179c0 /bin/cleanup | |
parent | 8ce7b285636c02b4215c838640bb748947c8317f (diff) |
Add fix for missing deletion of notes on user-deletion request
Depending on how the system was setup, this bug lead to keep user's data
around even after a successful deletion of user'S account. This patch
will make sure the missing database constraints are implemented and
missed out deletions are executed.
This bug was introduced to insufficent testing after implementing the
feature initially. It was well tested, using the app process itself, but
the migrations where missed out. I'm currently not sure, if there was
also a change in how sequelize handles cassaded deletion, since I'm
unter the impression that before switching to sequelize 5, this feature
has worked. But I haven't verified this.
No matter what, the cleanup process is rather straight forward and will
be invoked on migration, but can also be done manually using the new
`bin/cleanup` script.
This change will result in a release 1.6.1.
Signed-off-by: Sheogorath <sheogorath@shivering-isles.com>
Diffstat (limited to 'bin/cleanup')
-rwxr-xr-x | bin/cleanup | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/bin/cleanup b/bin/cleanup new file mode 100755 index 00000000..e2776bb7 --- /dev/null +++ b/bin/cleanup @@ -0,0 +1,56 @@ +#!/usr/bin/env node + +const logger = require("../lib/logger"); +const models = require('../lib/models') + +logger.info("Cleaning up notes that should already have been removed. Sorry.") + +async function cleanup() { + await models.Note.findAll({ + include: [{ + model: models.User, + as: 'owner' + }] + }).then(async function(notes) { + for(let i =0, noteCount = notes.length; i< noteCount; i++) { + const item = notes[i] + if(item.ownerId != null && !item.owner) { + await models.Note.destroy({ + where: { + id: item.id + }}) + await models.Revision.destroy({ + where: { + noteId: item.id + } + }) + await models.Author.destroy({ + where: { + noteId: item.id + } + }) + logger.info(`Deleted note ${item.id} from user ${item.ownerId}`) + } + } + }) + await models.Author.findAll({ + include: [{ + model: models.User, + as: 'user' + }] + }).then(async function(authors) { + for(let i =0, authorCount = authors.length; i< authorCount; i++) { + const item = authors[i] + if(item.userId != null && !item.user) { + await models.Author.destroy({ + where: { + id: item.id + }}) + logger.info(`Deleted authorship ${item.id} from user ${item.userId}`) + } + } + }) + process.exit(0) +} + +cleanup() |