def add_note(self, note, author="<automated>"): """Add an admin note about the user.""" from r2.models.admin_notes import AdminNotesBySystem AdminNotesBySystem.add( system_name="user", subject=self.name, note=note, author=author, when=datetime.now(g.tz), )
def __init__(self, system, subject): from r2.models.admin_notes import AdminNotesBySystem self.system = system self.subject = subject self.author = c.user.name self.notes = AdminNotesBySystem.in_display_order(system, subject) # Convert timestamps for easier reading/translation for note in self.notes: note["timesince"] = timesince(note["when"]) Templated.__init__(self)
def __init__(self, system, subject, subject_user=None): from r2.models.admin_notes import AdminNotesBySystem self.system = system self.subject = subject self.author = c.user.name self.notes = AdminNotesBySystem.in_display_order(system, subject) self.global_ban = 'yes' if subject_user and subject_user.is_global_banned else 'no' # Convert timestamps for easier reading/translation for note in self.notes: note["timesince"] = timesince(note["when"]) Templated.__init__(self)
def deleted_account_cleanup(data): from r2.models import Subreddit from r2.models.admin_notes import AdminNotesBySystem from r2.models.flair import Flair from r2.models.token import OAuth2Client for account_id36 in data.itervalues(): account = Account._byID36(account_id36, data=True) if not account._deleted: continue # wipe the account's password and email address account.password = "" account.email = "" account.email_verified = False notes = "" # "noisy" rel removals, we'll record all of these in the account's # usernotes in case we need the information later rel_removal_descriptions = { "moderator": "Unmodded", "moderator_invite": "Cancelled mod invite", "contributor": "Removed as contributor", "banned": "Unbanned", "wikibanned": "Un-wikibanned", "wikicontributor": "Removed as wiki contributor", } if account.has_subscribed: rel_removal_descriptions["subscriber"] = "Unsubscribed" for rel_type, description in rel_removal_descriptions.iteritems(): try: ids_fn = getattr(Subreddit, "reverse_%s_ids" % rel_type) sr_ids = ids_fn(account) sr_names = [] srs = Subreddit._byID(sr_ids, data=True, return_dict=False) for subreddit in srs: remove_fn = getattr(subreddit, "remove_" + rel_type) remove_fn(account) sr_names.append(subreddit.name) if description and sr_names: sr_list = ", ".join(sr_names) notes += "* %s from %s\n" % (description, sr_list) except Exception as e: notes += "* Error cleaning up %s rels: %s\n" % (rel_type, e) # silent rel removals, no record left in the usernotes rel_classes = { "flair": Flair, "friend": Friend, "enemy": Friend, } for rel_name, rel_cls in rel_classes.iteritems(): try: rels = rel_cls._query( rel_cls.c._thing2_id == account._id, rel_cls.c._name == rel_name, eager_load=True, ) for rel in rels: remove_fn = getattr(rel._thing1, "remove_" + rel_name) remove_fn(account) except Exception as e: notes += "* Error cleaning up %s rels: %s\n" % (rel_name, e) # add the note with info about the major changes to the account if notes: AdminNotesBySystem.add( system_name="user", subject=account.name, note="Account deletion cleanup summary:\n\n%s" % notes, author="<automated>", when=datetime.now(g.tz), ) account._commit()
def add_note(self, note, author="<automated>"): """Add an admin note about the user.""" from r2.models.admin_notes import AdminNotesBySystem AdminNotesBySystem.add(system_name="user", subject=self.name, note=note, author=author, when=datetime.now(g.tz))