Skip to content

Commit

Permalink
AAP-29291: Trial: redirect Anonymous used to the login page (#1344)
Browse files Browse the repository at this point in the history
If an Anonymous hits /trial, we now redirect it to the Login page. This will
be enough to avoid the err 500.
  • Loading branch information
goneri authored Oct 15, 2024
1 parent 52de54e commit ca99ffd
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ansible_ai_connect/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from django.apps import apps
from django.conf import settings
from django.contrib.auth.models import AnonymousUser
from django.forms import Form
from django.http import HttpResponseForbidden, HttpResponseRedirect
from django.shortcuts import render
Expand Down Expand Up @@ -158,6 +159,9 @@ def get_trial_plan(self):
return trial_plan

def dispatch(self, request, *args, **kwargs):
if isinstance(request.user, AnonymousUser):
return HttpResponseRedirect(reverse("login"))

if any(up.plan == self.get_trial_plan() for up in request.user.userplan_set.all()):
return super().dispatch(request, *args, **kwargs)

Expand Down

0 comments on commit ca99ffd

Please sign in to comment.