diff --git a/management/commands/anonymize_data.py b/management/commands/anonymize_data.py new file mode 100644 index 0000000..304cbdb --- /dev/null +++ b/management/commands/anonymize_data.py @@ -0,0 +1,21 @@ +# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay +# SPDX-License-Identifier: GPL-3.0-or-later + +from django.core.management.base import BaseCommand +from django.db import connection + + +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 handle(self, *args, **kwargs): + cur = connection.cursor() + cur.execute("UPDATE member_profile SET " + "phone_number = '0123456789', " + "address = '4 avenue des Sciences, 91190 GIF-SUR-YVETTE';") + cur.execute("UPDATE auth_user SET " + "first_name = 'Anne', " + "last_name = 'Onyme';") + cur.close() diff --git a/management/commands/import_account.py b/management/commands/import_account.py index 4a88e2d..8ac35ad 100644 --- a/management/commands/import_account.py +++ b/management/commands/import_account.py @@ -110,6 +110,7 @@ class Command(ImportCommand): "phone_number": row['tel'], "address": row['adresse'], "paid": row['normalien'], + "section": row["section"], "registration_valid": True, "email_confirmed": True, } diff --git a/management/commands/import_transaction.py b/management/commands/import_transaction.py index 2f380db..7d40658 100644 --- a/management/commands/import_transaction.py +++ b/management/commands/import_transaction.py @@ -295,7 +295,7 @@ class Command(ImportCommand): remittance_dict = { "pk": pk_remittance, - "date": make_aware(row["date"]), + "date": make_aware(row["date"][:19]), "remittance_type_id": 1, # Only Bank checks are supported in NK15 "comment": row["commentaire"], "closed": row["close"], @@ -315,6 +315,9 @@ class Command(ImportCommand): for idx, row in enumerate(cur): self.update_line(idx, n, row["nom"]) + if not row["idremise"]: + continue + tr = SpecialTransactionProxy.objects.get(transaction__id=MAP_TRANSACTION[row["idtransaction"]]) tr.remittance_id = MAP_REMITTANCE[row["idremise"]] tr.save() diff --git a/management/commands/refresh_highlighted_buttons.py b/management/commands/refresh_highlighted_buttons.py index 3b20fff..bcf53c4 100644 --- a/management/commands/refresh_highlighted_buttons.py +++ b/management/commands/refresh_highlighted_buttons.py @@ -14,10 +14,6 @@ class Command(BaseCommand): """ Command to add the ten most used buttons of the past month to the highlighted buttons. """ - - def add_arguments(self, parser): - return parser - def handle(self, *args, **kwargs): queryset = RecurrentTransaction.objects.filter( template__display=True, diff --git a/management/commands/syncsql.py b/management/commands/syncsql.py index 05d94a6..3bd24ba 100644 --- a/management/commands/syncsql.py +++ b/management/commands/syncsql.py @@ -11,7 +11,7 @@ from polymorphic.models import PolymorphicModel NO_SEQ = [ "Session", "Token", - "WEIRole", # dirty fix + "WEIRole", # dirty fix ] class Command(BaseCommand): @@ -33,10 +33,14 @@ class Command(BaseCommand): # no app specified, sync everything model_classes = apps.get_models(include_auto_created=True) - db_names = [ m._meta.db_table for m in model_classes if m.__base__.__base__ is not PolymorphicModel and m.__name__ not in NO_SEQ and m.objects.count()>1] + db_names = [ + m._meta.db_table for m in model_classes + if m.__base__.__base__ is not PolymorphicModel and m.__name__ not in NO_SEQ and m.objects.count() > 1 + ] com = "BEGIN;\n" for db_name in db_names: - com += f'SELECT setval(pg_get_serial_sequence(\'"{db_name}"\',\'id\'), coalesce(max("id"), 1), max("id") IS NOT null) FROM "{db_name}";\n' + com += f'SELECT setval(pg_get_serial_sequence(\'"{db_name}"\',\'id\'), coalesce(max("id"), 1),' \ + f' max("id") IS NOT null) FROM "{db_name}";\n' com += "COMMIT;" print(com) cur = connection.cursor()