Repository: svthalia/concrexit

Issue:
Cannot open admin as initial superuser
### Describe the bug
After some sales stuff (#1631) I tried to setup concrexit. When making an initial superuser, you can not open the admin page, bacause of a call to `is_super_user` on None:

```
Traceback (most recent call last):
  File "/Users/dirkdoesburg/Library/Caches/pypoetry/virtualenvs/concrexit-rmygm93M-py3.9/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/Users/dirkdoesburg/Library/Caches/pypoetry/virtualenvs/concrexit-rmygm93M-py3.9/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/dirkdoesburg/Library/Caches/pypoetry/virtualenvs/concrexit-rmygm93M-py3.9/lib/python3.9/site-packages/django/contrib/admin/sites.py", line 250, in wrapper
    return self.admin_view(view, cacheable)(*args, **kwargs)
  File "/Users/dirkdoesburg/Library/Caches/pypoetry/virtualenvs/concrexit-rmygm93M-py3.9/lib/python3.9/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/Users/dirkdoesburg/Library/Caches/pypoetry/virtualenvs/concrexit-rmygm93M-py3.9/lib/python3.9/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/Users/dirkdoesburg/Library/Caches/pypoetry/virtualenvs/concrexit-rmygm93M-py3.9/lib/python3.9/site-packages/django/contrib/admin/sites.py", line 232, in inner
    return view(request, *args, **kwargs)
  File "/Users/dirkdoesburg/Library/Caches/pypoetry/virtualenvs/concrexit-rmygm93M-py3.9/lib/python3.9/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/Users/dirkdoesburg/Library/Caches/pypoetry/virtualenvs/concrexit-rmygm93M-py3.9/lib/python3.9/site-packages/django/contrib/admin/sites.py", line 523, in index
    app_list = self.get_app_list(request)
  File "/Users/dirkdoesburg/Library/Caches/pypoetry/virtualenvs/concrexit-rmygm93M-py3.9/lib/python3.9/site-packages/django/contrib/admin/sites.py", line 506, in get_app_list
    app_dict = self._build_app_dict(request)
  File "/Users/dirkdoesburg/Library/Caches/pypoetry/virtualenvs/concrexit-rmygm93M-py3.9/lib/python3.9/site-packages/django/contrib/admin/sites.py", line 455, in _build_app_dict
    perms = model_admin.get_model_perms(request)
  File "/Users/dirkdoesburg/Library/Caches/pypoetry/virtualenvs/concrexit-rmygm93M-py3.9/lib/python3.9/site-packages/django/contrib/admin/options.py", line 660, in get_model_perms
    'add': self.has_add_permission(request),
  File "/Users/dirkdoesburg/Desktop/CS/Technicie/concrexit/website/sales/admin/order_admin.py", line 249, in has_add_permission
    request.member.is_superuser
  File "/Users/dirkdoesburg/Library/Caches/pypoetry/virtualenvs/concrexit-rmygm93M-py3.9/lib/python3.9/site-packages/django/utils/functional.py", line 247, in inner
    return func(self._wrapped, *args)

Exception Type: AttributeError at /admin/
Exception Value: 'NoneType' object has no attribute 'is_superuser'
```

### How to reproduce
Steps to reproduce the behaviour:
1. Make a new install of concrexit.
2. Log in.
3. Open the admin page.
4. See error.



Discussion:

Resolving patch:
diff --git a/website/sales/admin/order_admin.py b/website/sales/admin/order_admin.py
--- a/website/sales/admin/order_admin.py
+++ b/website/sales/admin/order_admin.py
@@ -223,7 +223,7 @@ def get_readonly_fields(self, request: HttpRequest, obj: Order = None):
     def get_queryset(self, request):
         queryset = super().get_queryset(request)
 
-        if not (
+        if request.member and not (
             request.member.is_superuser
             or request.member.has_perm("sales.override_manager")
         ):
@@ -245,7 +245,7 @@ def get_queryset(self, request):
         return queryset
 
     def has_add_permission(self, request):
-        if not (
+        if request.member and not (
             request.member.is_superuser
             or request.member.has_perm("sales.override_manager")
         ):
@@ -307,9 +307,11 @@ def formfield_for_dbfield(self, db_field, request, obj=None, **kwargs):
             )
         if db_field.name == "shift":
             field.queryset = Shift.objects.filter(locked=False)
-            if not (
-                request.member.is_superuser
-                or request.member.has_perm("sales.override_manager")
+            if request.member and not (
+                (
+                    request.member.is_superuser
+                    or request.member.has_perm("sales.override_manager")
+                )
             ):
                 field.queryset = field.queryset.filter(
                     managers__in=request.member.get_member_groups()
@@ -318,8 +320,11 @@ def formfield_for_dbfield(self, db_field, request, obj=None, **kwargs):
 
     def changelist_view(self, request, extra_context=None):
         if not (
-            request.member.is_superuser
-            or request.member.has_perm("sales.override_manager")
+            request.member
+            and (
+                request.member.is_superuser
+                or request.member.has_perm("sales.override_manager")
+            )
         ):
             self.message_user(
                 request,
@@ -331,7 +336,7 @@ def changelist_view(self, request, extra_context=None):
     def change_view(self, request, object_id, form_url="", extra_context=None):
         object_id
         return super().change_view(request, object_id, form_url, extra_context)
-        # TODO WARN WHEN ORDER IS AGE RESTRICTED AND PAYER IS UNDERAGE
+        # @todo WARN WHEN ORDER IS AGE RESTRICTED AND PAYER IS UNDERAGE
 
     def order_description(self, obj):
         if obj.order_description:


Test patch: