Commit 9b7b96a3 authored by Sli's avatar Sli

core: add UserIsLoggedMixin to check if an user is not anonymous

parent b18746e7
Pipeline #1919 failed with stage
in 49 seconds
......@@ -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
......
......@@ -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
"""
......@@ -770,11 +771,6 @@ class UserToolsView(QuickNotifMixin, UserTabsMixin, TemplateView):
template_name = "core/user_tools.jinja"
current_tab = "tools"
def dispatch(self, request, *args, **kwargs):
if request.user.is_anonymous:
raise PermissionDenied
return super(UserToolsView, self).dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs):
self.object = self.request.user
from launderette.models import Launderette
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment