Redirect from stats views to login page if users are not logged in
Issue: HIC-291
Change-Id: Ib22fdeda5dd345c7875b369d0094ebecd9ee7567
diff --git a/crashreport_stats/permissions.py b/crashreport_stats/permissions.py
index c457f42..ab00fe8 100644
--- a/crashreport_stats/permissions.py
+++ b/crashreport_stats/permissions.py
@@ -8,12 +8,16 @@
def check_user_is_hiccup_staff(user):
"""Check if the user is part of the Hiccup staff.
- Returns: True if the user is part of the Hiccup staff group.
+ Returns:
+ True if the user is part of the Hiccup staff group, False if the user
+ is not logged in.
Raises:
PermissionDenied: If the user is not part of the Hiccup staff group.
"""
+ if not user.is_authenticated:
+ return False
if not user_is_hiccup_staff(user):
raise PermissionDenied(
"User %s not part of the %s group" % (user, FP_STAFF_GROUP_NAME)