diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 216837bc..5c6a6ed2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,7 +5,7 @@ test: stage: test script: - apt-get update - - apt-get install -y gettext python3-xapian + - apt-get install -y gettext python3-xapian libgraphviz-dev - pushd /usr/lib/python3/dist-packages/xapian && ln -s _xapian* _xapian.so && popd - export PYTHONPATH="/usr/lib/python3/dist-packages:$PYTHONPATH" - python -c 'import xapian' # Fail immediately if there is a problem with xapian diff --git a/core/tests.py b/core/tests.py index 92e41a98..ff482067 100644 --- a/core/tests.py +++ b/core/tests.py @@ -396,6 +396,21 @@ http://git.an ) +class UserToolsTest(TestCase): + def setUp(self): + call_command("populate") + + def test_anonymous_user_unauthorized(self): + response = self.client.get(reverse("core:user_tools")) + self.assertEquals(response.status_code, 403) + + def test_page_is_working(self): + self.client.login(username="guy", password="plop") + response = self.client.get(reverse("core:user_tools")) + self.assertNotEquals(response.status_code, 500) + self.assertEquals(response.status_code, 200) + + # TODO: many tests on the pages: # - renaming a page # - changing a page's parent --> check that page's children's full_name diff --git a/core/views/__init__.py b/core/views/__init__.py index 202b08fa..41bd5eee 100644 --- a/core/views/__init__.py +++ b/core/views/__init__.py @@ -214,6 +214,17 @@ class FormerSubscriberMixin(View): return super(FormerSubscriberMixin, self).dispatch(request, *args, **kwargs) +class UserIsLoggedMixin(View): + """ + This view check if the user is logged + """ + + def dispatch(self, request, *args, **kwargs): + if request.user.is_anonymous: + raise PermissionDenied + return super(UserIsLoggedMixin, self).dispatch(request, *args, **kwargs) + + class TabedViewMixin(View): """ This view provide the basic functions for displaying tabs in the template diff --git a/core/views/user.py b/core/views/user.py index 019cda0a..63135872 100644 --- a/core/views/user.py +++ b/core/views/user.py @@ -52,6 +52,7 @@ from core.views import ( CanViewMixin, CanEditMixin, CanEditPropMixin, + UserIsLoggedMixin, TabedViewMixin, QuickNotifMixin, ) @@ -762,7 +763,7 @@ class UserUpdateGroupView(UserTabsMixin, CanEditPropMixin, UpdateView): current_tab = "groups" -class UserToolsView(QuickNotifMixin, UserTabsMixin, TemplateView): +class UserToolsView(QuickNotifMixin, UserTabsMixin, UserIsLoggedMixin, TemplateView): """ Displays the logged user's tools """ diff --git a/requirements.txt b/requirements.txt index 2efe3c6d..d5b5edd8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,7 @@ mistune django-jinja pyopenssl pytz -djangorestframework +djangorestframework <3.10 django-phonenumber-field phonenumbers django-ajax-selects