diff --git a/biscuit/core/menus.py b/biscuit/core/menus.py index c6bb49fba346903e54ebfa7c15d956e02cf5e80d..c40a246723fee61899d6f7403a7e3ee996acf49c 100644 --- a/biscuit/core/menus.py +++ b/biscuit/core/menus.py @@ -45,7 +45,7 @@ MENUS = { 'name': _('People'), 'url': '#', 'root': True, - 'validators': ['menu_generator.validators.is_authenticated'], + 'validators': ['menu_generator.validators.is_authenticated', 'biscuit.core.util.core_helpers.has_person'], 'submenu': [ { 'name': _('Persons'), diff --git a/biscuit/core/templates/core/base.html b/biscuit/core/templates/core/base.html index ad9c79960f7ee8cad093d9ef7edc7d6dbcb6dbee..059c8ed7d322bbc6c1a90ebda6aa7b223a1c1f3b 100644 --- a/biscuit/core/templates/core/base.html +++ b/biscuit/core/templates/core/base.html @@ -38,6 +38,8 @@ </header> <main role="main" class="container"> + {% include 'core/no_person.html' %} + {% bootstrap_messages %} <h1>{% block page_title %}{% endblock %}</h1> diff --git a/biscuit/core/templates/core/no_person.html b/biscuit/core/templates/core/no_person.html new file mode 100644 index 0000000000000000000000000000000000000000..3823b5ea96d7fa1ee3b5ea15671c0a69a47e0acc --- /dev/null +++ b/biscuit/core/templates/core/no_person.html @@ -0,0 +1,18 @@ +{% load i18n %} + +{% if not user.person %} + <div class="alert alert-danger" role="alert"> + <h2 class="alert-heading"> + {% blocktrans %} + You are not linked to a person + {% endblocktrans %} + </h2> + <p> + {% blocktrans %} + Your user account is not linked to a person. This means you + cannot access any school-related information. Please contact + the managers of BiscuIT at your school. + {% endblocktrans %} + </p> + </div> +{% endif %} diff --git a/biscuit/core/util/core_helpers.py b/biscuit/core/util/core_helpers.py index 992a51316da72723a55b44edab5ed98fa246f8cb..e2379d140782b9e866c41ee7efd9adff5c88fd01 100644 --- a/biscuit/core/util/core_helpers.py +++ b/biscuit/core/util/core_helpers.py @@ -69,3 +69,12 @@ def get_current_school() -> Optional: def is_impersonate(request: HttpRequest) -> bool: if hasattr(request, 'user'): return getattr(request.user, 'is_impersonate', False) + else: + return False + + +def has_person(request: HttpRequest) -> bool: + if hasattr(request, 'user'): + return getattr(request.user, 'person', None) is not None + else: + return False