From 3d5b9a669d098769b66267d0e804c64ba7a72e64 Mon Sep 17 00:00:00 2001 From: Lukas Juhrich Date: Wed, 4 Sep 2024 16:23:39 +0200 Subject: [PATCH] extract `can_target` to `.permissions` module --- pycroft/lib/user/__init__.py | 2 +- pycroft/lib/user/_old.py | 6 ------ pycroft/lib/user/edit.py | 3 ++- pycroft/lib/user/passwords.py | 3 +-- pycroft/lib/user/permission.py | 8 ++++++++ 5 files changed, 12 insertions(+), 10 deletions(-) create mode 100644 pycroft/lib/user/permission.py diff --git a/pycroft/lib/user/__init__.py b/pycroft/lib/user/__init__.py index 21cfed8e5..505d65a0e 100644 --- a/pycroft/lib/user/__init__.py +++ b/pycroft/lib/user/__init__.py @@ -2,7 +2,6 @@ setup_ipv4_networking, store_user_sheet, get_user_sheet, - can_target, create_user, login_available, move_in, @@ -76,6 +75,7 @@ from .mail_confirmation import ( confirm_mail_address, ) +from .permission import can_target from .exc import ( HostAliasExists, diff --git a/pycroft/lib/user/_old.py b/pycroft/lib/user/_old.py index 8c07e3c21..ce87cb806 100644 --- a/pycroft/lib/user/_old.py +++ b/pycroft/lib/user/_old.py @@ -135,12 +135,6 @@ def get_user_sheet(sheet_id: int) -> bytes | None: return storage.data -def can_target(user: User, processor: User) -> bool: - if user != processor: - return user.permission_level < processor.permission_level - else: - return True - def create_user( name: str, login: str, email: str, birthdate: date, groups: t.Iterable[PropertyGroup], processor: User | None, address: Address, diff --git a/pycroft/lib/user/edit.py b/pycroft/lib/user/edit.py index f731d1e31..6dc4f8e95 100644 --- a/pycroft/lib/user/edit.py +++ b/pycroft/lib/user/edit.py @@ -7,7 +7,8 @@ from pycroft.model.session import with_transaction from pycroft.model.user import User -from ._old import can_target, send_confirmation_email +from ._old import send_confirmation_email +from .permission import can_target @with_transaction diff --git a/pycroft/lib/user/passwords.py b/pycroft/lib/user/passwords.py index f710ef310..ebdd385f5 100644 --- a/pycroft/lib/user/passwords.py +++ b/pycroft/lib/user/passwords.py @@ -4,8 +4,7 @@ from pycroft.model.session import with_transaction from pycroft.model.user import User -from ._old import can_target - +from .permission import can_target def maybe_setup_wifi(user: User, processor: User) -> str | None: """If wifi is available, sets a wifi password.""" diff --git a/pycroft/lib/user/permission.py b/pycroft/lib/user/permission.py new file mode 100644 index 000000000..b8a0893d6 --- /dev/null +++ b/pycroft/lib/user/permission.py @@ -0,0 +1,8 @@ +from pycroft.model.user import User + + +def can_target(user: User, processor: User) -> bool: + if user != processor: + return user.permission_level < processor.permission_level + else: + return True