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

This commit is contained in:
Antoine Bartuccio 2019-07-15 12:26:04 +02:00
parent b18746e769
commit 9b7b96a310
2 changed files with 13 additions and 6 deletions

View File

@ -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

View File

@ -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