From b79406131b542bd5f34394ca81bee96ea3695889 Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Sat, 17 Jun 2023 21:14:02 +0200 Subject: [PATCH 1/3] =?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}') -- 2.39.5 From 5b5a83b4d566d9e21e0e1313ec91fcd214712250 Mon Sep 17 00:00:00 2001 From: MaM Web user Date: Sat, 17 Jun 2023 21:38:38 +0200 Subject: [PATCH 2/3] =?UTF-8?q?Chyb=C4=9Bj=C3=ADc=C3=AD=20continue=20:-)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- personalni/management/commands/check_org_permissions.py | 1 + 1 file changed, 1 insertion(+) diff --git a/personalni/management/commands/check_org_permissions.py b/personalni/management/commands/check_org_permissions.py index 4e937412..14f934a1 100644 --- a/personalni/management/commands/check_org_permissions.py +++ b/personalni/management/commands/check_org_permissions.py @@ -19,6 +19,7 @@ class Command(BaseCommand): orgove = m.Organizator.objects.filter(osoba__user=u) if orgove.count() != 1: nesparovani.add(u) + continue 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) -- 2.39.5 From 166fe0862abfbc3f018916928eab6cd9393b7274 Mon Sep 17 00:00:00 2001 From: MaM Web user Date: Sat, 17 Jun 2023 21:38:51 +0200 Subject: [PATCH 3/3] =?UTF-8?q?Vypisujeme=20i=20u=C5=BEivatele,=20pro=20ul?= =?UTF-8?q?eh=C4=8Den=C3=AD=20weba=C5=99=C5=AFm=20:-)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- personalni/management/commands/check_org_permissions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/personalni/management/commands/check_org_permissions.py b/personalni/management/commands/check_org_permissions.py index 14f934a1..3a66d5cc 100644 --- a/personalni/management/commands/check_org_permissions.py +++ b/personalni/management/commands/check_org_permissions.py @@ -32,4 +32,4 @@ class Command(BaseCommand): 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}') + print(f'\t{x}\torg: {x.osoba.user.username}') -- 2.39.5