Skip to content

Commit

Permalink
Add login redirect to user dashboard
Browse files Browse the repository at this point in the history
If the user is not authenticated, they will now be redirected to the
login URL instead of getting an unauthorized error.
  • Loading branch information
mvandenburgh committed Dec 11, 2023
1 parent 1dfde43 commit 294bc4d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions dandiapi/api/views/dashboard.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from allauth.socialaccount.models import SocialAccount
from django.conf import settings
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.contrib.auth.models import User
from django.core.exceptions import PermissionDenied, ValidationError
from django.db.models import Exists, OuterRef
from django.http.response import HttpResponseRedirect
from django.shortcuts import get_object_or_404, render
from django.views.decorators.http import require_http_methods
from django.views.generic.base import TemplateView
Expand Down Expand Up @@ -76,6 +78,11 @@ def _users(self):

@require_http_methods(['GET', 'POST'])
def user_approval_view(request, username: str):
# Redirect user to login if they're not authenticated
if not request.user.is_authenticated:
return HttpResponseRedirect(redirect_to=settings.LOGIN_URL)

# If they are authenticated but are not a superuser, deny access
if not request.user.is_superuser:
raise PermissionDenied

Expand Down

0 comments on commit 294bc4d

Please sign in to comment.