Skip to content
Commits on Source (6)
......@@ -10,7 +10,16 @@ class Command(BaseCommand):
Command to protect sensitive data during the beta phase, to prevent a right escalation.
Phone number, email address, postal address, first and last name are removed.
"""
def add_arguments(self, parser):
parser.add_argument('--force', '-f', action='store_true', help="Actually anonymize data.")
def handle(self, *args, **kwargs):
if not kwargs['force']:
self.stderr.write("CAUTION: This is a dangerous script. This will reset all personal data with "
"sample data. Don't use this in production! If you know what you are doing, "
"please add --force option.")
exit(1)
cur = connection.cursor()
cur.execute("UPDATE member_profile SET "
"phone_number = '0123456789', "
......
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from django.core.mail import send_mail
from django.core.management import BaseCommand
from django.db.models import Sum, F
......@@ -14,7 +14,6 @@ class Command(BaseCommand):
parser.add_argument('--check-all', '-a', action='store_true', help='Check all notes')
parser.add_argument('--check', '-c', type=int, nargs='+', help='Select note ids')
parser.add_argument('--fix', '-f', action='store_true', help='Fix note balances')
parser.add_argument('--mail', '-m', action='store_true', help='Send mail to admins if there is an error')
def handle(self, *args, **options):
error = False
......
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
import os
from django.conf import settings
......@@ -12,9 +13,6 @@ class Command(BaseCommand):
"""
Generate Javascript translation files
"""
def add_arguments(self, parser):
parser.add_argument('--out', '-o', type=str, default='static', help='Output directory, where static files are.')
def handle(self, *args, **kwargs):
for code, _ in settings.LANGUAGES:
if code == settings.LANGUAGE_CODE:
......@@ -23,7 +21,7 @@ class Command(BaseCommand):
self.stdout.write(f"Generate {code} javascript localization file")
with translation.override(code):
resp = JavaScriptCatalog().get(None, packages="member+note")
if not os.path.isdir(kwargs["out"] + "/js/jsi18n"):
os.makedirs(kwargs["out"] + "/js/jsi18n")
with open(kwargs["out"] + f"/js/jsi18n/{code}.js", "wb") as f:
if not os.path.isdir(settings.STATIC_ROOT + "/js/jsi18n"):
os.makedirs(settings.STATIC_ROOT + "/js/jsi18n")
with open(settings.STATIC_ROOT + f"/js/jsi18n/{code}.js", "wb") as f:
f.write(resp.content)
......@@ -78,11 +78,11 @@ class Command(BaseCommand):
# Deleting transactions
transactions = Transaction.objects.filter(Q(source=user.note) | Q(destination=user.note)).all()
local_deleted += list(transactions)
if kwargs['verbosity'] >= 1:
for tr in transactions:
for tr in transactions:
if kwargs['verbosity'] >= 1:
self.stdout.write(f"Removing {tr}...")
if force:
transactions.delete()
if force:
tr.delete()
# Deleting memberships
memberships = user.memberships.all()
......@@ -173,4 +173,5 @@ class Command(BaseCommand):
message += "Ont été supprimés en conséquence les objets suivants :\n\n"
for obj in deleted:
message += f"{repr(obj)} (pk: {obj.pk})\n"
mail_admins("Utilisateurs supprimés", message)
if force and kwargs['doit']:
mail_admins("Utilisateurs supprimés", message)
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from datetime import date
from datetime import date, timedelta
from django.core.mail import send_mail
from django.core.management import BaseCommand
......@@ -17,12 +17,22 @@ class Command(BaseCommand):
parser.add_argument("--spam", "-s", action='store_true', help="Spam negative users")
parser.add_argument("--report", "-r", action='store_true', help="Report the list of negative users to admins")
parser.add_argument("--negative-amount", "-n", action='store', type=int, default=1000,
help="Maximum amount to be considered as very negative")
help="Maximum amount to be considered as very negative (inclusive)")
parser.add_argument("--add-years", "-y", action='store', type=int, default=0,
help="Add also people that have a negative balance since N years "
"(default to only active members)")
def handle(self, *args, **options):
activate('fr')
if options['negative_amount'] == 0:
# Don't log empty notes
options['negative_amount'] = 0.01
notes = Note.objects.filter(
Q(noteuser__user__memberships__date_end__gte=date.today()) | Q(noteclub__isnull=False),
Q(noteuser__user__memberships__date_end__gte=
date.today() - timedelta(days=int(365.25 * options['add_years'])))
| Q(noteclub__isnull=False),
balance__lte=-options["negative_amount"],
is_active=True,
).order_by('balance').distinct().all()
......