Skip to content

Commit

Permalink
extract can_target to .permissions module
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasjuhrich committed Sep 9, 2024
1 parent 4b207c1 commit 3d5b9a6
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pycroft/lib/user/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
setup_ipv4_networking,
store_user_sheet,
get_user_sheet,
can_target,
create_user,
login_available,
move_in,
Expand Down Expand Up @@ -76,6 +75,7 @@
from .mail_confirmation import (
confirm_mail_address,
)
from .permission import can_target

from .exc import (
HostAliasExists,
Expand Down
6 changes: 0 additions & 6 deletions pycroft/lib/user/_old.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion pycroft/lib/user/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions pycroft/lib/user/passwords.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
8 changes: 8 additions & 0 deletions pycroft/lib/user/permission.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3d5b9a6

Please sign in to comment.