1
0
mirror of https://gitlab.crans.org/bde/nk20-scripts synced 2025-02-23 16:41:24 +00:00

Compare commits

...

5 Commits

Author SHA1 Message Date
0c7070aea1
Send mail to admins if a user got deleted iff it was successfully deleted
Signed-off-by: Yohann D'ANELLO <ynerant@crans.org>
2021-04-22 18:33:20 +02:00
961365656c
Compile Javascript translations in STATIC_ROOT directory
Signed-off-by: Yohann D'ANELLO <ynerant@crans.org>
2021-04-22 16:20:24 +02:00
076e1f0013
Mails are sent by the cron, not by the script
Signed-off-by: Yohann D'ANELLO <ynerant@crans.org>
2021-04-22 15:45:15 +02:00
f8feff7c55
Prevent data deletion in the anonymization script
Signed-off-by: Yohann D'ANELLO <ynerant@crans.org>
2021-04-22 15:40:10 +02:00
0fc9c4c50e
In the force delete script, delete transactions transaction by transaction
Signed-off-by: Yohann D'ANELLO <ynerant@crans.org>
2021-04-22 15:13:14 +02:00
4 changed files with 20 additions and 13 deletions

View File

@ -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', "

View File

@ -1,6 +1,6 @@
# 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

View File

@ -1,5 +1,6 @@
# 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)

View File

@ -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)