From 3a9110dc30eeb97baf4d52a87701a1628d6633fd Mon Sep 17 00:00:00 2001
From: Jan Dittberner <jan@dittberner.info>
Date: Sat, 24 Jan 2015 16:12:23 +0100
Subject: [PATCH] refactor dashboard.views.UserDashboardView

- use gvacommon.viewmixins.StaffOrSelfLoginRequiredMixin instead of custom
  implementation
---
 gnuviechadmin/dashboard/views.py | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/gnuviechadmin/dashboard/views.py b/gnuviechadmin/dashboard/views.py
index d378b1d..1542e45 100644
--- a/gnuviechadmin/dashboard/views.py
+++ b/gnuviechadmin/dashboard/views.py
@@ -4,15 +4,13 @@ This module defines the views for the gnuviechadmin customer dashboard.
 """
 from __future__ import unicode_literals
 
-from django.http import HttpResponseForbidden
 from django.views.generic import (
     DetailView,
     TemplateView,
 )
-from django.utils.translation import ugettext as _
 from django.contrib.auth import get_user_model
 
-from braces.views import LoginRequiredMixin
+from gvacommon.viewmixins import StaffOrSelfLoginRequiredMixin
 
 from hostingpackages.models import CustomerHostingPackage
 
@@ -25,7 +23,7 @@ class IndexView(TemplateView):
     template_name = 'dashboard/index.html'
 
 
-class UserDashboardView(LoginRequiredMixin, DetailView):
+class UserDashboardView(StaffOrSelfLoginRequiredMixin, DetailView):
     """
     This is the user dashboard view.
 
@@ -35,18 +33,16 @@ class UserDashboardView(LoginRequiredMixin, DetailView):
     slug_field = 'username'
     template_name = 'dashboard/user_dashboard.html'
 
-    def dispatch(self, request, *args, **kwargs):
-        if (request.user.is_staff or request.user == self.get_object()):
-            return super(UserDashboardView, self).dispatch(
-                request, *args, **kwargs
-            )
-        return HttpResponseForbidden(
-            _('You are not allowed to view this page.')
-        )
-
     def get_context_data(self, **kwargs):
         context = super(UserDashboardView, self).get_context_data(**kwargs)
         context['hosting_packages'] = CustomerHostingPackage.objects.filter(
             customer=self.object
         )
         return context
+
+    def get_customer_object(self):
+        """
+        Returns the customer object.
+
+        """
+        return self.get_object()