mozilla/openbadges — pull request #903 by stenington (2013-08-08 16:55:22+00:00)
Title: Account removal

Here's a somewhat frightening proposal for dealing with account removal in the backpack. I think I'd be just as happy having it shot down as accepted, but I'm a wimp about these things.

I've added a `User.deleteAccount` method that gathers up a user's badges, groups, and portfolios, and then deletes them all (unless `dryRun` is specified) returning all of that data. Then there's a `bin/db-account` utility that lets you run that from the command line given an email address.

The method itself is kind of awful for a few reasons:
* It finds and deletes entries one by one instead of using `findAndDestroy` because the latter doesn't return the deleted records.
* The code for deleting portfolios in a group, for example, should arguably live in the `Group` model, but I haven't done that. I wasn't even sure this functionality should be made readily available in the `User` object since it's only meant to be run very rarely, by hand, but it was more testable that way.
* It doesn't stream the results, and I'm not sure what the implications are of that for an account with lots of badges or groups or something.
* It's non-atomic, so we could theoretically end up with half-deleted accounts.

There are probably other problems too. I'm presenting this as a step up (hopefully) from doing manual database surgery in production instead.

@toolness @andrewhayward @brianloveswords