Helper scripts to fix some buggy users.

We have a lot of forged users that have bad fullnames due to
historical versions of our fullname computations; this function will
clean those up.

Also, we have a bunch of users with emails like foo|mit.edu@mit.edu
that were the result of a mirroring bug that we want to get rid of
from autocomplete -- putting them in a useless realm name will do.

(imported from commit 6e305093653ca9d327e9e28491636e99d16cfe1d)
This commit is contained in:
Tim Abbott
2012-11-14 13:40:25 -05:00
parent aecb8bd849
commit b22249d861
2 changed files with 50 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
from optparse import make_option
from django.core.management.base import BaseCommand
from zephyr.models import Realm, UserProfile
# Helper to be used with manage.py shell to get rid of bad users on prod.
def banish_busted_users(change=False):
for u in UserProfile.objects.select_related().all():
if (u.user.is_active or u.realm.domain != "mit.edu"):
continue
(banished_realm, _) = Realm.objects.get_or_create(domain="mit.deleted")
if "|mit.edu@mit.edu" in u.user.email:
print u.user.email
if change:
u.realm = banished_realm
u.user.email = u.user.email.split("@")[0] + "@" + banished_realm
u.user.save()
u.save()
class Command(BaseCommand):
option_list = BaseCommand.option_list + (
make_option('--dry-run', '-n', dest='dry_run', default=False, action='store_true'),)
def handle(self, *args, **options):
banish_busted_users(change=not options['dry_run'])

View File

@@ -0,0 +1,25 @@
from optparse import make_option
from django.core.management.base import BaseCommand
from zephyr.models import UserProfile, compute_mit_user_fullname
# Helper to be used with manage.py shell to fix bad names on prod.
def update_mit_fullnames(change=False):
for u in UserProfile.objects.select_related().all():
if (u.user.is_active or u.realm.domain != "mit.edu"):
# Don't change fullnames for non-MIT users or users who
# actually have an account (is_active) and thus have
# presumably set their fullname how they like it.
continue
computed_name = compute_mit_user_fullname(u.user.email)
if u.full_name != computed_name:
print "%s: %s => %s" % (u.user.email, u.full_name, computed_name)
if change:
u.full_name = computed_name
u.save()
class Command(BaseCommand):
option_list = BaseCommand.option_list + (
make_option('--dry-run', '-n', dest='dry_run', default=False, action='store_true'),)
def handle(self, *args, **options):
update_mit_fullnames(change=not options['dry_run'])