plans_page: Fix broken redirection to /accounts/login/.

When an unauthenticated user tries to access the /plans page, we
redirect to /accounts/login/?next=plans (note the missing slash
before "plans"). After the user is authenticated, they are then
redirected to /accounts/login/plans, which is an invalid URL. The
correct URL should be just /plans.

This commit solves this by prefixing the "plans" in the query
parameter with a forward slash, which results in the correct
redirect URL, i.e., /plans.
This commit is contained in:
Eeshan Garg 2021-06-15 17:53:45 -02:30 committed by Tim Abbott
parent f08555bb31
commit 512229cf7d
2 changed files with 2 additions and 2 deletions

View File

@ -399,7 +399,7 @@ class PlansPageTest(ZulipTestCase):
realm.save(update_fields=["plan_type"])
result = self.client_get("/plans/", subdomain="zulip")
self.assertEqual(result.status_code, 302)
self.assertEqual(result["Location"], "/accounts/login/?next=plans")
self.assertEqual(result["Location"], "/accounts/login/?next=/plans")
guest_user = "polonius"
self.login(guest_user)

View File

@ -47,7 +47,7 @@ def plans_view(request: HttpRequest) -> HttpResponse:
if realm.plan_type == Realm.SELF_HOSTED and settings.PRODUCTION:
return HttpResponseRedirect("https://zulip.com/plans")
if not request.user.is_authenticated:
return redirect_to_login(next="plans")
return redirect_to_login(next="/plans")
if request.user.is_guest:
return TemplateResponse(request, "404.html", status=404)
if settings.CORPORATE_ENABLED: