mirror of
				https://gitlab.crans.org/bde/nk20-scripts
				synced 2025-11-04 16:32:26 +01:00 
			
		
		
		
	Compare commits
	
		
			5 Commits
		
	
	
		
			5ce65e36a8
			...
			0c7070aea1
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						
						
							
						
						0c7070aea1
	
				 | 
					
					
						|||
| 
						
						
							
						
						961365656c
	
				 | 
					
					
						|||
| 
						
						
							
						
						076e1f0013
	
				 | 
					
					
						|||
| 
						
						
							
						
						f8feff7c55
	
				 | 
					
					
						|||
| 
						
						
							
						
						0fc9c4c50e
	
				 | 
					
					
						
@@ -10,7 +10,16 @@ class Command(BaseCommand):
 | 
				
			|||||||
    Command to protect sensitive data during the beta phase, to prevent a right escalation.
 | 
					    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.
 | 
					    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):
 | 
					    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 = connection.cursor()
 | 
				
			||||||
        cur.execute("UPDATE member_profile SET "
 | 
					        cur.execute("UPDATE member_profile SET "
 | 
				
			||||||
                    "phone_number = '0123456789', "
 | 
					                    "phone_number = '0123456789', "
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
 | 
					# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
 | 
				
			||||||
# SPDX-License-Identifier: GPL-3.0-or-later
 | 
					# SPDX-License-Identifier: GPL-3.0-or-later
 | 
				
			||||||
from django.core.mail import send_mail
 | 
					
 | 
				
			||||||
from django.core.management import BaseCommand
 | 
					from django.core.management import BaseCommand
 | 
				
			||||||
from django.db.models import Sum, F
 | 
					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-all', '-a', action='store_true', help='Check all notes')
 | 
				
			||||||
        parser.add_argument('--check', '-c', type=int, nargs='+', help='Select note ids')
 | 
					        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('--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):
 | 
					    def handle(self, *args, **options):
 | 
				
			||||||
        error = False
 | 
					        error = False
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,6 @@
 | 
				
			|||||||
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
 | 
					# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
 | 
				
			||||||
# SPDX-License-Identifier: GPL-3.0-or-later
 | 
					# SPDX-License-Identifier: GPL-3.0-or-later
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from django.conf import settings
 | 
					from django.conf import settings
 | 
				
			||||||
@@ -12,9 +13,6 @@ class Command(BaseCommand):
 | 
				
			|||||||
    """
 | 
					    """
 | 
				
			||||||
    Generate Javascript translation files
 | 
					    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):
 | 
					    def handle(self, *args, **kwargs):
 | 
				
			||||||
        for code, _ in settings.LANGUAGES:
 | 
					        for code, _ in settings.LANGUAGES:
 | 
				
			||||||
            if code == settings.LANGUAGE_CODE:
 | 
					            if code == settings.LANGUAGE_CODE:
 | 
				
			||||||
@@ -23,7 +21,7 @@ class Command(BaseCommand):
 | 
				
			|||||||
                self.stdout.write(f"Generate {code} javascript localization file")
 | 
					                self.stdout.write(f"Generate {code} javascript localization file")
 | 
				
			||||||
            with translation.override(code):
 | 
					            with translation.override(code):
 | 
				
			||||||
                resp = JavaScriptCatalog().get(None, packages="member+note")
 | 
					                resp = JavaScriptCatalog().get(None, packages="member+note")
 | 
				
			||||||
                if not os.path.isdir(kwargs["out"] + "/js/jsi18n"):
 | 
					                if not os.path.isdir(settings.STATIC_ROOT + "/js/jsi18n"):
 | 
				
			||||||
                    os.makedirs(kwargs["out"] + "/js/jsi18n")
 | 
					                    os.makedirs(settings.STATIC_ROOT + "/js/jsi18n")
 | 
				
			||||||
                with open(kwargs["out"] + f"/js/jsi18n/{code}.js", "wb") as f:
 | 
					                with open(settings.STATIC_ROOT + f"/js/jsi18n/{code}.js", "wb") as f:
 | 
				
			||||||
                    f.write(resp.content)
 | 
					                    f.write(resp.content)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -78,11 +78,11 @@ class Command(BaseCommand):
 | 
				
			|||||||
                    # Deleting transactions
 | 
					                    # Deleting transactions
 | 
				
			||||||
                    transactions = Transaction.objects.filter(Q(source=user.note) | Q(destination=user.note)).all()
 | 
					                    transactions = Transaction.objects.filter(Q(source=user.note) | Q(destination=user.note)).all()
 | 
				
			||||||
                    local_deleted += list(transactions)
 | 
					                    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}...")
 | 
					                            self.stdout.write(f"Removing {tr}...")
 | 
				
			||||||
                    if force:
 | 
					                        if force:
 | 
				
			||||||
                        transactions.delete()
 | 
					                            tr.delete()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    # Deleting memberships
 | 
					                    # Deleting memberships
 | 
				
			||||||
                    memberships = user.memberships.all()
 | 
					                    memberships = user.memberships.all()
 | 
				
			||||||
@@ -173,4 +173,5 @@ class Command(BaseCommand):
 | 
				
			|||||||
            message += "Ont été supprimés en conséquence les objets suivants :\n\n"
 | 
					            message += "Ont été supprimés en conséquence les objets suivants :\n\n"
 | 
				
			||||||
            for obj in deleted:
 | 
					            for obj in deleted:
 | 
				
			||||||
                message += f"{repr(obj)} (pk: {obj.pk})\n"
 | 
					                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)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user