mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 14:13:21 +00:00
counter: fix error for stats 500 on PermissionDenied
This commit is contained in:
parent
d466d645e6
commit
f0524a9f00
@ -83,6 +83,17 @@ class CounterTest(TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class CounterStatsTest(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
call_command("populate")
|
||||||
|
self.counter = Counter.objects.filter(id=2).first()
|
||||||
|
|
||||||
|
def test_unothorized_user_fail(self):
|
||||||
|
# Test with not login user
|
||||||
|
response = self.client.get(reverse("counter:stats", args=[self.counter.id]))
|
||||||
|
self.assertTrue(response.status_code == 403)
|
||||||
|
|
||||||
|
|
||||||
class BarmanConnectionTest(TestCase):
|
class BarmanConnectionTest(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
call_command("populate")
|
call_command("populate")
|
||||||
|
@ -1522,11 +1522,11 @@ class CounterStatView(DetailView, CounterAdminMixin):
|
|||||||
def dispatch(self, request, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
return super(CounterStatView, self).dispatch(request, *args, **kwargs)
|
return super(CounterStatView, self).dispatch(request, *args, **kwargs)
|
||||||
except:
|
except PermissionDenied:
|
||||||
if (
|
if (
|
||||||
request.user.is_root
|
request.user.is_root
|
||||||
or request.user.is_board_member
|
or request.user.is_board_member
|
||||||
or self.object.is_owned_by(request.user)
|
or self.get_object().is_owned_by(request.user)
|
||||||
):
|
):
|
||||||
return super(CanEditMixin, self).dispatch(request, *args, **kwargs)
|
return super(CanEditMixin, self).dispatch(request, *args, **kwargs)
|
||||||
raise PermissionDenied
|
raise PermissionDenied
|
||||||
|
Loading…
Reference in New Issue
Block a user