From b79406131b542bd5f34394ca81bee96ea3695889 Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Sat, 17 Jun 2023 21:14:02 +0200 Subject: [PATCH] =?UTF-8?q?Kontrola=20pr=C3=A1v,=20v1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit RFC! --- personalni/management/__init__.py | 0 personalni/management/commands/__init__.py | 0 .../commands/check_org_permissions.py | 34 +++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 personalni/management/__init__.py create mode 100644 personalni/management/commands/__init__.py create mode 100644 personalni/management/commands/check_org_permissions.py diff --git a/personalni/management/__init__.py b/personalni/management/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/personalni/management/commands/__init__.py b/personalni/management/commands/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/personalni/management/commands/check_org_permissions.py b/personalni/management/commands/check_org_permissions.py new file mode 100644 index 00000000..4e937412 --- /dev/null +++ b/personalni/management/commands/check_org_permissions.py @@ -0,0 +1,34 @@ +from django.core.management.base import BaseCommand +import logging + +from django.contrib.auth.models import User, Group +import seminar.models as m +from datetime import date + +logger = logging.getLogger(__name__) + +class Command(BaseCommand): + def handle(self, *args, **options): + org_group = Group.objects.get(name='org') + stari_orgove = set() + nesparovani = set() + for u in User.objects.all(): + if u.is_staff or u in org_group.user_set.all() or u.has_perm('auth.org'): + # Dohledáme orga + # Používáme .filter, protože se nemusí najít + orgove = m.Organizator.objects.filter(osoba__user=u) + if orgove.count() != 1: + nesparovani.add(u) + org = orgove.first() + # Pokud už není aktivní, tak ho vypíšeme + # Porovnáváme data, protože neřeší časové zóny (datetime.now není tz-aware) + if org.organizuje_do is not None and org.organizuje_do.date() < date.today(): + stari_orgove.add(org) + if len(nesparovani) > 0: + print('Účty s právy, ke kterým neznáme orga:') + for x in nesparovani: + print(f'\t{x}') + if len(stari_orgove) > 0: + print('Staří orgové, kterým zóstala práva a neměla:') + for x in stari_orgove: + print(f'\t{x}')