Mitja Nikolaus | a901798 | 2018-11-21 12:14:45 +0100 | [diff] [blame] | 1 | """Permissions for accessing the stats API.""" |
| 2 | from django.core.exceptions import PermissionDenied |
| 3 | |
| 4 | from crashreports.permissions import user_is_hiccup_staff |
| 5 | from hiccup.allauth_adapters import FP_STAFF_GROUP_NAME |
| 6 | |
| 7 | |
| 8 | def check_user_is_hiccup_staff(user): |
| 9 | """Check if the user is part of the Hiccup staff. |
| 10 | |
| 11 | Returns: True if the user is part of the Hiccup staff group. |
| 12 | |
| 13 | Raises: |
| 14 | PermissionDenied: If the user is not part of the Hiccup staff group. |
| 15 | |
| 16 | """ |
| 17 | if not user_is_hiccup_staff(user): |
| 18 | raise PermissionDenied( |
| 19 | "User %s not part of the %s group" % (user, FP_STAFF_GROUP_NAME) |
| 20 | ) |
| 21 | return True |