Skip to content

Commit

Permalink
fixed menu permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
bbonf committed Apr 16, 2024
1 parent 7fae53a commit e126436
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions lab/main/menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,12 @@


def _user_is_authenticated(x: WSGIRequest) -> bool:
"""
Checks whether the user x is is_authenticated
"""
return x.user.is_authenticated


def _user_is_not_authenticated(x: WSGIRequest) -> bool:
"""
Checks whether the user x is not authenticated
"""
return not _user_is_authenticated(x)


def _user_is_admin(req: WSGIRequest) -> bool:
return req.user.is_authenticated and req.user.is_superuser

def _user_is_lab_manager(req: WSGIRequest) -> bool:
return req.user.is_authenticated and req.user.is_staff


Expand All @@ -30,7 +22,7 @@ def _user_is_admin(req: WSGIRequest) -> bool:

experiments_menu = [
MenuItem(_("mainmenu:experiments:overview"), reverse("experiments:home")),
MenuItem(_("mainmenu:locations"), reverse("experiments:location_home")),
MenuItem(_("mainmenu:locations"), reverse("experiments:location_home"), check=_user_is_admin),
]

Menu.add_item(
Expand All @@ -40,15 +32,15 @@ def _user_is_admin(req: WSGIRequest) -> bool:

users_menu = [
MenuItem(_("mainmenu:leaders"), reverse("main:users_leaders"), check=_user_is_authenticated),
MenuItem(_("mainmenu:admins"), reverse("main:users_admins"), check=_user_is_authenticated),
MenuItem(_("mainmenu:admins"), reverse("main:users_admins"), check=_user_is_admin),
]

Menu.add_item("main", MenuItem(_("mainmenu:users"), check=_user_is_authenticated, children=users_menu, url=None))
Menu.add_item("main", MenuItem(_("mainmenu:users"), check=_user_is_lab_manager, children=users_menu, url=None))

participants_menu = [
MenuItem(_("mainmenu:participants"), reverse("participants:home"), check=_user_is_authenticated),
MenuItem(_("mainmenu:demographics"), reverse("participants:demographics"), check=_user_is_authenticated),
MenuItem(_("mainmenu:signups"), reverse("signups:list"), check=_user_is_authenticated),
MenuItem(_("mainmenu:demographics"), reverse("participants:demographics"), check=_user_is_lab_manager),
MenuItem(_("mainmenu:signups"), reverse("signups:list"), check=_user_is_lab_manager),
]

Menu.add_item(
Expand All @@ -68,8 +60,4 @@ def _user_is_admin(req: WSGIRequest) -> bool:

Menu.add_item(
"main", MenuItem(_("mainmenu:survey_admin"), reverse("survey_admin:overview"), check=_user_is_authenticated)
)

Menu.add_item("footer", MenuItem(_("footermenu:login"), reverse("main:login"), check=_user_is_not_authenticated))

Menu.add_item("footer", MenuItem(_("main:globals:logout"), reverse("main:logout"), check=_user_is_authenticated))
)

0 comments on commit e126436

Please sign in to comment.